ci: add dco-advisor #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: DCO Advisor Bot | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| check_run: | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| dco_advisor: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Handle DCO check result | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const pr = context.payload.pull_request || context.payload.check_run.pull_requests?.[0]; | |
| if (!pr) return; | |
| const prNumber = pr.number; | |
| const headSha = pr.head ? pr.head.sha : context.payload.check_run.head_sha; | |
| const { data: checks } = await github.rest.checks.listForRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: headSha | |
| }); | |
| const dcoCheck = checks.check_runs.find(run => run.name.toLowerCase().includes("dco")); | |
| if (!dcoCheck) return; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber | |
| }); | |
| const botUsername = (await github.rest.users.getAuthenticated()).data.login; | |
| const existingComment = comments.find(c => | |
| c.user.login === botUsername && | |
| c.body.includes("<!-- dco-advice-bot -->") | |
| ); | |
| const failureBody = [ | |
| '<!-- dco-advice-bot -->', | |
| '❌ **DCO Check Failed**', | |
| '', | |
| `Hi @${pr.user.login}, your pull request has failed the Developer Certificate of Origin (DCO) check.`, | |
| '', | |
| 'Because this repository supports **remediation commits**, you can fix this without rewriting history!', | |
| '', | |
| '---', | |
| '', | |
| '### 🛠 Quick Fix: Add a remediation commit', | |
| '```bash', | |
| 'git commit --allow-empty -s -m "chore: DCO remediation for failing commits"', | |
| 'git push', | |
| '```', | |
| '', | |
| 'This adds an empty signed commit to declare you agree with your previous commits.', | |
| '', | |
| '---', | |
| '', | |
| '<details>', | |
| '<summary>🔧 Advanced: Sign off each commit</summary>', | |
| '', | |
| 'If you prefer to re-sign your existing commits:', | |
| '', | |
| '**For the latest commit:**', | |
| '```bash', | |
| 'git commit --amend --signoff', | |
| 'git push --force', | |
| '```', | |
| '', | |
| '**For multiple commits:**', | |
| '```bash', | |
| `git rebase --signoff origin/${pr.base.ref}`, | |
| 'git push --force-with-lease', | |
| '```', | |
| '', | |
| '</details>', | |
| '', | |
| '---', | |
| '', | |
| 'More info: [DCO Fix Guide](https://github.com/probot/dco#how-it-works)' | |
| ].join('\n'); | |
| const successBody = [ | |
| '<!-- dco-advice-bot -->', | |
| '✅ **DCO Check Passed**', | |
| '', | |
| `Thanks @${pr.user.login}, all your commits are properly signed off. 🎉` | |
| ].join('\n'); | |
| const newBody = dcoCheck.conclusion === "failure" ? failureBody : successBody; | |
| if (existingComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| body: newBody | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: newBody | |
| }); | |
| } |