mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 09:36:20 +09:00
actions/get-merge-conflict: refactor
Using core.setOutput is much nicer than having to parse the json "result" on the outside. This also avoids some very odd errors, when the result can, for unknown reasons, *not* be parsed as JSON later on. Also avoiding a bit of duplication between the "if mergeable" branches.
This commit is contained in:
parent
cd9a22d753
commit
539e8d4f66
1 changed files with 14 additions and 15 deletions
29
.github/actions/get-merge-commit/action.yml
vendored
29
.github/actions/get-merge-commit/action.yml
vendored
|
@ -5,10 +5,10 @@ description: 'Checks whether the Pull Request is mergeable and returns two commi
|
|||
outputs:
|
||||
mergedSha:
|
||||
description: "The merge commit SHA"
|
||||
value: ${{ fromJSON(steps.merged.outputs.result).mergedSha }}
|
||||
value: ${{ steps.merged.outputs.mergedSha }}
|
||||
targetSha:
|
||||
description: "The target commit SHA"
|
||||
value: ${{ fromJSON(steps.merged.outputs.result).targetSha }}
|
||||
value: ${{ steps.merged.outputs.targetSha }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
|
@ -17,7 +17,7 @@ runs:
|
|||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||
with:
|
||||
script: |
|
||||
if (context.eventName == 'push') return { mergedSha: context.sha }
|
||||
if (context.eventName == 'push') return core.setOutput('mergedSha', context.sha)
|
||||
|
||||
for (const retryInterval of [5, 10, 20, 40, 80]) {
|
||||
console.log("Checking whether the pull request can be merged...")
|
||||
|
@ -35,32 +35,31 @@ runs:
|
|||
continue
|
||||
}
|
||||
|
||||
let mergedSha, targetSha
|
||||
|
||||
if (prInfo.mergeable) {
|
||||
console.log("The PR can be merged.")
|
||||
|
||||
const mergedSha = prInfo.merge_commit_sha
|
||||
const targetSha = (await github.rest.repos.getCommit({
|
||||
mergedSha = prInfo.merge_commit_sha
|
||||
targetSha = (await github.rest.repos.getCommit({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: prInfo.merge_commit_sha
|
||||
})).data.parents[0].sha
|
||||
|
||||
console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`)
|
||||
|
||||
return { mergedSha, targetSha }
|
||||
} else {
|
||||
console.log("The PR has a merge conflict.")
|
||||
|
||||
const mergedSha = prInfo.head.sha
|
||||
const targetSha = (await github.rest.repos.compareCommitsWithBasehead({
|
||||
mergedSha = prInfo.head.sha
|
||||
targetSha = (await github.rest.repos.compareCommitsWithBasehead({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
basehead: `${prInfo.base.sha}...${prInfo.head.sha}`
|
||||
})).data.merge_base_commit.sha
|
||||
|
||||
console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`)
|
||||
|
||||
return { mergedSha, targetSha }
|
||||
}
|
||||
|
||||
console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`)
|
||||
core.setOutput('mergedSha', mergedSha)
|
||||
core.setOutput('targetSha', targetSha)
|
||||
return
|
||||
}
|
||||
throw new Error("Not retrying anymore. It's likely that GitHub is having internal issues: check https://www.githubstatus.com.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue