Skip to content

Commit

Permalink
Merge pull request #25 from PetrHeinz/patch-1
Browse files Browse the repository at this point in the history
Prefer PR which has HEAD on requested commit
  • Loading branch information
8BitJonny authored Nov 28, 2021
2 parents a29e7e9 + c6fa088 commit 75c186f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ const getInputBool = (name, defaultValue = false) => {

async function main() {
const token = getInput('github-token', { required: true });
const sha = getInput('sha');
const sha = getInput('sha') || context.sha;
const filterOutClosed = getInputBool('filterOutClosed');

const result = await new GitHub(token, {}).repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: sha || context.sha,
commit_sha: sha,
});

let pr = result.data.length > 0 && result.data[0];
const pullRequests = result.data.filter((pullRequest) => pullRequest.state === 'open' || !filterOutClosed);

if (filterOutClosed === true) {
pr = pr.state === 'open' && pr
}
let pr = pullRequests.length > 0 && pullRequests[0];
pullRequests.forEach(pullRequest => pullRequest.head.sha.startsWith(sha) && (pr = pullRequest));

setOutput('number', pr && pr.number.toString() || '');
setOutput('pr', pr ? JSON.stringify(pr) : '');
Expand Down

0 comments on commit 75c186f

Please sign in to comment.