From f07dc2dc49c22d6f0dec0ee8a3516ce1699a0363 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 11 Nov 2026 23:25:37 -0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20PR=20comments:=20post=20over?= =?UTF-8?q?lap/mutation=20reports=20only=20on=20a=20finding,=20thank=20fir?= =?UTF-8?q?st-time=20contributors=20only,=20no=20self-/lgtm=20relay=20on?= =?UTF-8?q?=20Prow=20PRs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #17863. - .github/scripts/pr-overlap.sh: create the comment only when a sibling PR conflicts or shares a file; a later clean run edits the existing comment to a one-line Resolved note; never post for a PR that never had a finding. The step summary keeps the full report. - src/scripts/mutation-report.sh post: same for on a pass verdict; the report is appended to the step summary first. - src/scripts/feedback-gate.sh (+ test): decides whether the merge thank-you is posted — skips bot/App authors, scanner/* and hive/* branches, hive-origin bodies and returning contributors; FEEDBACK_* env knobs. Wired by the feedback.yml change in the next commit. - pkg/github: a dashboard approval on a Prow-managed, hive-authored PR relays /approve only (LGTMSkipped); Prow rejects a self-/lgtm every time and no hive lane reads the relayed /lgtm. - docs: notifications.md (new section + Prow config location), glossary, running-at-level-6; changelog fragment. Signed-off-by: Andrew Anderson --- .github/scripts/pr-overlap.sh | 27 ++++- .github/scripts/test-pr-overlap.sh | 27 ++++- .../changed-17863-pr-comment-quartet.md | 1 + .../glossary-and-operations.md | 2 +- src/docs/notifications.md | 27 ++++- src/docs/running-at-level-6.md | 2 +- src/pkg/github/pr_decision_operator.go | 32 ++++- src/pkg/github/pr_decision_operator_test.go | 41 ++++++- src/scripts/feedback-gate.sh | 109 ++++++++++++++++++ src/scripts/mutation-report.sh | 22 ++++ src/scripts/test-feedback-gate.sh | 80 +++++++++++++ src/scripts/test-mutation-report.sh | 37 ++++++ 12 files changed, 392 insertions(+), 15 deletions(-) create mode 100644 changelog.d/changed-17863-pr-comment-quartet.md create mode 100755 src/scripts/feedback-gate.sh create mode 100755 src/scripts/test-feedback-gate.sh diff --git a/.github/scripts/pr-overlap.sh b/.github/scripts/pr-overlap.sh index f5fdaa2692..e354d26979 100755 --- a/.github/scripts/pr-overlap.sh +++ b/.github/scripts/pr-overlap.sh @@ -240,10 +240,19 @@ report_body() { } } +# One-line body the existing marker comment is edited to once a PR that had +# overlaps no longer has any. A PR that never had a finding gets no comment +# at all: the full clean report goes to the step summary only (#17863). +resolved_body() { + local base=$1 + # shellcheck disable=SC2016 # backticks are literal Markdown + printf '%s\n\n### Open PR overlap check\n\n✅ Resolved: no conflicting open PRs or same-file overlaps remain against `%s`.\n' "$MARKER" "$base" +} + upsert_comment_and_label() { - local pr=$1 body=$2 has_conflicts=$3 + local pr=$1 body=$2 has_conflicts=$3 has_any=${4:-1} base=${5:-} if ((DRY_RUN)); then - printf 'DRY RUN: would update PR #%s comment and label=%s\n' "$pr" "$has_conflicts" + printf 'DRY RUN: would update PR #%s comment and label=%s findings=%s\n' "$pr" "$has_conflicts" "$has_any" printf '%s\n' "$body" return 0 fi @@ -251,7 +260,13 @@ upsert_comment_and_label() { local comment_id comment_id=$(api "repos/${REPO}/issues/${pr}/comments?per_page=100" --paginate \ --jq ".[] | select(.body | contains(\"${MARKER}\")) | .id" | head -n1) - if [[ -n "$comment_id" ]]; then + if [[ "$has_any" != '1' ]]; then + if [[ -n "$comment_id" ]]; then + api -X PATCH "repos/${REPO}/issues/comments/${comment_id}" -f body="$(resolved_body "$base")" >/dev/null + else + printf 'PR #%s: no overlap findings and no earlier comment; not posting\n' "$pr" + fi + elif [[ -n "$comment_id" ]]; then api -X PATCH "repos/${REPO}/issues/comments/${comment_id}" -f body="$body" >/dev/null else api -X POST "repos/${REPO}/issues/${pr}/comments" -f body="$body" >/dev/null @@ -276,12 +291,12 @@ write_summary() { run_for_one_pr() { local pr=$1 base=$2 writable=$3 truncated=${4:-0} - local rows has_conflicts _has_any base_conflict body - make_report_for_pr "$pr" "$base" rows has_conflicts _has_any base_conflict + local rows has_conflicts has_any base_conflict body + make_report_for_pr "$pr" "$base" rows has_conflicts has_any base_conflict body=$(report_body "$pr" "$base" "$rows" "$truncated" "$base_conflict") write_summary "$body" if [[ "$writable" == '1' ]]; then - upsert_comment_and_label "$pr" "$body" "$has_conflicts" + upsert_comment_and_label "$pr" "$body" "$has_conflicts" "$has_any" "$base" fi } diff --git a/.github/scripts/test-pr-overlap.sh b/.github/scripts/test-pr-overlap.sh index f3581977cc..3b553a279c 100755 --- a/.github/scripts/test-pr-overlap.sh +++ b/.github/scripts/test-pr-overlap.sh @@ -109,7 +109,7 @@ case "$*" in *'.head.repo.full_name'*) printf '%s\n' "$REPO_SLUG" ;; *'.head.sha'*) printf '%s\n' "${FALLBACK_SHA:-}" ;; *'.base.ref'*) printf 'v6\n' ;; - *'/comments?'*) : ;; + *'/comments?'*) if [[ -n "${EXISTING_COMMENT_ID:-}" ]]; then printf '%s\n' "$EXISTING_COMMENT_ID"; fi ;; *) echo "unexpected gh api call: $*" >&2; exit 2 ;; esac GH @@ -134,6 +134,8 @@ run_pr() { # pr -> sets OUT and WRITES LABEL_ADD="-X POST repos/${REPO_SLUG}/issues/%s/labels -f labels[]=conflicts-with-open-pr" LABEL_DEL="-X DELETE repos/${REPO_SLUG}/issues/%s/labels/conflicts-with-open-pr" +COMMENT_POST="-X POST repos/${REPO_SLUG}/issues/%s/comments -f body=" +COMMENT_PATCH="-X PATCH repos/${REPO_SLUG}/issues/comments/%s -f body=" echo 'PR 2: real sibling conflict with PR 3, stale PR 1 is not blamed' run_pr 2 @@ -144,6 +146,16 @@ assert_not_contains "$OUT" '| #1 |' 'does not blame PR 1 for its conflict with t assert_not_contains "$OUT" '| #4 |' 'does not link the unrelated stale PR 4' # shellcheck disable=SC2059 assert_contains "$WRITES" "$(printf -- "$LABEL_ADD" 2)" 'labels PR 2 conflicts-with-open-pr' +# shellcheck disable=SC2059 +assert_contains "$WRITES" "$(printf -- "$COMMENT_POST" 2)" 'posts the overlap comment when there is a finding' + +echo 'PR 2: an existing marker comment is edited, not duplicated' +EXISTING_COMMENT_ID=4242 run_pr 2 +assert_exit0 +# shellcheck disable=SC2059 +assert_contains "$WRITES" "$(printf -- "$COMMENT_PATCH" 4242)" 'edits the existing marker comment' +# shellcheck disable=SC2059 +assert_not_contains "$WRITES" "$(printf -- "$COMMENT_POST" 2)" 'does not post a second comment' echo 'PR 5: add/add of the same new path with different content' run_pr 5 @@ -167,9 +179,20 @@ assert_contains "$WRITES" "$(printf -- "$LABEL_DEL" 1)" 'removes the sibling-con echo 'PR 4: stale but clean, no overlap' run_pr 4 assert_exit0 -assert_contains "$OUT" 'No conflicting open PRs or same-file overlaps were found.' 'reports no overlap' +assert_contains "$OUT" 'No conflicting open PRs or same-file overlaps were found.' 'reports no overlap in the summary' # shellcheck disable=SC2059 assert_contains "$WRITES" "$(printf -- "$LABEL_DEL" 4)" 'removes the sibling-conflict label' +assert_not_contains "$WRITES" '/comments' 'posts no comment when there is nothing to report (#17863)' +assert_contains "$OUT" 'no overlap findings and no earlier comment; not posting' 'logs the skipped post' + +echo 'PR 4: a clean run edits an earlier finding comment to a one-line resolved note' +EXISTING_COMMENT_ID=777 run_pr 4 +assert_exit0 +# shellcheck disable=SC2059 +assert_contains "$WRITES" "$(printf -- "$COMMENT_PATCH" 777)" 'edits the existing comment, keeping the marker' +assert_contains "$WRITES" 'Resolved: no conflicting open PRs or same-file overlaps remain against `v6`' 'collapses to the resolved line' +# shellcheck disable=SC2059 +assert_not_contains "$WRITES" "$(printf -- "$COMMENT_POST" 4)" 'does not post a new comment' echo 'PR 3: missing pull ref falls back to the API head and replaces a stale local ref' export FALLBACK_SHA diff --git a/changelog.d/changed-17863-pr-comment-quartet.md b/changelog.d/changed-17863-pr-comment-quartet.md new file mode 100644 index 0000000000..eb5412ae90 --- /dev/null +++ b/changelog.d/changed-17863-pr-comment-quartet.md @@ -0,0 +1 @@ +- PR comment noise: the three per-PR workflow comments that survived the hive-App reducers now post only on a finding ([#17863](https://github.com/hivecommons/hive/issues/17863)). `.github/scripts/pr-overlap.sh` creates its `` comment only when a sibling PR conflicts or shares a file and, when a later push clears that, edits the existing comment to a one-line "Resolved" note instead of re-posting "no overlaps found" on every PR; `src/scripts/mutation-report.sh post` does the same for `` on a `pass` verdict (the full report, clean case included, still goes to the step summary); the "Thank you for your contribution!" merge comment (`feedback.yml`) is gated by the new `src/scripts/feedback-gate.sh` to a person's first merged PR — bot/App authors, `scanner/*` and `hive/*` branches, hive-origin bodies and returning contributors are skipped, with `FEEDBACK_*` workflow `env` knobs. A dashboard approval on a Prow-managed PR the hive account opened now relays `/approve` only, since a self-`/lgtm` is rebuked by Prow every time (`PullRequestApprovalEvent.LGTMSkipped`). Expected effect: roughly half of the comments on a typical merged PR. diff --git a/src/docs/labels-and-control-signals/glossary-and-operations.md b/src/docs/labels-and-control-signals/glossary-and-operations.md index 5c1d52e9ae..64a5606d00 100644 --- a/src/docs/labels-and-control-signals/glossary-and-operations.md +++ b/src/docs/labels-and-control-signals/glossary-and-operations.md @@ -225,7 +225,7 @@ The dashboard renders every open issue and PR's stage as one unified tracker str ## Non-label equivalents - **Human comments and assignees** can acknowledge hive-filed directions for #5117; assignees also affect ranking. -- **Hidden comment markers** carry state that no label does. `` records an issue claim, `` dedupes a published finding, `` marks an overlap notice, `` starts the question auto-close clock, and `` is stamped on the single comment a fix lane leaves on a PR it defers to shared incident `#` (`DEFER_TO_INCIDENT` from `bin/hive-baseline-check.sh`), so "every PR incident `#` broke" stays greppable after the fix lands ([#10441](https://github.com/hivecommons/hive/issues/10441)). One marker per PR per incident; it is never edited or removed while the incident is open. While incident `#` is open, the governor records it as `deferred_incident` on the PR's `ci-failing.json` row and the kick builders keep that PR out of every CI-FAILING / FIX-BEFORE-NEW repair list, naming it only as deferred; once the incident closes the PR is listed for repair again ([#10528](https://github.com/hivecommons/hive/issues/10528)). When the incident closes (not as "not planned"), the shared-CI rerun sweep re-runs the failed jobs of each still-open PR carrying that marker — the newest failed, timed-out or cancelled run per workflow on the PR head — using the hive's own credential, then stamps `` and `` on the PR so it is re-run at most once per incident; disable with `shared_ci_rerun.enabled: false` ([#12253](https://github.com/hivecommons/hive/issues/12253)). +- **Hidden comment markers** carry state that no label does. `` records an issue claim, `` dedupes a published finding, `` marks the one overlap notice a PR gets (posted only when a sibling PR conflicts or shares a file, edited down to a "Resolved" line when that clears; [#17863](https://github.com/hivecommons/hive/issues/17863)), `` starts the question auto-close clock, and `` is stamped on the single comment a fix lane leaves on a PR it defers to shared incident `#` (`DEFER_TO_INCIDENT` from `bin/hive-baseline-check.sh`), so "every PR incident `#` broke" stays greppable after the fix lands ([#10441](https://github.com/hivecommons/hive/issues/10441)). One marker per PR per incident; it is never edited or removed while the incident is open. While incident `#` is open, the governor records it as `deferred_incident` on the PR's `ci-failing.json` row and the kick builders keep that PR out of every CI-FAILING / FIX-BEFORE-NEW repair list, naming it only as deferred; once the incident closes the PR is listed for repair again ([#10528](https://github.com/hivecommons/hive/issues/10528)). When the incident closes (not as "not planned"), the shared-CI rerun sweep re-runs the failed jobs of each still-open PR carrying that marker — the newest failed, timed-out or cancelled run per workflow on the PR head — using the hive's own credential, then stamps `` and `` on the PR so it is re-run at most once per incident; disable with `shared_ci_rerun.enabled: false` ([#12253](https://github.com/hivecommons/hive/issues/12253)). - **Paused repos** (`project.paused_repos`) stop whole-repo write/merge/enumeration paths without labels. - **Contributor queue holds** such as active leases, cooldowns, dependencies, and quota guard holds suppress contributor offers without touching GitHub labels. - **Jira/Linear labels** map only where the work-source adapter supports them: Linear skips held work using substring hold labels; Jira skips exact configured hold labels; GitHub Projects currently imports labels but does not use a hold gate. diff --git a/src/docs/notifications.md b/src/docs/notifications.md index d036a5c274..38427784fc 100644 --- a/src/docs/notifications.md +++ b/src/docs/notifications.md @@ -703,7 +703,32 @@ and exits non-zero instead of posting a possible duplicate. `.github/scripts/test-hive-status-card.sh` and `src/scripts/test-comment-merged-refs.sh` pin this behaviour. +### Per-PR workflow comments post only on a finding + +Three workflow comments used to land on every PR regardless of outcome, and +after the runtime's own reducers they were ~70% of the comments on a merged +PR ([#17863](https://github.com/hivecommons/hive/issues/17863)). Each now +posts only when it has something to say; the full report, including the +clean case, still goes to the job's step summary: + +| Workflow / script | Comment | Behaviour | +| --- | --- | --- | +| Open PR Overlap (`.github/workflows/pr-overlap.yml`, `.github/scripts/pr-overlap.sh`) | `` table of conflicting / same-file open PRs | **Posts** only when at least one sibling PR conflicts or shares a file; **edits** the one marker comment in place on later pushes; when a later run finds nothing and a comment exists, **edits it** to a one-line "✅ Resolved" note; a PR that never had an overlap gets no comment. The `conflicts-with-open-pr` label is unchanged. | +| Mutation (advisory) (`.github/workflows/mutation-advisory.yml`, `src/scripts/mutation-report.sh post`) | `` surviving / uncovered mutant report | **Posts** only for a non-`pass` verdict (`lived`, `uncovered`, `misrouted`, `error`); **edits** the one marker comment on later pushes; a later `pass` **edits** the existing comment to a one-line "✅ Resolved" note; a PR whose every run passes gets no comment. | +| Feedback Wanted (`.github/workflows/feedback.yml` → `hivecommons/infra` `reusable-feedback.yml`, gated by `src/scripts/feedback-gate.sh`) | "Thank you for your contribution! Your PR has been merged." | **Posts** only for a person's first merged PR in the repo. Skipped for `[bot]` / App authors, hive-managed head branches (`scanner/*`, `hive/*`), PR bodies carrying a `` comment appears only when there is a conflict or same-file overlap). | Resolve or close conflicting work before merging; same-file overlap alone may be harmless. Two open PRs that both `Fixes` one issue are resolved by the duplicate-fix sweep without a decision: the earlier green/pending PR stays, the later hive PR is closed as `duplicate-of:`, a person's later PR is commented on and left open ([#14799](https://github.com/hivecommons/hive/issues/14799)). | | `has-open-pr` | Pre-dispatch guard | An open PR already links the issue with a closing keyword; the hive skipped the claim. | Nothing — the label is a tracker signal, not a park; see `scanner.skip_issues_with_open_pr` in [operator-reference.md](operator-reference.md#open-pr-dispatch-guard-and-duplicate-fix-sweep-scanner). | | `no-changelog` | Dependabot/maintainer | Repo changelog exception, not a Hive safety gate. | Apply only under repo policy. | | `human-only` remainder text (not a default label) | Agent/reviewer | Task-list sweep can park remaining issue work as `needs-human`. | Treat as a handoff; add PR `hold` if merging must stop. | diff --git a/src/pkg/github/pr_decision_operator.go b/src/pkg/github/pr_decision_operator.go index 6ca3c432df..8f0e30e6e2 100644 --- a/src/pkg/github/pr_decision_operator.go +++ b/src/pkg/github/pr_decision_operator.go @@ -94,6 +94,13 @@ type PullRequestApprovalEvent struct { // reply stays on the PR, so the next Approve takes the CommandsSkipped // path (hivecommons/hive#17475). ProwRejected bool + // LGTMSkipped is true when only `/approve` was relayed: the PR is + // Prow-managed and was opened by the hive's own account, so a `/lgtm` + // posted from that account is the PR author's and Prow's lgtm plugin + // answers every one with "you cannot LGTM your own PR" + // (hivecommons/hive#17863). No hive lane reads the relayed `/lgtm`; + // the `/approve` comment carries the attribution they use. + LGTMSkipped bool // ReportingError preserves partial progress: the native approval stands, // but comments, labels or stage reporting must be retried/reconciled. ReportingError string @@ -503,19 +510,40 @@ func (c *Client) reportOperatorPullRequestApproval(ctx context.Context, owner, n c.logger.Info("pull request approval commands not posted: Prow rejected the hive's earlier commands on this PR (bot is not an approver); the hive's own approval record stands", "repo", event.Repo, "pr", number, "actor", actor, "head", head) } } else { - for _, command := range PRApprovalCommands { + commands := PRApprovalCommands + if event.ProwManaged && selfAuthored { + commands = prApprovalCommandsWithoutLGTM(commands) + event.LGTMSkipped = true + } + // Each relayed command carries the prApprovalCommentMarkerPrefix + // marker bound to head, which is what prowRejectedHiveCommands and + // the sentinel/workflow-approval readers key on; once posted for a + // head it is not posted again (CommandsSkipped above). + for _, command := range commands { if err := c.CreateIssueComment(ctx, full, number, renderPRApprovalCommandComment(command, actor, head)); err != nil { return fmt.Errorf("posting %s on %s/%s#%d: %w", command, owner, name, number, err) } } if c.logger != nil { - c.logger.Info("pull request approval commands posted by dashboard decision", "repo", event.Repo, "pr", number, "actor", actor, "head", head) + c.logger.Info("pull request approval commands posted by dashboard decision", "repo", event.Repo, "pr", number, "actor", actor, "head", head, "lgtm_skipped_self_authored", event.LGTMSkipped) } event.ProwRejected = c.awaitProwRejection(ctx, owner, name, number, event.ProwManaged) } return ctx.Err() } +// prApprovalCommandsWithoutLGTM returns commands minus `/lgtm`, for a +// Prow-managed PR the posting account itself authored (#17863). +func prApprovalCommandsWithoutLGTM(commands []string) []string { + out := make([]string, 0, len(commands)) + for _, command := range commands { + if command != "/lgtm" { + out = append(out, command) + } + } + return out +} + // ProwManagedLabels reports whether labels carry Prow's plugin markers: // the approve plugin's `approved`, size's `size/*`, the `do-not-merge/*` // family and trigger's `ok-to-test` / `needs-ok-to-test`. diff --git a/src/pkg/github/pr_decision_operator_test.go b/src/pkg/github/pr_decision_operator_test.go index c6a5746ad2..96afbdc68a 100644 --- a/src/pkg/github/pr_decision_operator_test.go +++ b/src/pkg/github/pr_decision_operator_test.go @@ -390,6 +390,42 @@ func TestRecordOperatorPullRequestApprovalSkipsCommandsProwRejected(t *testing.T } } +// On a Prow-managed PR the hive account opened, a `/lgtm` from that account +// is a self-LGTM Prow always rebukes; only `/approve` is relayed +// (hivecommons/hive#17863). A person's PR and a non-Prow repo keep both. +func TestRecordOperatorPullRequestApprovalSkipsSelfLGTMOnProwPR(t *testing.T) { + for _, tc := range []struct { + name string + pr unparkWireIssue + wantLGTM bool + wantSkipped bool + }{ + {"hive-authored prow-managed", parkedPR(liveDecisionPR, "hive[bot]", []string{PRNeedsDecisionStageLabel, "author/hive", "size/M"}), false, true}, + {"hive-authored not prow-managed", hiveParkedPR(), true, false}, + {"person-authored prow-managed", parkedPR(liveDecisionPR, "contributor", []string{PRNeedsDecisionStageLabel, "author/human", "size/M"}), true, false}, + } { + t.Run(tc.name, func(t *testing.T) { + c, rec := newUnparkPRClient(t, []unparkWireIssue{tc.pr}, map[string]string{"maintainer": "write"}) + event, err := c.RecordOperatorPullRequestApproval(context.Background(), "org/repo", liveDecisionPR, "maintainer") + if err != nil { + t.Fatalf("approval: %v", err) + } + if event.LGTMSkipped != tc.wantSkipped { + t.Fatalf("event = %+v, want LGTMSkipped=%v", event, tc.wantSkipped) + } + posted := rec.posted[liveDecisionPR] + var gotLGTM, gotApprove bool + for _, body := range posted { + gotLGTM = gotLGTM || strings.HasPrefix(body, "/lgtm\n") + gotApprove = gotApprove || strings.HasPrefix(body, "/approve\n") + } + if gotLGTM != tc.wantLGTM || !gotApprove { + t.Fatalf("posted %v, want lgtm=%v and /approve", posted, tc.wantLGTM) + } + }) + } +} + // On a Prow repo where rejection has not been observed yet, Prow answers the // relayed commands after they are posted. The approval event reports that // reply instead of leaving the board at "approved" (hivecommons/hive#17475). @@ -418,8 +454,9 @@ func TestRecordOperatorPullRequestApprovalReportsProwRejectionAfterPost(t *testi if err != nil { t.Fatalf("approval: %v", err) } - if event.ProwRejected != tc.want || event.CommandsSkipped != "" || len(rec.posted[liveDecisionPR]) != len(PRApprovalCommands) { - t.Fatalf("event = %+v, want ProwRejected %v with commands posted", event, tc.want) + // Hive-authored and Prow-managed: only `/approve` is relayed (#17863). + if event.ProwRejected != tc.want || event.CommandsSkipped != "" || !event.LGTMSkipped || len(rec.posted[liveDecisionPR]) != len(PRApprovalCommands)-1 { + t.Fatalf("event = %+v, want ProwRejected %v with /approve posted", event, tc.want) } }) } diff --git a/src/scripts/feedback-gate.sh b/src/scripts/feedback-gate.sh new file mode 100755 index 0000000000..50c1c0e314 --- /dev/null +++ b/src/scripts/feedback-gate.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# feedback-gate.sh — decides whether the post-merge "Thank you for your +# contribution!" comment (.github/workflows/feedback.yml → +# hivecommons/infra reusable-feedback.yml) should be posted on a merged PR. +# +# The reusable workflow is unconditional, so before #17863 every merged PR +# got the comment: 38 of 40 in the 2026-11-11 spam sample were on hive-App or +# maintainer PRs that nobody reads it on. The comment is for people merging +# their first change, so the gate keeps it for exactly that case. +# +# Reads the pull_request event from $GITHUB_EVENT_PATH (or the FEEDBACK_PR_* +# overrides below, used by the self-test) and writes `post=true|false` and +# `reason=` to $GITHUB_OUTPUT (stdout when unset). Exit status is 0 in +# both cases; only a broken event or API read exits non-zero, which the caller +# treats as "do not post". +# +# Configuration (workflow `env:`), each with its default: +# FEEDBACK_SKIP_BOTS=1 skip `[bot]` / type=Bot authors +# FEEDBACK_SKIP_BRANCHES='scanner/* hive/*' +# space-separated globs of hive-managed +# head branches to skip +# FEEDBACK_SKIP_HIVE_ORIGIN=1 skip PRs whose body carries a `' +run true 'fix-* branch by a person is still thanked' FEEDBACK_PR_HEAD_REF=fix-typo GH_TOTAL=1 +run false 'unmerged (closed) PR is never thanked' FEEDBACK_PR_MERGED=false +run error 'merged-PR lookup failure exits non-zero without an output' GH_FAIL=1 +run error 'garbage merged count exits non-zero' GH_TOTAL=lots + +echo "configuration" +run true 'FEEDBACK_SKIP_BOTS=0 thanks a bot' FEEDBACK_SKIP_BOTS=0 FEEDBACK_PR_AUTHOR='x[bot]' FEEDBACK_PR_AUTHOR_TYPE=Bot GH_TOTAL=1 +run true 'FEEDBACK_FIRST_TIME_ONLY=0 thanks a returning contributor' FEEDBACK_FIRST_TIME_ONLY=0 GH_TOTAL=9 +run false 'FEEDBACK_SKIP_BRANCHES adds a pattern' FEEDBACK_SKIP_BRANCHES='scanner/* release/*' FEEDBACK_PR_HEAD_REF=release/v5.1 +run true 'FEEDBACK_SKIP_BRANCHES= disables branch skipping' FEEDBACK_SKIP_BRANCHES= FEEDBACK_PR_HEAD_REF=scanner/x GH_TOTAL=1 +run false 'FEEDBACK_SKIP_LOGINS is case-insensitive' FEEDBACK_SKIP_LOGINS='Maintainer other' FEEDBACK_PR_AUTHOR=maintainer +run true 'FEEDBACK_MERGED_COUNT override skips the API' FEEDBACK_MERGED_COUNT=1 GH_FAIL=1 + +echo "event file" +cat > "$TMP/event.json" <<'EOF' +{"pull_request":{"number":17716,"merged":true,"user":{"login":"clubanderson","type":"User"},"head":{"ref":"fix/thing"},"body":"body"}} +EOF +out="$TMP/output"; : > "$out" +result=$(env -i PATH="$TMP/bin:/usr/bin:/bin" HOME="$TMP" GITHUB_OUTPUT="$out" GITHUB_REPOSITORY=example/hive \ + GITHUB_EVENT_PATH="$TMP/event.json" GH_TOTAL=400 bash "$SCRIPT" 2>&1); rc=$? +[ "$rc" -eq 0 ] && grep -qx 'post=false' "$out" && grep -q 'returning-contributor:clubanderson:400-merged' "$out" \ + && pass "fields are read from GITHUB_EVENT_PATH" || bad "event file: rc=$rc out=$(cat "$out") $result" + +if [ "$fail" -ne 0 ]; then + echo "test-feedback-gate.sh: FAILED" + exit 1 +fi +echo "test-feedback-gate.sh: all checks passed" diff --git a/src/scripts/test-mutation-report.sh b/src/scripts/test-mutation-report.sh index 3da43953bb..f41b6a9bdf 100755 --- a/src/scripts/test-mutation-report.sh +++ b/src/scripts/test-mutation-report.sh @@ -200,6 +200,43 @@ output=$(MUTATION_OUT_DIR="$TMP/missing" bash "$SCRIPT" verdict 2>&1); rc=$? [ "$rc" -eq 1 ] && out_grep -q '::error::mutation: no verdict at' \ && pass "missing verdict file fails the verdict phase" || bad "missing verdict rc=$rc: $output" +echo "post phase (#17863)" +# Stub gh: lists $GH_EXISTING_ID (if set) as the bot's marker comment and logs writes. +cat > "$TMP/bin/gh" <<'GHSTUB' +#!/usr/bin/env bash +case "$*" in + *-X*) printf '%s\n' "$*" >> "$GH_WRITE_LOG"; exit 0 ;; + *'/comments'*) if [ -n "${GH_EXISTING_ID:-}" ]; then printf '%s\n' "$GH_EXISTING_ID"; fi; exit 0 ;; + *) echo "unexpected gh call: $*" >&2; exit 2 ;; +esac +GHSTUB +chmod +x "$TMP/bin/gh" +run_post() { # run_post [existing-id] + GH_WRITE_LOG="$TMP/gh-writes.log"; : > "$GH_WRITE_LOG" + SUMMARY="$TMP/summary.md"; : > "$SUMMARY" + output=$(cd "$repo" && GH_WRITE_LOG="$GH_WRITE_LOG" GH_EXISTING_ID="${2:-}" GITHUB_STEP_SUMMARY="$SUMMARY" \ + MUTATION_OUT_DIR="$1" PR_NUMBER=42 GITHUB_REPOSITORY=example/hive bash "$SCRIPT" post 2>&1) + writes=$(cat "$GH_WRITE_LOG") +} +mkdir -p "$TMP/out-pass" "$TMP/out-lived" +printf '\n### Mutation testing\n\nAll 3 mutant(s) in changed files were killed.\n' > "$TMP/out-pass/comment.md" +echo pass > "$TMP/out-pass/verdict" +printf '\n### Mutation testing\n\ngremlins found **1 surviving mutant(s)**\n' > "$TMP/out-lived/comment.md" +echo lived > "$TMP/out-lived/verdict" +run_post "$TMP/out-pass" +[ -z "$writes" ] && pass "pass verdict with no earlier comment posts nothing" || bad "pass posted: $writes" +out_grep -q 'verdict pass and no earlier comment; not posting' && pass "skip is logged" || bad "skip not logged: $output" +grep -q 'All 3 mutant(s) in changed files were killed' "$SUMMARY" && pass "clean report still lands in the step summary" || bad "summary missing report" +run_post "$TMP/out-lived" +grep -q "^api -X POST repos/example/hive/issues/42/comments" <<<"$writes" && pass "lived verdict posts a new comment" || bad "lived did not post: $writes" +run_post "$TMP/out-lived" 99 +grep -q "^api -X PATCH repos/example/hive/issues/comments/99" <<<"$writes" && pass "lived verdict edits the existing comment" || bad "lived did not edit: $writes" +grep -q 'POST' <<<"$writes" && bad "lived posted a duplicate" || pass "no duplicate comment" +run_post "$TMP/out-pass" 99 +grep -q "^api -X PATCH repos/example/hive/issues/comments/99 -f body=" <<<"$writes" && pass "pass after a finding edits the existing comment, keeping the marker" || bad "pass did not edit: $writes" +grep -q 'Resolved: no surviving or uncovered mutants' <<<"$writes" && pass "edited body is the one-line resolved note" || bad "resolved note missing: $writes" +grep -q 'All 3 mutant' <<<"$writes" && bad "full report was written to the comment" || pass "full report stays out of the comment" + if [ "$fail" -ne 0 ]; then echo "test-mutation-report.sh: FAILED" exit 1 From dec8b3b3d3bcdc30d776bbac0b6399d43931f2ef Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 11 Nov 2026 23:25:40 -0700 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20workflows:=20gate=20the=20Fe?= =?UTF-8?q?edback=20Wanted=20thank-you=20on=20src/scripts/feedback-gate.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #17863. Workflow-only commit: adds a gate job (self-test + decision) before the hivecommons/infra reusable-feedback call, which runs only when the gate outputs post=true. Signed-off-by: Andrew Anderson --- .github/workflows/feedback.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/feedback.yml b/.github/workflows/feedback.yml index 0d4f5de803..14872a8e7d 100644 --- a/.github/workflows/feedback.yml +++ b/.github/workflows/feedback.yml @@ -14,5 +14,35 @@ permissions: pull-requests: write jobs: + # The reusable workflow thanks every merged PR unconditionally; the gate + # keeps the comment for a person's first merged PR only (#17863). Rules and + # knobs: src/scripts/feedback-gate.sh. + gate: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + pull-requests: read + outputs: + post: ${{ steps.gate.outputs.post }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Self-test feedback gate + run: bash src/scripts/test-feedback-gate.sh + - id: gate + name: Decide whether to thank the author + env: + GH_TOKEN: ${{ github.token }} + FEEDBACK_SKIP_BOTS: '1' + FEEDBACK_SKIP_BRANCHES: 'scanner/* hive/*' + FEEDBACK_SKIP_HIVE_ORIGIN: '1' + FEEDBACK_FIRST_TIME_ONLY: '1' + run: bash src/scripts/feedback-gate.sh + feedback: + needs: gate + if: needs.gate.outputs.post == 'true' uses: hivecommons/infra/.github/workflows/reusable-feedback.yml@f1c0b61675386f54e63c04cf07b3aa933cc963eb # hivecommons/infra main as of 2026-09-02 From abe9e95a662c3eefcd022b290581b120fb59778b Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 12 Nov 2026 01:36:01 -0700 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8C=B1=20governance:=20re-pin=20TRUST?= =?UTF-8?q?ED=5FSCRIPTS=5FTREE=20for=20the=20feedback-gate=20and=20mutatio?= =?UTF-8?q?n-report=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #17863. src/scripts gained feedback-gate.sh / test-feedback-gate.sh and mutation-report.sh changed, so the pinned tree moves to 1f1eb9048. Signed-off-by: Andrew Anderson --- .github/scripts/integration-governance.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index a1cb7d505b..87ad4e2ce7 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -9,7 +9,7 @@ const MAX_COMMITS = 1000; const MAX_AUTHOR_BATCH = 50; // This literal is inside the enrolled .github closure. A caller-supplied // preparedBy.sourceSHA must never choose a new executable verifier tree. -const TRUSTED_SCRIPTS_TREE = '718b8f2888041981d0779cfd19d90484ac01b8a9'; +const TRUSTED_SCRIPTS_TREE = '1f1eb904839561af15c1772e6d9106a3b8d2b028'; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) =>