name: Approve Merged Contributor on: pull_request_target: types: [closed] jobs: approve: if: ${{ github.event.pull_request.merged == true }} runs-on: ubuntu-latest permissions: contents: write pull-requests: read steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.event.repository.default_branch }} - name: Add merged contributor to approved list id: update uses: actions/github-script@v7 with: script: | const fs = require('fs'); const prAuthor = context.payload.pull_request.user.login; const approvedFile = '.github/APPROVED_CONTRIBUTORS'; if (prAuthor.endsWith('[bot]') || prAuthor === 'dependabot[bot]') { console.log(`Skipping bot: ${prAuthor}`); core.setOutput('status', 'skipped'); return; } let content = fs.readFileSync(approvedFile, 'utf8'); const approvedList = content .split('\n') .map(line => line.trim().toLowerCase()) .filter(line => line && !line.startsWith('#')); if (approvedList.includes(prAuthor.toLowerCase())) { console.log(`${prAuthor} is already approved`); core.setOutput('status', 'already'); return; } content = content.trimEnd() + '\n' + prAuthor + '\n'; fs.writeFileSync(approvedFile, content); console.log(`Added ${prAuthor} to approved contributors`); core.setOutput('status', 'added'); - name: Commit and push if: steps.update.outputs.status == 'added' run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add .github/APPROVED_CONTRIBUTORS git diff --staged --quiet || git commit -m "chore: approve merged contributor ${{ github.event.pull_request.user.login }}" git push