Skip to content
Closed
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-15273-blocker-ledger-clear-on-close.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- An `issues: closed` webhook now clears the closed issue's blocker ledger entry, so `capabilities.blocked_items` no longer counts closed issues ([#15273](https://github.com/hivecommons/hive/issues/15273)).
39 changes: 39 additions & 0 deletions src/pkg/github/issue_blocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,45 @@ func TestWebhookIssueCommentRecordsBlocker(t *testing.T) {
}
}

// hivecommons/hive#15273: closing an issue through GitHub (not only the
// dashboard's recheck/close-partial handlers) clears its ledger row, so
// capabilities.blocked_items stops counting it.
func TestWebhookIssueClosedClearsBlocker(t *testing.T) {
l := swapSharedLedger(t)
c, _ := setupWebhookCacheTest(t)
at := time.Date(2026, 10, 20, 19, 33, 0, 0, time.UTC)
res, err := c.HandleWebhookEvent("issue_comment", []byte(`{"action":"created","issue":{"number":21},"comment":{"body":`+jsonString(workflowsReport)+`,"created_at":"2026-10-20T19:33:00Z"},"repository":{"full_name":"org/repo"}}`))
if err != nil || res.BlockerKind == "" {
t.Fatalf("seed: %+v %v", res, err)
}
repo := res.ConfiguredRepo
l.Observe(repo, 22, workflowsReport, at)
if _, ok := l.Blocking(repo, 21); !ok {
t.Fatal("issue 21 not blocking before close")
}
// A labeled event leaves the row; a PR close is not an issue close.
for _, payload := range []string{
`{"action":"labeled","issue":{"number":21},"repository":{"full_name":"org/repo"}}`,
`{"action":"closed","issue":{"number":21,"pull_request":{"url":"x"}},"repository":{"full_name":"org/repo"}}`,
} {
if _, err := c.HandleWebhookEvent("issues", []byte(payload)); err != nil {
t.Fatal(err)
}
if _, ok := l.Blocking(repo, 21); !ok {
t.Fatalf("payload %s cleared the ledger row", payload)
}
}
if _, err := c.HandleWebhookEvent("issues", []byte(`{"action":"closed","issue":{"number":21},"repository":{"full_name":"org/repo"}}`)); err != nil {
t.Fatal(err)
}
if _, ok := l.Get(repo, 21); ok {
t.Fatal("closed issue kept its ledger row")
}
if got := l.Capabilities(); got.BlockedItems != 1 {
t.Fatalf("blocked_items = %+v, want only issue 22", got)
}
}

func jsonString(s string) string {
return `"` + strings.NewReplacer(`\`, `\\`, `"`, `\"`, "\n", `\n`).Replace(s) + `"`
}
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/github/webhook_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,17 @@ func (c *Client) HandleWebhookEvent(event string, payload []byte) (WebhookEventR
res.BlockerKind = string(e.Blocker.Kind)
}
}
// A closed issue is no longer blocked: forget its ledger row so
// capabilities.blocked_items stops counting it, the same as the
// dashboard's recheck and close-partial paths do
// (hivecommons/hive#15273).
if webhookIssueClosed(event, p) {
if l := itemblocker.Shared(); l != nil {
if _, ok := l.Get(configured, n); ok {
l.Clear(configured, n)
}
}
}
}
res.Item = webhookItemHint(event, p)
if reviewRequestWakeEvent(event, p) {
Expand Down Expand Up @@ -633,6 +644,11 @@ func webhookIssueCommentBody(event string, p webhookEventPayload) (string, time.
return p.Comment.Body, at, true
}

// webhookIssueClosed reports whether an `issues` delivery closed an issue.
func webhookIssueClosed(event string, p webhookEventPayload) bool {
return event == "issues" && p.Action == "closed"
}

// webhookIssueReopenedTarget returns the issue number of an `issues` event
// whose action reopened a non-PR issue.
func webhookIssueReopenedTarget(event string, p webhookEventPayload) (int, bool) {
Expand Down
Loading