Skip to content

Commit 4c2df3c

Browse files
committed
Refactor out a function to determine the SHA for a PR
This functionality is used already for the `/deploy` command, and we are about to need it also in the `/git-artifacts` and `/release` commands. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4064d75 commit 4c2df3c

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

GitForWindowsHelper/issues.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ const createReactionForIssueComment = async (context, token, owner, repo, commen
5252
return answer.id
5353
}
5454

55+
const getPRCommitSHA = async (context, token, owner, repo, pullRequestNumber) => {
56+
const answer = await sendGitHubAPIRequest(
57+
context,
58+
token,
59+
'GET',
60+
`/repos/${owner}/${repo}/pulls/${pullRequestNumber}`
61+
)
62+
return answer.head.sha
63+
}
64+
5565
module.exports = {
5666
addIssueComment,
5767
getIssue,
5868
getIssueComment,
5969
appendToIssueComment,
60-
createReactionForIssueComment
70+
createReactionForIssueComment,
71+
getPRCommitSHA
6172
}

GitForWindowsHelper/slash-commands.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,8 @@ module.exports = async (context, req) => {
123123
// The commit hash of the tip commit is sadly not part of the
124124
// "comment.created" webhook's payload. Therefore, we have to get it
125125
// "by hand"
126-
const githubApiRequest = require('./github-api-request')
127-
const { head: { sha: ref } } = await githubApiRequest(
128-
console,
129-
null,
130-
'GET',
131-
`/repos/${owner}/${repo}/pulls/${issueNumber}`
132-
)
126+
const { getPRCommitSHA } = require('./issues')
127+
const ref = await getPRCommitSHA(console, await getToken(), owner, repo, issueNumber)
133128

134129
await thumbsUp()
135130

0 commit comments

Comments
 (0)