Skip to content

Commit d2e95b0

Browse files
authored
Fix PR triage labeling and skip previously assessed PRs (#3996)
* Fix PR triage activation and skip prior assessments * Recognize the configured PR triage writer
1 parent 1a3b6a7 commit d2e95b0

5 files changed

Lines changed: 112 additions & 17 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$(dirname "$0")"
5+
export GH_REPO=fixture/fixture PR_TRIAGE_WRITER_LOGIN='triage-app[bot]'
6+
7+
gh() {
8+
if [[ $2 == --paginate ]]; then
9+
printf '[]\n'
10+
jq -nc --arg author "$author" --arg body "$body" '[{user:{login:$author}, body:$body}]'
11+
else
12+
echo false
13+
fi
14+
}
15+
export -f gh
16+
17+
check() {
18+
export author="$1" body="$2"
19+
local actual
20+
actual=$(bash pr-already-triaged.sh 1)
21+
if [[ $actual != "$3" ]]; then
22+
printf 'author=%s body=%s: expected %s, got %s\n' "$author" "$body" "$3" "$actual" >&2
23+
exit 1
24+
fi
25+
}
26+
27+
check 'triage-app[bot]' '### AI Assessment: Missing Details' true
28+
check 'github-actions[bot]' '### AI Assessment: Invalid' true
29+
check contributor '### AI Assessment: Missing Details' false
30+
check 'triage-app[bot]' 'Unrelated comment' false
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
pr="repos/${GH_REPO}/issues/$1"
5+
labels=$(gh api "$pr" --jq '[.labels[].name] | any(. == "waiting-for-reply" or . == "invalid")')
6+
if [[ "$labels" == true ]]; then
7+
echo true
8+
exit 0
9+
fi
10+
11+
# The assessment stays on the PR even after a maintainer removes its label.
12+
gh api --paginate "$pr/comments?per_page=100" \
13+
| jq --arg writer "${PR_TRIAGE_WRITER_LOGIN:?set the login that posts triage assessments}" \
14+
'any(.[]; (.user.login == "github-actions[bot]" or .user.login == $writer) and
15+
(.body | test("(?m)^### AI Assessment: (Invalid|Missing Details)\\s*$")))' \
16+
| jq -s 'any'

‎.github/workflows/pr-triage-dispatch.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
permissions:
99
actions: write
10+
contents: read
1011
pull-requests: read
1112

1213
concurrency:
@@ -21,10 +22,14 @@ jobs:
2122
MAX_RUNS_PER_DAY: 20
2223
MAX_ATTEMPTS_PER_PR: 2
2324
steps:
25+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26+
with:
27+
persist-credentials: false
2428
- name: Start triage for pull requests from external contributors
2529
env:
2630
GH_TOKEN: ${{ github.token }}
2731
GH_REPO: ${{ github.repository }}
32+
PR_TRIAGE_WRITER_LOGIN: ${{ vars.PR_TRIAGE_WRITER_LOGIN || (secrets.GH_AW_GITHUB_TOKEN == '' && 'github-actions[bot]') || '' }}
2833
run: |
2934
set -euo pipefail
3035
since=$(date -u -d '7 days ago' +%Y-%m-%d)
@@ -88,6 +93,11 @@ jobs:
8893
echo "Reached the limit of ${MAX_RUNS_PER_DAY} triage runs per day."
8994
break
9095
fi
96+
already_triaged=$(bash .github/scripts/pr-already-triaged.sh "$number")
97+
if [ "$already_triaged" = true ]; then
98+
echo "Skipping already triaged #${number}"
99+
continue
100+
fi
91101
gh workflow run pr-triage.lock.yml -f pr_number="$number"
92102
echo "Started triage for #${number}"
93103
started=$((started + 1))

‎.github/workflows/pr-triage.lock.yml‎

Lines changed: 36 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.github/workflows/pr-triage.md‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,40 @@ jobs:
3232
check:
3333
runs-on: ubuntu-latest
3434
permissions:
35+
contents: read
3536
pull-requests: read
3637
outputs:
37-
result: ${{ steps.check.outputs.result }}
38+
result: ${{ steps.check.outputs.verdict }}
3839
failed_sections: ${{ steps.check.outputs.failed_sections }}
3940
steps:
41+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
42+
with:
43+
persist-credentials: false
44+
- name: Check for prior triage
45+
id: prior
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
GH_REPO: ${{ github.repository }}
49+
# When overriding the safe-output token, set this repository variable to its comment author's login.
50+
PR_TRIAGE_WRITER_LOGIN: ${{ vars.PR_TRIAGE_WRITER_LOGIN || (secrets.GH_AW_GITHUB_TOKEN == '' && 'github-actions[bot]') || '' }}
51+
PR_NUMBER: ${{ inputs.pr_number }}
52+
run: |
53+
already_triaged=$(bash .github/scripts/pr-already-triaged.sh "$PR_NUMBER")
54+
echo "already_triaged=$already_triaged" >> "$GITHUB_OUTPUT"
4055
- name: Check the pull request against the template
4156
id: check
57+
if: steps.prior.outputs.already_triaged == 'false'
4258
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
4359
with:
4460
script: |
4561
const prNumber = Number(context.payload.inputs.pr_number);
4662
const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: prNumber });
4763
if (pr.state !== 'open' || pr.draft) {
48-
core.setOutput('result', 'skip');
64+
core.setOutput('verdict', 'skip');
4965
return;
5066
}
5167
if (pr.changed_files === 0) {
52-
core.setOutput('result', 'invalid');
68+
core.setOutput('verdict', 'invalid');
5369
return;
5470
}
5571
@@ -122,7 +138,7 @@ jobs:
122138
if (!lint || !(checked(lint) || hasText(lint))) failed.push('Lint & tests');
123139
requireBox('Docs');
124140
125-
core.setOutput('result', failed.length > 0 ? 'missing_details' : 'pass');
141+
core.setOutput('verdict', failed.length > 0 ? 'missing_details' : 'pass');
126142
core.setOutput('failed_sections', failed.join(', '));
127143
128144
tools:
@@ -135,9 +151,6 @@ tools:
135151
max-ai-credits: 100
136152

137153
safe-outputs:
138-
# Previews outputs in the run summary without writing anything. Remove this
139-
# line once the previews look right.
140-
staged: true
141154
# Keep run diagnostics in the Actions logs instead of public tracking issues.
142155
report-failure-as-issue: false
143156
report-missing-tool:

0 commit comments

Comments
 (0)