diff --git a/.github/workflows/preloop-triage.yml b/.github/workflows/preloop-triage.yml new file mode 100644 index 0000000..0c300ae --- /dev/null +++ b/.github/workflows/preloop-triage.yml @@ -0,0 +1,108 @@ +# Surface Preloop PR review comments. Label + sticky checklist only. No secrets. +# Reviews themselves come from Preloop Cloud flow "DD - Pull Request Reviewer". + +name: preloop triage + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + triage: + name: label + checklist + runs-on: ubuntu-latest + timeout-minutes: 5 + if: > + github.event.sender.login == 'preloop[bot]' && + ( + (github.event_name == 'issue_comment' && + github.event.issue.pull_request != null && + contains(github.event.comment.body, 'preloop-review:flow-id:pr-reviewer')) || + (github.event_name == 'pull_request_review_comment' && + contains(github.event.comment.body, 'preloop-review:flow-id:pr-reviewer')) + ) + steps: + - name: Resolve PR number + id: pr + env: + EVENT_NAME: ${{ github.event_name }} + ISSUE_NUMBER: ${{ github.event.issue.number }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + if [[ "$EVENT_NAME" == "issue_comment" ]]; then + echo "number=${ISSUE_NUMBER}" >> "$GITHUB_OUTPUT" + else + echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" + fi + + - name: Ensure label preloop-triage + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + if ! gh label list --repo "$REPO" --limit 200 --json name \ + --jq '.[].name' | grep -qx 'preloop-triage'; then + gh label create preloop-triage --repo "$REPO" \ + --color BFD4F2 --description "Preloop left PR review findings to triage" + fi + + - name: Label PR + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR: ${{ steps.pr.outputs.number }} + run: | + set -euo pipefail + gh pr edit "$PR" --repo "$REPO" --add-label preloop-triage + + - name: Upsert sticky triage checklist + if: github.event_name == 'issue_comment' + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR: ${{ steps.pr.outputs.number }} + COMMENT_URL: ${{ github.event.comment.html_url }} + run: | + set -euo pipefail + MARKER='' + BODY=$(cat </dev/null + else + gh api --method POST "repos/${REPO}/issues/${PR}/comments" \ + -f body="$BODY" >/dev/null + fi diff --git a/docs/CI.md b/docs/CI.md new file mode 100644 index 0000000..ca1ce14 --- /dev/null +++ b/docs/CI.md @@ -0,0 +1,16 @@ +# CI + +**Godot:** workflow [`.github/workflows/godot-headless.yml`](../.github/workflows/godot-headless.yml) — self-hosted headless bake. Not a required merge check. + +**Preloop:** Cloud flow **DD - Pull Request Reviewer** now includes this repo. It comments on PRs asynchronously. It does **not** block Godot CI. + +| Piece | Detail | +|-------|--------| +| Findings | `preloop[bot]` summary + inline comments | +| Surface | [`.github/workflows/preloop-triage.yml`](../.github/workflows/preloop-triage.yml) labels `preloop-triage` | +| Fetch | [`scripts/fetch-preloop-pr.sh`](../scripts/fetch-preloop-pr.sh) | + +```bash +./scripts/fetch-preloop-pr.sh 7 +gh pr list --label preloop-triage +``` diff --git a/scripts/fetch-preloop-pr.sh b/scripts/fetch-preloop-pr.sh new file mode 100755 index 0000000..5a87e0a --- /dev/null +++ b/scripts/fetch-preloop-pr.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Fetch Preloop (preloop[bot]) summary + inline review comments for a PR. +set -euo pipefail + +PR="${1:-}" +if [[ -z "$PR" || "$PR" == "-h" || "$PR" == "--help" ]]; then + echo "usage: $0 " >&2 + exit 2 +fi + +REPO="${REPO:-}" +if [[ -z "$REPO" ]]; then + REPO="$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null || true)" +fi +REPO="${REPO:-DynamicDevices/godot-cnc-toolpath}" + +echo "=== Preloop on ${REPO}#${PR} ===" +echo +echo "--- summary / issue comments ---" +gh api "repos/${REPO}/issues/${PR}/comments" --paginate \ + --jq '.[] | select(.user.login=="preloop[bot]") | "\(.created_at)\n\(.html_url)\n\(.body)\n---"' +echo +echo "--- inline review comments ---" +gh api "repos/${REPO}/pulls/${PR}/comments" --paginate \ + --jq '.[] | select(.user.login=="preloop[bot]") | "\(.path):\(.line // .original_line)\n\(.html_url)\n\(.body)\n---"' +echo +echo "--- reviews ---" +gh api "repos/${REPO}/pulls/${PR}/reviews" --paginate \ + --jq '.[] | select(.user.login=="preloop[bot]") | "\(.submitted_at) state=\(.state)\n\(.html_url)\n\(.body)\n---"' +echo +echo "Tip: gh pr list --label preloop-triage"