diff --git a/changelog.d/fixed-html-entity-issue-refs.md b/changelog.d/fixed-html-entity-issue-refs.md new file mode 100644 index 0000000000..db44ff74a2 --- /dev/null +++ b/changelog.d/fixed-html-entity-issue-refs.md @@ -0,0 +1 @@ +- The closing-keyword and reference parsers no longer read the `#8203` inside Renovate's `​` (zero-width space) as an issue reference. On projectbluefin/gutenprint-printer-app#169, "fixed and prefixed label handlers by [@​…" became a claim on #8203, and the review filed projectbluefin/gutenprint-printer-app#170 about the artifact. The review backlog also no longer files an info-severity finding that says "no action needed": it opens an item with nothing to do. diff --git a/src/docs/review-swarm.md b/src/docs/review-swarm.md index b9f9e3a12c..992a6ebd32 100644 --- a/src/docs/review-swarm.md +++ b/src/docs/review-swarm.md @@ -108,7 +108,7 @@ The default human threshold is `high`. Review-triggered fix cycles use the same ### Out-of-scope backlog filing -When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals/reference.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue is titled `[reviewer] Review backlog (): ` — like every issue the hive files, the title starts with the filing agent in square brackets (`issueshape.AgentIssueTitle`, the one function every hive issue-creation path runs its title through — `CreateIssue`, the raw advisory/recommendations/upstream-watch creates and the egress proxy — so no filer can forget it; it puts the tag first, never doubles it, and title dedupe ignores it so items filed before the tag still match). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again. When an open issue cites a path this finding also cites but is a different finding, the new item gets a "Same file as #N" cross-link naming the path the two share (not necessarily the finding's own evidence file). +When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals/reference.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue is titled `[reviewer] Review backlog (): ` — like every issue the hive files, the title starts with the filing agent in square brackets (`issueshape.AgentIssueTitle`, the one function every hive issue-creation path runs its title through — `CreateIssue`, the raw advisory/recommendations/upstream-watch creates and the egress proxy — so no filer can forget it; it puts the tag first, never doubles it, and title dedupe ignores it so items filed before the tag still match). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again. When an open issue cites a path this finding also cites but is a different finding, the new item gets a "Same file as #N" cross-link naming the path the two share (not necessarily the finding's own evidence file). An `info` finding that says in its own words that no action is needed ("No action needed", "no further action is required") is not filed: it would open an item with nothing to do. The PR receives one summary comment listing the backlog issues filed from that review. Filing is enabled by default and bounded by `review.max_out_of_scope_backlog_issues` (default `3`) per PR; set `review.out_of_scope_backlog_disabled: true` to opt out. diff --git a/src/pkg/github/prclaims.go b/src/pkg/github/prclaims.go index 7cefdde5fe..559d68fd1d 100644 --- a/src/pkg/github/prclaims.go +++ b/src/pkg/github/prclaims.go @@ -544,9 +544,16 @@ var ( fencedCodeBlockPattern = regexp.MustCompile("(?s)```.*?```") inlineCodeSpanPattern = regexp.MustCompile("`[^`\n]*`") closingURLPattern = regexp.MustCompile(`https?://[^\s)]+`) + // htmlNumericEntityPattern is a decimal character reference; a hex one + // (`​`) never reads as `#N`. Renovate writes `[#​628]` and + // `@​user` so GitHub links nothing; the `#8203` inside the entity + // is not an issue reference (projectbluefin/gutenprint-printer-app#170 + // was filed against "#8203"). + htmlNumericEntityPattern = regexp.MustCompile(`&#[0-9]+;`) ) func stripClosingFalsePositiveText(text string) string { + text = htmlNumericEntityPattern.ReplaceAllString(text, " ") text = fencedCodeBlockPattern.ReplaceAllString(text, " ") text = inlineCodeSpanPattern.ReplaceAllString(text, " ") text = closingURLPattern.ReplaceAllString(text, " ") @@ -672,7 +679,7 @@ var issueRefPattern = regexp.MustCompile(`(?:([\w.-]+/[\w.-]+))?#(\d+)`) // It is the weak-evidence companion to ParseClaimedIssues: claimsFromPR reads // both and keeps the closing claim wherever the two name the same issue. func ParseReferencedIssues(text, defaultRepo string) []ClaimedRef { - return parseRefs(referenceRefPattern, text, defaultRepo) + return parseRefs(referenceRefPattern, htmlNumericEntityPattern.ReplaceAllString(text, " "), defaultRepo) } // branchIssuePattern matches the branch-naming conventions agents use to encode diff --git a/src/pkg/github/prclaims_html_entity_test.go b/src/pkg/github/prclaims_html_entity_test.go new file mode 100644 index 0000000000..de8cf991b3 --- /dev/null +++ b/src/pkg/github/prclaims_html_entity_test.go @@ -0,0 +1,97 @@ +package github + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/outputschema" +) + +// projectbluefin/gutenprint-printer-app#170: Renovate writes `@​user` +// and `[#​628]` so GitHub links nothing, and the closing parser read +// "fixed and prefixed label handlers by [@​" as a claim on #8203. The +// review then filed a backlog issue about the artifact that said itself "No +// action needed on the PR". +func TestClaimParsersSkipHTMLNumericEntities(t *testing.T) { + renovate := "- feat(plugins): remove, hold, lgtm, fixed and prefixed label handlers by [@​hivecommons-hive](https://redirect.github.com/hivecommons-hive) in [#​628](https://redirect.github.com/cncf/prow-github-actions/pull/628)\n" + + "- fix the documented values by [@​jeefy](https://redirect.github.com/jeefy)\n" + if got := ParseClaimedIssues(renovate, "o/r"); len(got) != 0 { + t.Fatalf("claimed = %v, want none from entities", got) + } + if _, ok := FindClosingKeywordReference(renovate, "o/r", "o/r", 8203); ok { + t.Fatal("FindClosingKeywordReference matched #8203 inside ​") + } + if got := ParseReferencedIssues("Refs ​12 and see ​", "o/r"); len(got) != 0 { + t.Fatalf("referenced = %v, want none from entities", got) + } + // Real references next to entities still count. + got := ParseClaimedIssues(renovate+"\nFixes #12", "o/r") + if len(got) != 1 || got[0].Issue != 12 { + t.Fatalf("claimed = %v, want only #12", got) + } + if refs := ParseReferencedIssues("Refs #7 (by [@​jeefy])", "o/r"); len(refs) != 1 || refs[0].Issue != 7 { + t.Fatalf("referenced = %v, want only #7", refs) + } +} + +func TestFindingNeedsNoAction(t *testing.T) { + for _, tc := range []struct { + name string + f outputschema.Finding + want bool + }{ + {name: "gutenprint#170", f: outputschema.Finding{Severity: outputschema.SeverityInfo, Title: "Linked issue #8203 is a parsing artifact, not a real issue", Summary: "The diff does exactly that. No action needed on the PR."}, want: true}, + {name: "no action required", f: outputschema.Finding{Severity: outputschema.SeverityInfo, Summary: "No further action is required."}, want: true}, + {name: "low severity says no action: still filed", f: outputschema.Finding{Severity: outputschema.SeverityLow, Summary: "No action needed on the PR, but the base is wrong."}, want: false}, + {name: "info with work in it", f: outputschema.Finding{Severity: outputschema.SeverityInfo, Summary: "The retry loop gives up on the first 502; retry it."}, want: false}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := findingNeedsNoAction(tc.f); got != tc.want { + t.Fatalf("findingNeedsNoAction = %v, want %v", got, tc.want) + } + }) + } +} + +// The backlog filer skips an info finding that says no action is needed and +// still files the others in the same report. +func TestReviewBacklogSkipsNoActionFinding(t *testing.T) { + withReviewBacklogState(t) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/repos/o/r/issues/5/comments": + fmt.Fprint(w, `{"id":1}`) + case "/repos/o/r/pulls/5": + fmt.Fprint(w, `{"base":{"ref":"v6"}}`) + case "/repos/o/r/contents/pkg/a.go": + fmt.Fprint(w, `{"type":"file","path":"pkg/a.go"}`) + case "/repos/o/r/pulls/5/files": + fmt.Fprint(w, `[{"filename":"other.go"}]`) + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer srv.Close() + sink := &fakeBacklogSink{dest: config.ReviewBacklogLinear} + c := headsBacklogClient(t, srv.URL, sink) + report := routingReport(t, 5, "abc", + nit("Linked issue #8203 is a parsing artifact", "info", "pkg/a.go", 7, "The diff does what the title says. No action needed on the PR."), + nit("retry gives up early", "info", "pkg/a.go", 9, "The retry loop gives up on the first 502; retry it.")) + if err := c.fileOutOfScopeReviewBacklog(context.Background(), ReviewRequest{Repo: "o/r", Number: 5, Agent: "reviewer", Report: report}, time.Now()); err != nil { + t.Fatal(err) + } + if len(sink.created) != 1 || !strings.Contains(sink.created[0].Title, "retry gives up early") { + titles := []string{} + for _, it := range sink.created { + titles = append(titles, it.Title) + } + t.Fatalf("created = %v, want only the finding with work in it", titles) + } +} diff --git a/src/pkg/github/review_backlog.go b/src/pkg/github/review_backlog.go index d57356ebd0..dc4d7feae5 100644 --- a/src/pkg/github/review_backlog.go +++ b/src/pkg/github/review_backlog.go @@ -10,6 +10,7 @@ import ( "log/slog" "os" "path/filepath" + "regexp" "sort" "strconv" "strings" @@ -268,7 +269,7 @@ func (c *Client) fileReviewBacklog(ctx context.Context, req ReviewRequest, now t var updated, capped int for _, report := range reports { for _, finding := range report.Findings { - if !findingHasEvidence(finding) { + if !findingHasEvidence(finding) || findingNeedsNoAction(finding) { continue } outOfScope := !review.InScopeFinding(finding) @@ -577,6 +578,19 @@ func findingHasEvidence(f outputschema.Finding) bool { return strings.TrimSpace(f.File) != "" && f.Line > 0 } +// noActionRE is a finding saying, in its own words, that nothing is to be +// done ("No action needed on the PR"). +var noActionRE = regexp.MustCompile(`(?i)\bno (?:further )?action (?:is )?(?:needed|required)\b`) + +// findingNeedsNoAction reports an info-severity finding that says nothing is +// to be done. Filing it opens an item with no work in it: +// projectbluefin/gutenprint-printer-app#170 ("Linked issue #8203 is a parsing +// artifact … No action needed on the PR"). Any higher severity is filed as +// before, whatever its wording. +func findingNeedsNoAction(f outputschema.Finding) bool { + return f.Severity == outputschema.SeverityInfo && noActionRE.MatchString(f.Title+"\n"+f.Summary) +} + func reviewBacklogKey(repo string, pr int, perspective review.Perspective, f outputschema.Finding) string { h := sha256.Sum256([]byte(strings.ToLower(strings.Join([]string{ strings.TrimSpace(repo),