diff --git a/changelog.d/fixed-blocked-issue-form-comment-marker.md b/changelog.d/fixed-blocked-issue-form-comment-marker.md new file mode 100644 index 0000000000..e74a8c9701 --- /dev/null +++ b/changelog.d/fixed-blocked-issue-form-comment-marker.md @@ -0,0 +1 @@ +- A `` marker read from an issue's comment is now remembered in the issue form, so the row reads "blocked on issue owner/repo#N". It was remembered as "blocked on owner/repo#N", and a later blocked sweep pass whose comment budget skipped the issue looked the blocker up as a pull request, which failed with a 404 and kept the block from ever lifting on that pass. diff --git a/src/pkg/github/issue_blocked.go b/src/pkg/github/issue_blocked.go index dc367a9b17..947f4c4e98 100644 --- a/src/pkg/github/issue_blocked.go +++ b/src/pkg/github/issue_blocked.go @@ -607,7 +607,7 @@ func (c *Client) reconcileBlockedTargets(ctx context.Context, targets []blockedI scanned = err == nil if scan.ok { prRepo, prNumber, onIssue, ok = scan.prRepo, scan.pr, scan.issue, scan.ok - noteBlockedOnSeen(t.repo, t.number, scan.prRepo, scan.pr) + noteBlockedOnSeenRef(t.repo, t.number, blockedOnRef{repo: scan.prRepo, number: scan.pr, issue: scan.issue}) blockers, fromComment = scan.refs, true } if !ok && !t.recheckAfter.IsZero() && !now.Before(t.recheckAfter) { @@ -910,9 +910,18 @@ func blockedOnSeenKey(repo string, number int) string { } func noteBlockedOnSeen(repo string, number int, prRepo string, pr int) { + noteBlockedOnSeenRef(repo, number, blockedOnRef{repo: prRepo, number: pr}) +} + +// noteBlockedOnSeenRef is noteBlockedOnSeen for either marker form. It keeps +// the issue form's "issue " word, so the reason the enumeration rebuilds from +// it ("blocked on issue owner/repo#N") still names an issue: in the PR form, a +// later pass whose comment budget skipped the issue read the reason back as a +// PR and looked the blocker up with GET /pulls/N, which 404s for an issue. +func noteBlockedOnSeenRef(repo string, number int, ref blockedOnRef) { blockedOnSeen.Lock() defer blockedOnSeen.Unlock() - blockedOnSeen.m[blockedOnSeenKey(repo, number)] = prRepo + "#" + strconv.Itoa(pr) + blockedOnSeen.m[blockedOnSeenKey(repo, number)] = ref.reasonRef() } func forgetBlockedOnSeen(repo string, number int) { @@ -1156,7 +1165,7 @@ func reconcileBlockedOnAll(ctx context.Context, c *Client, t blockedIssueTarget, logger.Info("blocked sweep: issue unblocked; every blocker settled", "repo", t.repo, "issue", t.number, "blockers", blockedOnRefList(settled)) return } - noteBlockedOnSeen(t.repo, t.number, open[0].repo, open[0].number) + noteBlockedOnSeenRef(t.repo, t.number, open[0]) if len(moves) > 0 { retargetBlockedOnAll(ctx, c, t, open, moves, scanned, res, logger) } diff --git a/src/pkg/github/issue_blocked_test.go b/src/pkg/github/issue_blocked_test.go index 28b4338502..77e24f696d 100644 --- a/src/pkg/github/issue_blocked_test.go +++ b/src/pkg/github/issue_blocked_test.go @@ -2050,3 +2050,65 @@ func TestBlockedSuccessorRefused(t *testing.T) { } } } + +// An issue-form marker read from a comment is remembered in the issue form: +// the enumeration's next reason is "blocked on issue o/r#100", so a later +// pass whose comment budget skips the issue looks the blocker up as an +// issue. It used to be remembered as "o/r#100", read back as a PR, and +// looked up with GET /repos/o/r/pulls/100, which 404s for an issue. +func TestBlockedOnSeenKeepsIssueForm(t *testing.T) { + var mu sync.Mutex + var calls []string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + mu.Lock() + calls = append(calls, r.Method+" "+r.URL.Path) + mu.Unlock() + switch { + case r.Method == "GET" && r.URL.Path == "/repos/o/r/issues/40/comments": + _, _ = io.WriteString(w, `[{"id":1,"body":"\nblocked on #100"}]`) + case r.Method == "GET" && r.URL.Path == "/repos/o/r/issues/100": + _, _ = io.WriteString(w, `{"number":100,"state":"open"}`) + case r.Method == "GET" && (strings.HasSuffix(r.URL.Path, "/comments") || strings.HasSuffix(r.URL.Path, "/timeline")): + _, _ = io.WriteString(w, `[]`) + case r.Method == "DELETE": + _, _ = io.WriteString(w, `[]`) + default: + w.WriteHeader(http.StatusNotFound) + _, _ = fmt.Fprintf(w, `{"path":%q}`, r.URL.Path) + } + })) + defer srv.Close() + c := testClient(t, srv.URL) + t.Cleanup(func() { forgetBlockedOnSeen("o/r", 40) }) + result := &ActionableResult{WorkDetailsByRepo: map[string]RepoWorkDetails{ + "o/r": {Issues: []RepoWorkIssue{{Repo: "o/r", Number: 40, Labels: []string{"blocked"}, Bucket: workBucketFiltered, Reason: "blocked"}}}, + }} + if res := ReconcileBlockedIssues(context.Background(), c, result, nil); res.Errors != 0 { + t.Fatalf("result = %+v", res) + } + reason := blockedFilterReasonFor("o/r", 40, "") + if reason != "blocked on issue o/r#100" { + t.Fatalf("remembered reason = %q, want the issue form", reason) + } + // reconcileBlockedTargets reads a pass's blocker from this reason when + // its comment budget is spent; it must name an issue, not a PR. + if _, _, isIssue, ok := parseBlockedOnReason(reason); !ok || !isIssue { + t.Fatalf("reason %q reads back as a PR", reason) + } + mu.Lock() + for _, call := range calls { + if strings.Contains(call, "/pulls/") { + mu.Unlock() + t.Fatalf("issue blocker looked up as a PR: %v", calls) + } + } + mu.Unlock() + + // The PR form is unchanged. + noteBlockedOnSeenRef("o/r", 41, blockedOnRef{repo: "o/r", number: 3}) + t.Cleanup(func() { forgetBlockedOnSeen("o/r", 41) }) + if got := blockedFilterReasonFor("o/r", 41, ""); got != "blocked on o/r#3" { + t.Fatalf("PR-form reason = %q", got) + } +}