Skip to content

Commit

Permalink
feat: Allow action to report on push events with an associated pull r…
Browse files Browse the repository at this point in the history
…equest on that commit (#11)
  • Loading branch information
cmanou authored Mar 4, 2024
1 parent 1fccc40 commit c90ff77
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,29 @@ async function saveComment(accessToken: string, markdown: string) {
payload: { pull_request: pr, issue },
repo,
} = github.context;
const id = pr?.number ?? issue?.number;

let id = pr?.number ?? issue?.number;

const octokit = github.getOctokit(accessToken);

if (!id) {
core.debug(
'No pull request or issue found from context, trying to find pull requests associated with commit',
);

const { data: pullRequests } = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
...repo,
commit_sha: github.context.sha,
});

id = pullRequests[0]?.number;
}

if (!id) {
core.warning('No pull request or issue found, will not add a comment.');
return;
}

const octokit = github.getOctokit(accessToken);
const { data: comments } = await octokit.rest.issues.listComments({
...repo,
issue_number: id,
Expand Down

0 comments on commit c90ff77

Please sign in to comment.