Skip to content

automerge-dependabot #35

automerge-dependabot

automerge-dependabot #35

# Automatically merge PRs from dependabot
name: "automerge-dependabot"
on:
workflow_run:
workflows: [ "ci" ]
types: [ "completed" ]
permissions:
contents: write
pull-requests: write
jobs:
Automerge:
runs-on: ubuntu-latest
if: |
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.ref == 'refs/heads/main'
steps:
- name: Merge PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (!context.payload.pull_request && (!context.payload.workflow_run.pull_requests || context.payload.workflow_run.pull_requests.length === 0)) {
console.log('Not Merged 🚫');
console.log('No pull_request found in payload.');
return;
}
const pr_number = context.payload.pull_request ? context.payload.pull_request.number : context.payload.workflow_run.pull_requests[0].number
console.log(`Merging PR <${pr_number}>... 🕜`);
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
});
if (pr.data.user.login !== 'dependabot[bot]') {
console.log('Not Merged 🚫');
console.log(`User <${pr.data.user.login}> does not equal <dependabot[bot]>`);
} else {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
});
console.log('Merged 🎉');
}