|
1 | | -name: Welcome first-time contributors |
| 1 | +name: Contributor guidance |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request_target: |
|
7 | 7 | permissions: {} |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - first_time_contributor: |
11 | | - name: Is first-time contributor |
12 | | - # GitHub can report first-time contributors as NONE in the event payload. |
| 10 | + contributor: |
| 11 | + name: Resolve contributor status |
| 12 | + # Use the event only to exclude trusted associations, mannequins, and bots. |
| 13 | + # Resolve every potentially external contributor with a privileged API request. |
13 | 14 | if: >- |
14 | 15 | github.run_attempt == 1 && |
15 | 16 | github.repository == 'nodejs/node' && |
16 | | - (github.event.pull_request.author_association == 'FIRST_TIMER' || |
| 17 | + github.event.pull_request.user.type != 'Bot' && |
| 18 | + (github.event.pull_request.author_association == 'CONTRIBUTOR' || |
| 19 | + github.event.pull_request.author_association == 'FIRST_TIMER' || |
17 | 20 | github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' || |
18 | 21 | github.event.pull_request.author_association == 'NONE') |
19 | 22 | runs-on: ubuntu-slim |
20 | | - permissions: |
21 | | - pull-requests: read |
22 | 23 | outputs: |
23 | | - eligible: >- |
24 | | - ${{ |
25 | | - github.event.pull_request.author_association != 'NONE' || |
26 | | - steps.recheck.outputs.eligible == 'true' |
27 | | - }} |
| 24 | + is_first_time: ${{ steps.resolve.outputs.is_first_time }} |
| 25 | + should_scan: ${{ steps.resolve.outputs.should_scan }} |
28 | 26 | steps: |
29 | | - - name: Recheck contributor eligibility |
30 | | - id: recheck |
31 | | - if: github.event.pull_request.author_association == 'NONE' |
| 27 | + - name: Check author association |
| 28 | + id: resolve |
32 | 29 | env: |
33 | | - GH_TOKEN: ${{ github.token }} |
| 30 | + GH_TOKEN: ${{ secrets.GH_USER_TOKEN }} |
34 | 31 | NUMBER: ${{ github.event.pull_request.number }} |
35 | 32 | run: | |
36 | 33 | started_at=$SECONDS |
37 | | - for delay in 15 30 60 120; do |
| 34 | + # TODO: Remove the retries once privileged API requests are confirmed |
| 35 | + # to return the association immediately. |
| 36 | + for delay in 0 15 30 60; do |
38 | 37 | sleep "$delay" |
39 | 38 | association=$(gh api "/repos/$GITHUB_REPOSITORY/pulls/$NUMBER" \ |
40 | 39 | --jq '.author_association') |
@@ -43,60 +42,66 @@ jobs: |
43 | 42 |
|
44 | 43 | case "$association" in |
45 | 44 | FIRST_TIMER|FIRST_TIME_CONTRIBUTOR) |
46 | | - echo 'eligible=true' >> "$GITHUB_OUTPUT" |
| 45 | + echo 'is_first_time=true' >> "$GITHUB_OUTPUT" |
| 46 | + echo 'should_scan=true' >> "$GITHUB_OUTPUT" |
| 47 | + exit 0 |
| 48 | + ;; |
| 49 | + CONTRIBUTOR) |
| 50 | + echo 'is_first_time=false' >> "$GITHUB_OUTPUT" |
| 51 | + echo 'should_scan=true' >> "$GITHUB_OUTPUT" |
47 | 52 | exit 0 |
48 | 53 | ;; |
49 | 54 | NONE) |
50 | 55 | ;; |
51 | | - *) |
52 | | - echo 'eligible=false' >> "$GITHUB_OUTPUT" |
| 56 | + COLLABORATOR|MANNEQUIN|MEMBER|OWNER) |
| 57 | + echo 'is_first_time=false' >> "$GITHUB_OUTPUT" |
| 58 | + echo 'should_scan=false' >> "$GITHUB_OUTPUT" |
53 | 59 | exit 0 |
54 | 60 | ;; |
| 61 | + *) |
| 62 | + echo "Unexpected author association: $association" >&2 |
| 63 | + exit 1 |
| 64 | + ;; |
55 | 65 | esac |
56 | 66 | done |
57 | 67 |
|
58 | | - echo 'eligible=false' >> "$GITHUB_OUTPUT" |
| 68 | + # NONE is unresolved, not trusted. Scan without posting the welcome. |
| 69 | + echo 'is_first_time=false' >> "$GITHUB_OUTPUT" |
| 70 | + echo 'should_scan=true' >> "$GITHUB_OUTPUT" |
59 | 71 |
|
60 | | - agentscan: |
61 | | - needs: first_time_contributor |
62 | | - if: needs.first_time_contributor.outputs.eligible == 'true' |
| 72 | + guidance: |
| 73 | + name: Apply contributor guidance |
| 74 | + needs: contributor |
| 75 | + if: needs.contributor.outputs.should_scan == 'true' |
63 | 76 | runs-on: ubuntu-slim |
64 | 77 | permissions: |
65 | 78 | contents: read |
66 | | - outputs: |
67 | | - scan_outcome: ${{ steps.scan.outcome }} |
68 | | - classification: ${{ steps.scan.outputs.classification }} |
69 | | - community_flagged: ${{ steps.scan.outputs['community-flagged'] }} |
| 79 | + pull-requests: write |
70 | 80 | steps: |
71 | 81 | - name: Scan contributor activity |
72 | | - id: scan |
| 82 | + id: agentscan |
73 | 83 | # The welcome should still be posted if this advisory scan fails. |
74 | 84 | continue-on-error: true |
75 | | - uses: MatteoGabriele/agentscan-action@98202262c925c508d4c1424b1dfbe17ee35b0c02 # v2.4.0 |
| 85 | + uses: MatteoGabriele/agentscan-action@8112fb79b33fafb8506159df20129a34209ac410 # v2.5.0 |
76 | 86 | with: |
77 | 87 | github-token: ${{ github.token }} |
78 | | - mode: silent |
| 88 | + mode: labels |
79 | 89 | scan-pull-requests: true |
80 | 90 | scan-issues: false |
81 | 91 | auto-close: false |
82 | 92 | honeypot: false |
83 | 93 |
|
84 | | - comment: |
85 | | - needs: |
86 | | - - first_time_contributor |
87 | | - - agentscan |
88 | | - if: needs.first_time_contributor.outputs.eligible == 'true' |
89 | | - runs-on: ubuntu-slim |
90 | | - permissions: |
91 | | - pull-requests: write |
92 | | - steps: |
93 | | - - name: Welcome first-time contributor |
| 94 | + - name: Comment with contributor guidance |
94 | 95 | env: |
| 96 | + ADD_CAUTION: >- |
| 97 | + ${{ |
| 98 | + steps.agentscan.outputs.classification == 'mixed' || |
| 99 | + steps.agentscan.outputs.classification == 'automation' || |
| 100 | + steps.agentscan.outputs['community-flagged'] == 'true' |
| 101 | + }} |
95 | 102 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + IS_FIRST_TIME: ${{ needs.contributor.outputs.is_first_time }} |
96 | 104 | NUMBER: ${{ github.event.pull_request.number }} |
97 | | - AGENTSCAN_OUTCOME: ${{ needs.agentscan.outputs.scan_outcome }} |
98 | | - AGENTSCAN_CLASSIFICATION: ${{ needs.agentscan.outputs.classification }} |
99 | | - AGENTSCAN_COMMUNITY_FLAGGED: ${{ needs.agentscan.outputs.community_flagged }} |
100 | 105 | WELCOME_MESSAGE: >2- |
101 | 106 | Welcome to Node.js, and thank you for your first contribution! |
102 | 107 |
|
@@ -128,20 +133,15 @@ jobs: |
128 | 133 | [automation policy](https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md#automation-and-bots) |
129 | 134 | for additional context. |
130 | 135 | run: | |
131 | | - add_caution=false |
132 | | - if [[ "$AGENTSCAN_OUTCOME" == "success" ]]; then |
133 | | - case "$AGENTSCAN_CLASSIFICATION" in |
134 | | - mixed|automation) |
135 | | - add_caution=true |
136 | | - ;; |
137 | | - esac |
138 | | - if [[ "$AGENTSCAN_COMMUNITY_FLAGGED" == "true" ]]; then |
139 | | - add_caution=true |
140 | | - fi |
| 136 | + if [[ "$IS_FIRST_TIME" == "true" && "$ADD_CAUTION" == "true" ]]; then |
| 137 | + body="$WELCOME_MESSAGE"$'\n\n'"$CAUTION_MESSAGE" |
| 138 | + elif [[ "$IS_FIRST_TIME" == "true" ]]; then |
| 139 | + body="$WELCOME_MESSAGE" |
| 140 | + elif [[ "$ADD_CAUTION" == "true" ]]; then |
| 141 | + body="$CAUTION_MESSAGE" |
| 142 | + else |
| 143 | + exit 0 |
141 | 144 | fi |
142 | 145 |
|
143 | | - if [[ "$add_caution" == "true" ]]; then |
144 | | - printf '%s\n\n%s\n' "$WELCOME_MESSAGE" "$CAUTION_MESSAGE" |
145 | | - else |
146 | | - printf '%s\n' "$WELCOME_MESSAGE" |
147 | | - fi | gh pr comment "$NUMBER" --repo "$GITHUB_REPOSITORY" --body-file - |
| 146 | + printf '%s\n' "$body" | |
| 147 | + gh pr comment "$NUMBER" --repo "$GITHUB_REPOSITORY" --body-file - |