update build

This commit is contained in:
Michael Shick 2022-11-05 12:44:51 -04:00
parent 3bebc5877c
commit 7238e87e37
No known key found for this signature in database
GPG key ID: ADF5BC9704BB4A61

View file

@ -30,16 +30,6 @@ const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github")); const github = __importStar(require("@actions/github"));
const http_client_1 = require("@actions/http-client"); const http_client_1 = require("@actions/http-client");
const promises_1 = __importDefault(require("node:fs/promises")); 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 getIssueNumberFromCommitPullsList = (commitPullsList) => (commitPullsList.length ? commitPullsList[0].number : null);
const createCommentProxy = async (params) => { const createCommentProxy = async (params) => {
const { repoToken, owner, repo, issueNumber, body, proxyUrl } = params; const { repoToken, owner, repo, issueNumber, body, proxyUrl } = params;
@ -99,6 +89,7 @@ const run = async () => {
return; return;
} }
const [owner, repo] = repoFullName.split('/'); const [owner, repo] = repoFullName.split('/');
const octokit = github.getOctokit(repoToken);
let issueNumber; let issueNumber;
if (issue && issue.number) { if (issue && issue.number) {
issueNumber = issue.number; issueNumber = issue.number;
@ -108,15 +99,18 @@ const run = async () => {
} }
else { else {
// If this is not a pull request, attempt to find a PR matching the sha // If this is not a pull request, attempt to find a PR matching the sha
const commitPullsList = await listCommitPulls({ repoToken, owner, repo, commitSha }); const commitPullsList = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
issueNumber = commitPullsList && getIssueNumberFromCommitPullsList(commitPullsList); owner,
repo,
commit_sha: commitSha,
});
issueNumber = commitPullsList.data && getIssueNumberFromCommitPullsList(commitPullsList.data);
} }
if (!issueNumber) { if (!issueNumber) {
core.info('this action only works on issues and pull_request events or other commits associated with a pull'); core.info('this action only works on issues and pull_request events or other commits associated with a pull');
core.setOutput('comment-created', 'false'); core.setOutput('comment-created', 'false');
return; return;
} }
const octokit = github.getOctokit(repoToken);
let shouldCreateComment = true; let shouldCreateComment = true;
if (!allowRepeats) { if (!allowRepeats) {
core.debug('repeat comments are disallowed, checking for existing'); core.debug('repeat comments are disallowed, checking for existing');