|
1 | 1 | name: DCO Assistant for First-Time Contributors |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
5 | | - types: [opened] |
| 4 | + check_run: |
| 5 | + types: [completed] |
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | dco-help: |
9 | 9 | 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 |
11 | 14 | 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 |
14 | 18 | 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 | +
|
15 | 41 | - name: Post DCO Instructions |
| 42 | + if: steps.pr-context.outputs.should_comment == 'true' |
16 | 43 | uses: peter-evans/create-or-update-comment@v3 |
17 | 44 | with: |
18 | | - issue-number: ${{ github.event.pull_request.number }} |
| 45 | + issue-number: ${{ steps.pr-context.outputs.pr_number }} |
19 | 46 | body: | |
20 | 47 | 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 | +
|
24 | 51 | 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: |
25 | 52 | `git commit -s -m "Your message"` |
26 | | - |
| 53 | +
|
27 | 54 | For existing commits, you can fix them with: |
28 | 55 | `git commit --amend --signoff` or `git rebase -i HEAD~N --signoff` (where N is the number of commits) |
29 | 56 | 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