From 7238e87e37e8526085c4e82f6b26fc293515435b Mon Sep 17 00:00:00 2001 From: Michael Shick Date: Sat, 5 Nov 2022 12:44:51 -0400 Subject: [PATCH] update build --- lib/main.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/main.js b/lib/main.js index 32a9c32..9c0a89a 100644 --- a/lib/main.js +++ b/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');