mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
update build
This commit is contained in:
parent
3bebc5877c
commit
7238e87e37
1 changed files with 7 additions and 13 deletions
20
lib/main.js
20
lib/main.js
|
|
@ -30,16 +30,6 @@ const core = __importStar(require("@actions/core"));
|
|||
const github = __importStar(require("@actions/github"));
|
||||
const http_client_1 = require("@actions/http-client");
|
||||
const promises_1 = __importDefault(require("node:fs/promises"));
|
||||
const listCommitPulls = async (params) => {
|
||||
const { repoToken, owner, repo, commitSha } = params;
|
||||
const http = new http_client_1.HttpClient('http-client-add-pr-comment');
|
||||
const additionalHeaders = {
|
||||
accept: 'application/vnd.github.groot-preview+json',
|
||||
authorization: `token ${repoToken}`,
|
||||
};
|
||||
const body = await http.getJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}/pulls`, additionalHeaders);
|
||||
return body.result;
|
||||
};
|
||||
const getIssueNumberFromCommitPullsList = (commitPullsList) => (commitPullsList.length ? commitPullsList[0].number : null);
|
||||
const createCommentProxy = async (params) => {
|
||||
const { repoToken, owner, repo, issueNumber, body, proxyUrl } = params;
|
||||
|
|
@ -99,6 +89,7 @@ const run = async () => {
|
|||
return;
|
||||
}
|
||||
const [owner, repo] = repoFullName.split('/');
|
||||
const octokit = github.getOctokit(repoToken);
|
||||
let issueNumber;
|
||||
if (issue && issue.number) {
|
||||
issueNumber = issue.number;
|
||||
|
|
@ -108,15 +99,18 @@ const run = async () => {
|
|||
}
|
||||
else {
|
||||
// If this is not a pull request, attempt to find a PR matching the sha
|
||||
const commitPullsList = await listCommitPulls({ repoToken, owner, repo, commitSha });
|
||||
issueNumber = commitPullsList && getIssueNumberFromCommitPullsList(commitPullsList);
|
||||
const commitPullsList = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||
owner,
|
||||
repo,
|
||||
commit_sha: commitSha,
|
||||
});
|
||||
issueNumber = commitPullsList.data && getIssueNumberFromCommitPullsList(commitPullsList.data);
|
||||
}
|
||||
if (!issueNumber) {
|
||||
core.info('this action only works on issues and pull_request events or other commits associated with a pull');
|
||||
core.setOutput('comment-created', 'false');
|
||||
return;
|
||||
}
|
||||
const octokit = github.getOctokit(repoToken);
|
||||
let shouldCreateComment = true;
|
||||
if (!allowRepeats) {
|
||||
core.debug('repeat comments are disallowed, checking for existing');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue