Skip to content

Automated Formatting Fixes #94

Automated Formatting Fixes

Automated Formatting Fixes #94

name: Auto Approve and Merge
on:
pull_request:
types:
- opened
- synchronize
jobs:
auto-approve-and-merge:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
checks: read
statuses: read
if: github.actor == 'github-actions[bot]' && (github.event.pull_request.head.ref == 'license-header-updates' || github.event.pull_request.head.ref == 'formatting-fixes')
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ vars.GH_APP_ID }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Auto-approve pull request
uses: hmarr/auto-approve-action@v2
with:
github-token: ${{ steps.generate_token.outputs.token }}
- name: Wait for status checks to pass
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const pull_number = context.payload.pull_request.number;
const requiredChecks = ['Rust CI']; // Update with your actual status check names
async function waitForChecks() {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
while (true) {
const { data: pr } = await github.pulls.get({
owner,
repo,
pull_number,
});
const { data: combinedStatus } = await github.repos.getCombinedStatusForRef({
owner,
repo,
ref: pr.head.sha,
});
const statuses = combinedStatus.statuses;
let allChecksPassed = true;
for (const checkName of requiredChecks) {
const check = statuses.find((status) => status.context === checkName);
if (!check || check.state !== 'success') {
allChecksPassed = false;
break;
}
}
if (allChecksPassed) {
return;
} else {
// Wait 10 seconds before checking again
await delay(10000);
}
}
}
await waitForChecks();
- name: Merge pull request
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
merge_method: 'squash',
})