Skip to content

Commit

Permalink
feat: auto update PR comment
Browse files Browse the repository at this point in the history
* create PR comment when PR is available
  • Loading branch information
ktrz committed Jan 31, 2024
1 parent e108afd commit 5fda30c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
output-file-path: examples/rust/output.txt
fail-on-alert: true
summary-always: true
comment-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Rust Benchmark'

go:
Expand Down
23 changes: 16 additions & 7 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,23 @@ async function leaveComment(commitId: string, body: string, token: string) {

const repoMetadata = getCurrentRepoMetadata();
const repoUrl = repoMetadata.html_url ?? '';
const pr = github.context.payload.pull_request;
const client = github.getOctokit(token);
const res = await client.rest.repos.createCommitComment({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
commit_sha: commitId,
body,
});
const res = await (pr?.number
? client.rest.pulls.createReviewComment({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
pull_number: pr.number,
body,
})
: client.rest.repos.createCommitComment({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
commit_sha: commitId,
body,
}));

const commitUrl = `${repoUrl}/commit/${commitId}`;
console.log(`Comment was sent to ${commitUrl}. Response:`, res.status, res.data);
Expand Down

0 comments on commit 5fda30c

Please sign in to comment.