Skip to content

Commit 9c58310

Browse files
authored
Use official auto-merge for repo-sync PRs (#17815)
* Remove automerge label from repo-sync PRs to prevent automerge workflow from kicking in * Add github-script step to enable GitHub's official auto-merge on repo-sync PRs * Remove unused variable
1 parent 2d0f1ab commit 9c58310

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/repo-sync.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
destination_branch: main
4141
pr_title: 'repo sync'
4242
pr_body: "This is an automated pull request to sync changes between the public and private repos.\n\n:robot: This pull request should be merged (not squashed) to preserve continuity across repos, so please let a bot do the merging!"
43-
pr_label: automerge,autoupdate,automated-reposync-pr
43+
pr_label: autoupdate,automated-reposync-pr
4444
github_token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
4545

4646
- name: Find pull request
@@ -88,6 +88,32 @@ jobs:
8888
console.log(`Branch is already up-to-date`)
8989
}
9090
91+
- name: Enable GitHub auto-merge
92+
if: ${{ steps.find-pull-request.outputs.number }}
93+
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
94+
with:
95+
github-token: ${{ secrets.GITHUB_TOKEN }}
96+
script: |
97+
const pull = await github.pulls.get({
98+
...context.repo,
99+
pull_number: parseInt(${{ steps.find-pull-request.outputs.number }})
100+
})
101+
102+
const pullNodeId = pull.data.node_id
103+
console.log(`Pull request GraphQL Node ID: ${pullNodeId}`)
104+
105+
const mutation = `mutation (id: String!) {
106+
enablePullRequestAutoMerge (input: {
107+
pullRequestId: $id,
108+
mergeMethod: MERGE
109+
})
110+
}`;
111+
const variables = {
112+
id: pullNodeId
113+
}
114+
await github.graphql(mutation, variables)
115+
console.log('Auto-merge enabled!')
116+
91117
- name: Send Slack notification if workflow fails
92118
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
93119
if: failure()

0 commit comments

Comments
 (0)