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
1 change: 1 addition & 0 deletions changelog.d/fixed-blocked-issue-form-comment-marker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A `<!-- hive:blocked-on issue=owner/repo#N -->` 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.
15 changes: 12 additions & 3 deletions src/pkg/github/issue_blocked.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
62 changes: 62 additions & 0 deletions src/pkg/github/issue_blocked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":"<!-- hive:blocked-on issue=o/r#100 -->\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)
}
}
Loading