Skip to content

Commit cf7f4fb

Browse files
authored
Tweak DCO bot to only comment when the check fails. (#723)
Signed-off-by: fruffy <fruffy@nyu.edu>
1 parent 81d1287 commit cf7f4fb

1 file changed

Lines changed: 37 additions & 10 deletions

File tree

.github/workflows/dco-welcome.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
name: DCO Assistant for First-Time Contributors
22

33
on:
4-
pull_request_target:
5-
types: [opened]
4+
check_run:
5+
types: [completed]
66

77
jobs:
88
dco-help:
99
runs-on: ubuntu-latest
10-
# Only run for first-time contributors or users with no previous history
10+
permissions:
11+
contents: read
12+
issues: write
13+
pull-requests: write
1114
if: |
12-
github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' ||
13-
github.event.pull_request.author_association == 'NONE'
15+
github.event.check_run.conclusion == 'failure' &&
16+
contains(github.event.check_run.name, 'DCO') &&
17+
github.event.check_run.pull_requests[0] != null
1418
steps:
19+
- name: Load PR Context
20+
id: pr-context
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const prs = context.payload.check_run.pull_requests || [];
25+
if (prs.length === 0) {
26+
core.setOutput('should_comment', 'false');
27+
return;
28+
}
29+
30+
const prNumber = prs[0].number;
31+
const { data: pr } = await github.rest.pulls.get({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
pull_number: prNumber,
35+
});
36+
37+
const shouldComment = ['FIRST_TIME_CONTRIBUTOR', 'NONE'].includes(pr.author_association);
38+
core.setOutput('pr_number', String(prNumber));
39+
core.setOutput('should_comment', shouldComment ? 'true' : 'false');
40+
1541
- name: Post DCO Instructions
42+
if: steps.pr-context.outputs.should_comment == 'true'
1643
uses: peter-evans/create-or-update-comment@v3
1744
with:
18-
issue-number: ${{ github.event.pull_request.number }}
45+
issue-number: ${{ steps.pr-context.outputs.pr_number }}
1946
body: |
2047
Welcome to the project, @${{ github.actor }}!
21-
22-
It looks like this is your first contribution. We noticed the **DCO (Developer Certificate of Origin)** check might fail if your commits aren't signed.
23-
48+
49+
It looks like this is your first contribution. We noticed the **DCO (Developer Certificate of Origin)** check might fail if your commits aren't signed.
50+
2451
To fix this, please ensure every commit has a `Signed-off-by: Name <email>` line. You can do this automatically by using the `-s` flag:
2552
`git commit -s -m "Your message"`
26-
53+
2754
For existing commits, you can fix them with:
2855
`git commit --amend --signoff` or `git rebase -i HEAD~N --signoff` (where N is the number of commits)
2956
The Developer Community DCO guide also provides helpful tips on fixing DCO inconveniences. Setting a commit hook in the git repository will automate adding the DCO signoff.

0 commit comments

Comments
 (0)