Skip to content

Commit

Permalink
feat: add commit sha to comment
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
corymhall committed Oct 31, 2023
1 parent be6055d commit 77fd717
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const project = new GitHubActionTypeScriptProject({
},
},
deps: [
'@octokit/webhooks-definitions',
'@aws-cdk/cloudformation-diff',
'@aws-cdk/cloud-assembly-schema',
'@actions/exec@^1.1.1',
Expand Down
16 changes: 11 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function run() {
};
const octokit = github.getOctokit(inputs.githubToken);
const context = github.context;

try {
const assembly = AssemblyManifestReader.fromPath('cdk.out');
let stages = assembly.stages;
Expand Down
10 changes: 9 additions & 1 deletion src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Context } from '@actions/github/lib/context';
import { GitHub } from '@actions/github/lib/utils';
import { PullRequestEvent } from '@octokit/webhooks-definitions/schema';

export class Comments {
private readonly issueNumber: number;
private readonly commitSha: string;
constructor(
private readonly octokit: InstanceType<typeof GitHub>,
private readonly context: Context,
) {
if (!context.payload.pull_request?.number) {
const payload = context.payload as PullRequestEvent;
this.commitSha = payload.pull_request.head.sha;
if (!payload.pull_request.number) {
throw new Error('Cannot find PR number, is this from a pull request?');
}
this.issueNumber = this.context.payload.pull_request?.number!;
Expand All @@ -27,6 +31,8 @@ export class Comments {
body: [
`<!-- cdk diff action with hash ${hash} -->`,
...content,
'',
`_Generated for commit ${this.commitSha}_`,
].join('\n'),
comment_id: commentId,
});
Expand All @@ -38,6 +44,8 @@ export class Comments {
body: [
`<!-- cdk diff action with hash ${hash} -->`,
...content,
'',
`_Generated for commit ${this.commitSha}_`,
].join('\n'),
issue_number: this.issueNumber,
});
Expand Down
7 changes: 6 additions & 1 deletion test/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const context: Context = {
full_name: 'some-repo',
},
pull_request: {
head: { sha: '123' },
number: 1,
},
},
} as Context;
} as unknown as Context;
// const pullRequestData = {
// data: {
// items: [
Expand Down Expand Up @@ -89,6 +90,8 @@ describe('comments', () => {
body: [
`<!-- cdk diff action with hash ${hash} -->`,
'message',
'',
`_Generated for commit ${context.payload.pull_request?.head.sha}_`,
].join('\n'),
comment_id: 1,
});
Expand All @@ -103,6 +106,8 @@ describe('comments', () => {
body: [
`<!-- cdk diff action with hash ${hash} -->`,
'message',
'',
`_Generated for commit ${context.payload.pull_request?.head.sha}_`,
].join('\n'),
issue_number: context.payload.pull_request?.number,
});
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77fd717

Please sign in to comment.