-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Create/Pass commit date to commit for signing #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f470462
c42090c
085fe71
5481c5e
c1bf2e0
65499e8
ab972fd
14f2e03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,7 @@ export interface Logger { | |
| export interface UserData { | ||
| name: string; | ||
| email: string; | ||
| date?: Date; | ||
| } | ||
|
|
||
| export interface CommitData { | ||
|
|
@@ -216,6 +217,11 @@ export interface CommitData { | |
| committer?: UserData; | ||
| } | ||
|
|
||
| export interface CommitDataWithRequiredDate extends CommitData { | ||
| author?: Required<UserData>; | ||
| committer?: Required<UserData>; | ||
| } | ||
|
|
||
| export interface CommitSigner { | ||
| generateSignature(commit: CommitData): Promise<string>; | ||
| generateSignature(commit: CommitDataWithRequiredDate): Promise<string>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a breaking change which makes additional inputs required. Does this actually need to be a required field?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might have a thinking mistake: The reason why I was making the date required is because all places where the So they simply get a new never null field in the function parameters. I'm happy to change it make that field optional. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I follow why date is part of the UserData as opposed to the commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this into the UserData as GitHub does it like this:
https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if you run this command here:
Full output:
You will get:
{ "sha": "f470462d6aa6ce356a4b8151780c3131d9dc3431", "node_id": "C_kwDOEF_fiNoAKGY0NzA0NjJkNmFhNmNlMzU2YTRiODE1MTc4MGMzMTMxZDlkYzM0MzE", "commit": { "author": { "name": "Dennis Kugelmann", "email": "dennis.kugelmann@simpleclub.com", "date": "2024-01-30T16:33:12Z" }, "committer": { "name": "Dennis Kugelmann", "email": "dennis.kugelmann@simpleclub.com", "date": "2024-01-30T16:33:12Z" }, "message": "Create/Pass commit date to commit for signing", "tree": { "sha": "c1cf81371f7f287d14ca2d8d4091db8339e0682a", "url": "https://api.github.com/repos/googleapis/code-suggester/git/trees/c1cf81371f7f287d14ca2d8d4091db8339e0682a" }, "url": "https://api.github.com/repos/googleapis/code-suggester/git/commits/f470462d6aa6ce356a4b8151780c3131d9dc3431", "comment_count": 0, "verification": { "verified": true, "reason": "valid", "signature": "-----BEGIN PGP SIGNATURE-----\n\niQIzBAABCAAdFiEE7H0SA8TDxy7sibehbDlA5QJOreMFAmW5JMgACgkQbDlA5QJO\nreN2LQ/+LUEXtKj2mIxhXJUE6QBtQ62VSrVDm8LassE7fdz8QZfSzDb561L0hcfi\nV6r8aUlq1wTJSJGSTIEZBERO3FQKCtXrML+z0VDnxc34lf9h75lXFGfvvWoWntAE\n6XFTGVCHPx+MVmkexZkz2kk26XLqdD1h+iLwkjIeMP0gSEzRwJVzMlYlPvQFoKTW\n/RewhmN8e+q4Y06gPzbQAVxcMZn7R8NrhxaChM9FS2q7S8yeGCgCiR20uLpMkh0Y\nFWaVdLh8oYAVBn/lrf6CsiW44uiROhzvrhhPRm0fKaXDnyW5fFsElUZPH9/602n5\nPe+vJVtZXfnKhLIT+JyeulQRMakq2vUaqEqOJW/8cfz6of6zTU251Ca0pQ4wXkha\nxLbDlDEh7Mt+KOGHBAi3OqSJo3lKqKS9f+ZvMRPdTc36HUt6DDYZc0lZ3QWkupoa\n7tMGaShiTLEALm2BNFlUqIobm67mGgcm3EuGEohQ8+ZSTyzZLl3V0HDSoM9rNtZI\nVLVfcR6RbDyRjlL6SIdMkXoM1Fk83OYICE5QOiUlDW4teBBjYwb/UjxcUBEQ9zEY\nMI6CULh8k0hNDThttx6DlejtN/3aprbk44w2JyE3txoAmyifMOwtoS5U3zYXJtwF\nBJGCVKvZfDcXBlb76K9GChIAo68tltSH73nChHmot16deT0/dOU=\n=J/h5\n-----END PGP SIGNATURE-----", "payload": "tree c1cf81371f7f287d14ca2d8d4091db8339e0682a\nparent f091b69577a0ad2d14eb90888485f28909aba480\nauthor Dennis Kugelmann <dennis.kugelmann@simpleclub.com> 1706632392 +0000\ncommitter Dennis Kugelmann <dennis.kugelmann@simpleclub.com> 1706632392 +0000\n\nCreate/Pass commit date to commit for signing\n", "verified_at": "2024-11-14T03:15:56Z" } }, "url": "https://api.github.com/repos/googleapis/code-suggester/commits/f470462d6aa6ce356a4b8151780c3131d9dc3431", "html_url": "https://github.com/googleapis/code-suggester/commit/f470462d6aa6ce356a4b8151780c3131d9dc3431", "comments_url": "https://api.github.com/repos/googleapis/code-suggester/commits/f470462d6aa6ce356a4b8151780c3131d9dc3431/comments", "author": { "login": "IchordeDionysos", "id": 10195482, "node_id": "MDQ6VXNlcjEwMTk1NDgy", "avatar_url": "https://avatars.githubusercontent.com/u/10195482?v=4", "gravatar_id": "", "url": "https://api.github.com/users/IchordeDionysos", "html_url": "https://github.com/IchordeDionysos", "followers_url": "https://api.github.com/users/IchordeDionysos/followers", "following_url": "https://api.github.com/users/IchordeDionysos/following{/other_user}", "gists_url": "https://api.github.com/users/IchordeDionysos/gists{/gist_id}", "starred_url": "https://api.github.com/users/IchordeDionysos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/IchordeDionysos/subscriptions", "organizations_url": "https://api.github.com/users/IchordeDionysos/orgs", "repos_url": "https://api.github.com/users/IchordeDionysos/repos", "events_url": "https://api.github.com/users/IchordeDionysos/events{/privacy}", "received_events_url": "https://api.github.com/users/IchordeDionysos/received_events", "type": "User", "user_view_type": "public", "site_admin": false }, "committer": { "login": "IchordeDionysos", "id": 10195482, "node_id": "MDQ6VXNlcjEwMTk1NDgy", "avatar_url": "https://avatars.githubusercontent.com/u/10195482?v=4", "gravatar_id": "", "url": "https://api.github.com/users/IchordeDionysos", "html_url": "https://github.com/IchordeDionysos", "followers_url": "https://api.github.com/users/IchordeDionysos/followers", "following_url": "https://api.github.com/users/IchordeDionysos/following{/other_user}", "gists_url": "https://api.github.com/users/IchordeDionysos/gists{/gist_id}", "starred_url": "https://api.github.com/users/IchordeDionysos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/IchordeDionysos/subscriptions", "organizations_url": "https://api.github.com/users/IchordeDionysos/orgs", "repos_url": "https://api.github.com/users/IchordeDionysos/repos", "events_url": "https://api.github.com/users/IchordeDionysos/events{/privacy}", "received_events_url": "https://api.github.com/users/IchordeDionysos/received_events", "type": "User", "user_view_type": "public", "site_admin": false }, "parents": [ { "sha": "f091b69577a0ad2d14eb90888485f28909aba480", "url": "https://api.github.com/repos/googleapis/code-suggester/commits/f091b69577a0ad2d14eb90888485f28909aba480", "html_url": "https://github.com/googleapis/code-suggester/commit/f091b69577a0ad2d14eb90888485f28909aba480" } ], "stats": { "total": 40, "additions": 29, "deletions": 11 }, "files": [ { "sha": "21553db0912990ffd7e9d8092b88aa4e76ac08d7", "filename": "src/github/create-commit.ts", "status": "modified", "additions": 28, "deletions": 11, "changes": 39, "blob_url": "https://github.com/googleapis/code-suggester/blob/f470462d6aa6ce356a4b8151780c3131d9dc3431/src%2Fgithub%2Fcreate-commit.ts", "raw_url": "https://github.com/googleapis/code-suggester/raw/f470462d6aa6ce356a4b8151780c3131d9dc3431/src%2Fgithub%2Fcreate-commit.ts", "contents_url": "https://api.github.com/repos/googleapis/code-suggester/contents/src%2Fgithub%2Fcreate-commit.ts?ref=f470462d6aa6ce356a4b8151780c3131d9dc3431", "patch": "@@ -44,15 +44,28 @@ export async function createCommit(\n options: CreateCommitOptions = {}\n ): Promise<string> {\n try {\n- const signature = options.signer\n- ? await options.signer.generateSignature({\n- message,\n- tree: treeSha,\n- parents: [refHead],\n- author: options.author,\n- committer: options.committer,\n- })\n- : undefined;\n+ let signature: string | undefined;\n+ if (options.signer) {\n+ const commitDate = new Date();\n+ // Attach author/commit date.\n+ if (options.author && !options.author?.date) {\n+ options.author.date = commitDate;\n+ }\n+ if (options.committer && !options.committer?.date) {\n+ options.committer.date = commitDate;\n+ }\n+\n+ signature = await options.signer.generateSignature({\n+ message,\n+ tree: treeSha,\n+ parents: [refHead],\n+ author: options.author,\n+ committer: options.committer,\n+ });\n+ } else {\n+ signature = undefined;\n+ }\n+\n const {\n data: {sha, url},\n } = await octokit.git.createCommit({\n@@ -62,8 +75,12 @@ export async function createCommit(\n tree: treeSha,\n parents: [refHead],\n signature,\n- author: options.author,\n- committer: options.committer,\n+ author: options.author\n+ ? {...options.author, date: options.author.date?.toISOString()}\n+ : undefined,\n+ committer: options.committer\n+ ? {...options.committer, date: options.committer.date?.toISOString()}\n+ : undefined,\n });\n logger.info(`Successfully created commit. See commit at ${url}`);\n return sha;" }, { "sha": "046c05a6385b466399a43e640bc3baecaa26f7f9", "filename": "src/types.ts", "status": "modified", "additions": 1, "deletions": 0, "changes": 1, "blob_url": "https://github.com/googleapis/code-suggester/blob/f470462d6aa6ce356a4b8151780c3131d9dc3431/src%2Ftypes.ts", "raw_url": "https://github.com/googleapis/code-suggester/raw/f470462d6aa6ce356a4b8151780c3131d9dc3431/src%2Ftypes.ts", "contents_url": "https://api.github.com/repos/googleapis/code-suggester/contents/src%2Ftypes.ts?ref=f470462d6aa6ce356a4b8151780c3131d9dc3431", "patch": "@@ -206,6 +206,7 @@ export interface Logger {\n export interface UserData {\n name: string;\n email: string;\n+ date?: Date;\n }\n \n export interface CommitData {" } ] }In the verification you will find:
The payload contains a date for both the committer and the author:
I'm unsure whether the committer and the author date will be the same?
Probably for the purpose of this repository, which is all about creating changes and committing them immediately, it probably is.
In the end I do use the same data for committer and author if not passed by the user.