Skip to content

Commit

Permalink
Merge pull request #173565 from Homebrew/automerge-fork
Browse files Browse the repository at this point in the history
automerge-from-merge-queue: fix merging from forks
  • Loading branch information
MikeMcQuaid committed Jun 3, 2024
2 parents 698ead1 + b7fc97c commit e71ffc1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/automerge-from-merge-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ jobs:
id: pr
env:
GH_TOKEN: ${{ github.token }}
WORKFLOW_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
WORKFLOW_RUN_NODE_ID: ${{ github.event.workflow_run.node_id }}
QUERY: |-
query($url: URI!) {
resource(url: $url) {
query($id: ID!) {
node(id: $id) {
... on WorkflowRun {
checkSuite {
commit {
parents(last: 2) {
nodes {
oid
associatedPullRequests(last: 1) {
nodes {
number
Expand All @@ -72,13 +73,20 @@ jobs:
}
run: |
# Get the latest PR associated with the second parent of the merge commit created for the merge_group.
number="$(
head_commit_data="$(
gh api graphql \
--field url="$WORKFLOW_RUN_URL" \
--field id="$WORKFLOW_RUN_NODE_ID" \
--raw-field query="$QUERY" \
--jq '.data.resource.checkSuite.commit.parents.nodes |
last.associatedPullRequests.nodes[].number'
--jq '.data.node.checkSuite.commit.parents.nodes | last'
)"
number="$(jq --raw-output '.associatedPullRequests.nodes[].number' <<<"$head_commit_data")"
# Fall back to using the commit SHA if the associated PR is not available from the GraphQL API.
if [[ -z "$number" ]]
then
commit_sha="$(jq --raw-output '.oid' <<<"$head_commit_data")"
number="$(gh pr list --search "$commit_sha" --state open --limit 1 --json number --jq '.[].number')"
fi
if [[ -z "$number" ]]
then
Expand Down

0 comments on commit e71ffc1

Please sign in to comment.