Skip to content

Commit 150e4a8

Browse files
committed
add dco-advisor
Signed-off-by: Michele Dolfi <[email protected]>
1 parent d13e103 commit 150e4a8

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

.github/workflows/dco-advisor.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: DCO Advisor Bot
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
check_run:
7+
types: [completed]
8+
9+
permissions:
10+
pull-requests: write
11+
issues: write
12+
13+
jobs:
14+
dco_advisor:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Handle DCO check result
18+
uses: actions/github-script@v7
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
script: |
22+
const pr = context.payload.pull_request || context.payload.check_run.pull_requests?.[0];
23+
if (!pr) return;
24+
25+
const prNumber = pr.number;
26+
const headSha = pr.head ? pr.head.sha : context.payload.check_run.head_sha;
27+
28+
const { data: checks } = await github.rest.checks.listForRef({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
ref: headSha
32+
});
33+
34+
const dcoCheck = checks.check_runs.find(run => run.name.toLowerCase().includes("dco"));
35+
if (!dcoCheck) return;
36+
37+
const { data: comments } = await github.rest.issues.listComments({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
issue_number: prNumber
41+
});
42+
43+
const botUsername = (await github.rest.users.getAuthenticated()).data.login;
44+
45+
const existingComment = comments.find(c =>
46+
c.user.login === botUsername &&
47+
c.body.includes("<!-- dco-advice-bot -->")
48+
);
49+
50+
const failureBody = `
51+
<!-- dco-advice-bot -->
52+
❌ **DCO Check Failed**
53+
54+
Hi @${pr.user.login}, your pull request has failed the Developer Certificate of Origin (DCO) check.
55+
56+
Because this repository supports **remediation commits**, you can fix this without rewriting history!
57+
58+
---
59+
60+
### 🛠 Quick Fix: Add a remediation commit
61+
\`\`\`bash
62+
git commit --allow-empty -s -m "chore: DCO remediation for failing commits"
63+
git push
64+
\`\`\`
65+
66+
This adds an empty signed commit to declare you agree with your previous commits.
67+
68+
---
69+
70+
<details>
71+
<summary>🔧 Advanced: Sign off each commit</summary>
72+
73+
If you prefer to re-sign your existing commits:
74+
75+
**For the latest commit:**
76+
\`\`\`bash
77+
git commit --amend --signoff
78+
git push --force
79+
\`\`\`
80+
81+
**For multiple commits:**
82+
\`\`\`bash
83+
git rebase --signoff origin/${pr.base.ref}
84+
git push --force-with-lease
85+
\`\`\`
86+
87+
</details>
88+
89+
---
90+
91+
More info: [DCO Fix Guide](https://github.com/probot/dco#how-it-works)
92+
`;
93+
94+
const successBody = `
95+
<!-- dco-advice-bot -->
96+
✅ **DCO Check Passed**
97+
98+
Thanks @${pr.user.login}, all your commits are properly signed off. 🎉
99+
`;
100+
101+
const newBody = dcoCheck.conclusion === "failure" ? failureBody : successBody;
102+
103+
if (existingComment) {
104+
await github.rest.issues.updateComment({
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
comment_id: existingComment.id,
108+
body: newBody
109+
});
110+
} else {
111+
await github.rest.issues.createComment({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
issue_number: prNumber,
115+
body: newBody
116+
});
117+
}

0 commit comments

Comments
 (0)