Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/scripts/pr-already-triaged-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")"
export GH_REPO=fixture/fixture PR_TRIAGE_WRITER_LOGIN='triage-app[bot]'

gh() {
if [[ $2 == --paginate ]]; then
printf '[]\n'
jq -nc --arg author "$author" --arg body "$body" '[{user:{login:$author}, body:$body}]'
else
echo false
fi
}
export -f gh

check() {
export author="$1" body="$2"
local actual
actual=$(bash pr-already-triaged.sh 1)
if [[ $actual != "$3" ]]; then
printf 'author=%s body=%s: expected %s, got %s\n' "$author" "$body" "$3" "$actual" >&2
exit 1
fi
}

check 'triage-app[bot]' '### AI Assessment: Missing Details' true
check 'github-actions[bot]' '### AI Assessment: Invalid' true
check contributor '### AI Assessment: Missing Details' false
check 'triage-app[bot]' 'Unrelated comment' false
16 changes: 16 additions & 0 deletions .github/scripts/pr-already-triaged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

pr="repos/${GH_REPO}/issues/$1"
labels=$(gh api "$pr" --jq '[.labels[].name] | any(. == "waiting-for-reply" or . == "invalid")')
if [[ "$labels" == true ]]; then
echo true
exit 0
fi

# The assessment stays on the PR even after a maintainer removes its label.
gh api --paginate "$pr/comments?per_page=100" \
| jq --arg writer "${PR_TRIAGE_WRITER_LOGIN:?set the login that posts triage assessments}" \
'any(.[]; (.user.login == "github-actions[bot]" or .user.login == $writer) and
(.body | test("(?m)^### AI Assessment: (Invalid|Missing Details)\\s*$")))' \
| jq -s 'any'
10 changes: 10 additions & 0 deletions .github/workflows/pr-triage-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

permissions:
actions: write
contents: read
pull-requests: read

concurrency:
Expand All @@ -21,10 +22,14 @@ jobs:
MAX_RUNS_PER_DAY: 20
MAX_ATTEMPTS_PER_PR: 2
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Start triage for pull requests from external contributors
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_TRIAGE_WRITER_LOGIN: ${{ vars.PR_TRIAGE_WRITER_LOGIN || (secrets.GH_AW_GITHUB_TOKEN == '' && 'github-actions[bot]') || '' }}
run: |
set -euo pipefail
since=$(date -u -d '7 days ago' +%Y-%m-%d)
Expand Down Expand Up @@ -88,6 +93,11 @@ jobs:
echo "Reached the limit of ${MAX_RUNS_PER_DAY} triage runs per day."
break
fi
already_triaged=$(bash .github/scripts/pr-already-triaged.sh "$number")
if [ "$already_triaged" = true ]; then
echo "Skipping already triaged #${number}"
continue
fi
gh workflow run pr-triage.lock.yml -f pr_number="$number"
echo "Started triage for #${number}"
started=$((started + 1))
Expand Down
46 changes: 36 additions & 10 deletions .github/workflows/pr-triage.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions .github/workflows/pr-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,40 @@ jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
result: ${{ steps.check.outputs.result }}
result: ${{ steps.check.outputs.verdict }}
failed_sections: ${{ steps.check.outputs.failed_sections }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check for prior triage
id: prior
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
# When overriding the safe-output token, set this repository variable to its comment author's login.
PR_TRIAGE_WRITER_LOGIN: ${{ vars.PR_TRIAGE_WRITER_LOGIN || (secrets.GH_AW_GITHUB_TOKEN == '' && 'github-actions[bot]') || '' }}
PR_NUMBER: ${{ inputs.pr_number }}
run: |
already_triaged=$(bash .github/scripts/pr-already-triaged.sh "$PR_NUMBER")
echo "already_triaged=$already_triaged" >> "$GITHUB_OUTPUT"
- name: Check the pull request against the template
id: check
if: steps.prior.outputs.already_triaged == 'false'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const prNumber = Number(context.payload.inputs.pr_number);
const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: prNumber });
if (pr.state !== 'open' || pr.draft) {
core.setOutput('result', 'skip');
core.setOutput('verdict', 'skip');
return;
}
if (pr.changed_files === 0) {
core.setOutput('result', 'invalid');
core.setOutput('verdict', 'invalid');
return;
}
Expand Down Expand Up @@ -122,7 +138,7 @@ jobs:
if (!lint || !(checked(lint) || hasText(lint))) failed.push('Lint & tests');
requireBox('Docs');
core.setOutput('result', failed.length > 0 ? 'missing_details' : 'pass');
core.setOutput('verdict', failed.length > 0 ? 'missing_details' : 'pass');
core.setOutput('failed_sections', failed.join(', '));
tools:
Expand All @@ -135,9 +151,6 @@ tools:
max-ai-credits: 100

safe-outputs:
# Previews outputs in the run summary without writing anything. Remove this
# line once the previews look right.
staged: true
# Keep run diagnostics in the Actions logs instead of public tracking issues.
report-failure-as-issue: false
report-missing-tool:
Expand Down
Loading