Skip to content

Commit

Permalink
chore: add auto merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oceanroleplay committed Dec 7, 2021
1 parent f4c8a00 commit 7336e8d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/Auto Merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Auto Merge
on:
pull_request_target:
branches: [main]

jobs:
publish:
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Enable AutoMerge
uses: actions/github-script@v5
with:
script: |
const queryOne = `query GetPullRequestId($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pullRequestNumber) {
id
}
}
}`
const variablesOne = {
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pullRequestNumber: context.payload.pull_request.number
}
const resultOne = await github.graphql(queryOne, variablesOne)
const pullRequestId = resultOne.repository.pullRequest.id
const queryTwo = `mutation ($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {
enablePullRequestAutoMerge(input: {
pullRequestId: $pullRequestId,
mergeMethod: $mergeMethod
}) {
pullRequest {
autoMergeRequest {
enabledAt
enabledBy {
login
}
}
}
}
}`
const variablesTwo = {
pullRequestId: pullRequestId,
mergeMethod: 'SQUASH'
}
const resultTwo = await github.graphql(queryTwo, variablesTwo)
console.log(resultTwo.enablePullRequestAutoMerge.pullRequest.autoMergeRequest)
github-token: ${{github.token}}

- name: Approve PR
uses: actions/github-script@v5
with:
script: |
github.rest.pulls.createReview({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: context.payload.pull_request.number,
event: 'APPROVE'
})
github-token: ${{github.token}}

0 comments on commit 7336e8d

Please sign in to comment.