@@ -81,27 +81,30 @@ async function action() {
81
81
if (!isValidCommentType(commentType)) {
82
82
core.setFailed(`'comment-type' ${commentType} is invalid`);
83
83
}
84
+ let prNumber = Number(core.getInput('pr-number')) || undefined;
85
+ const client = github.getOctokit(token);
84
86
let base;
85
87
let head;
86
- let prNumber;
87
88
switch (event) {
88
89
case 'pull_request':
89
90
case 'pull_request_target':
90
91
base = github.context.payload.pull_request?.base.sha;
91
92
head = github.context.payload.pull_request?.head.sha;
92
- prNumber = github.context.payload.pull_request?.number;
93
+ prNumber = prNumber ?? github.context.payload.pull_request?.number;
93
94
break;
94
95
case 'push':
95
96
base = github.context.payload.before;
96
97
head = github.context.payload.after;
98
+ prNumber =
99
+ prNumber ??
100
+ (await getPrNumberAssociatedWithCommit(client, github.context.sha));
97
101
break;
98
102
default:
99
103
core.setFailed(`Only pull requests and pushes are supported, ${github.context.eventName} not supported.`);
100
104
return;
101
105
}
102
106
core.info(`base sha: ${base}`);
103
107
core.info(`head sha: ${head}`);
104
- const client = github.getOctokit(token);
105
108
if (debugMode)
106
109
core.info(`reportPaths: ${reportPaths}`);
107
110
const changedFiles = await getChangedFiles(base, head, client, debugMode);
@@ -234,6 +237,14 @@ const validCommentTypes = ['pr_comment', 'summary', 'both'];
234
237
const isValidCommentType = (value) => {
235
238
return validCommentTypes.includes(value);
236
239
};
240
+ async function getPrNumberAssociatedWithCommit(client, commitSha) {
241
+ const response = await client.rest.repos.listPullRequestsAssociatedWithCommit({
242
+ commit_sha: commitSha,
243
+ owner: github.context.repo.owner,
244
+ repo: github.context.repo.repo,
245
+ });
246
+ return response.data.length > 0 ? response.data[0].number : undefined;
247
+ }
237
248
238
249
239
250
/***/ }),
0 commit comments