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-15155-closed-issue-blockers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Clear blockers when issues close through GitHub or the hive, so closed issues no longer inflate the capabilities blocked-item count ([#15155](https://github.com/hivecommons/hive/issues/15155)).
50 changes: 50 additions & 0 deletions src/pkg/github/issue_blocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,53 @@ func TestIssueStageFactsCarryBlocker(t *testing.T) {
t.Fatalf("derived = %+v", d)
}
}

// Ordinary GitHub closes must clear the same ledger used by capabilitiesStatus.
func TestWebhookClosedIssueClearsBlocker(t *testing.T) {
for _, tt := range []struct {
name, event, action, state, repo string
pr, wantBlocked bool
}{
{"closed", "issues", "closed", "closed", "org/repo", false, false},
{"closed comment", "issue_comment", "created", "closed", "org/repo", false, false},
{"edited closed comment", "issue_comment", "edited", "closed", "org/repo", false, false},
{"closed label event", "issues", "labeled", "closed", "ORG/REPO", false, false},
{"open issue", "issues", "labeled", "open", "org/repo", false, true},
{"reopened issue", "issues", "reopened", "open", "org/repo", false, true},
{"unknown repository", "issues", "closed", "closed", "other/repo", false, true},
{"PR comment", "issue_comment", "created", "closed", "org/repo", true, true},
} {
t.Run(tt.name, func(t *testing.T) {
l := swapSharedLedger(t)
c, _ := setupWebhookCacheTest(t)
l.Observe("org/repo", 7, workflowsReport, time.Now())
l.Observe("org/repo", 8, workflowsReport, time.Now())
l.Observe("repo", 7, workflowsReport, time.Now())
pr := ""
if tt.pr {
pr = `,"pull_request":{"url":"x"}`
}
payload := `{"action":` + jsonString(tt.action) + `,"issue":{"number":7,"state":` + jsonString(tt.state) + pr + `},"comment":{"body":` + jsonString(workflowsReport) + `},"repository":{"full_name":` + jsonString(tt.repo) + `}}`
res, err := c.HandleWebhookEvent(tt.event, []byte(payload))
if err != nil {
t.Fatal(err)
}
if _, blocked := l.Blocking("org/repo", 7); blocked != tt.wantBlocked {
t.Fatalf("blocked = %v, want %v", blocked, tt.wantBlocked)
}
if _, blocked := l.Blocking("repo", 7); blocked != tt.wantBlocked {
t.Fatalf("short-name blocked = %v, want %v", blocked, tt.wantBlocked)
}
wantCount := 1
if tt.wantBlocked {
wantCount += 2
}
if caps := l.Capabilities(); caps.BlockedItems != wantCount || caps.ByPermission["workflows"] != wantCount {
t.Fatalf("capabilities = %+v, want %d blocked items", caps, wantCount)
}
if !tt.wantBlocked && res.BlockerKind != "" {
t.Fatalf("closed issue recorded blocker %q", res.BlockerKind)
}
})
}
}
8 changes: 8 additions & 0 deletions src/pkg/github/issue_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

gh "github.com/google/go-github/v72/github"

itemblocker "github.com/hivecommons/hive/pkg/blocker"
"github.com/hivecommons/hive/pkg/forgestate"
)

Expand Down Expand Up @@ -128,6 +129,13 @@ func (c *Client) closeIssue(ctx context.Context, repo string, number int, opts I
if _, _, err := c.client.Issues.Edit(ctx, owner, repoName, number, req); err != nil {
return false, fmt.Errorf("closing issue %s/%s#%d: %w", owner, repoName, number, err)
}
if !isPR {
l := itemblocker.Shared()
l.Clear(owner+"/"+repoName, number)
if repo != owner+"/"+repoName {
l.Clear(repo, number)
}
}
closedKind := forgestate.KindIssue
if isPR {
closedKind = forgestate.KindPR
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/github/issue_close_error_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

gh "github.com/google/go-github/v72/github"
)
Expand Down Expand Up @@ -132,6 +133,8 @@ func TestCloseIssueOverrideCommentFailureAbortsClose(t *testing.T) {
}

func TestCloseIssueEditFailure(t *testing.T) {
l := swapSharedLedger(t)
l.Observe("o/r", 7, workflowsReport, time.Now())
issue := closeGateIssue("hive-app[bot]", "Bot", "Bug: bot finding", "automated", []string{"bug"})
srv := closeGateMux(t, issue, emptyCommentList, failHandler, failHandler)
defer srv.Close()
Expand All @@ -141,6 +144,9 @@ func TestCloseIssueEditFailure(t *testing.T) {
if err == nil || !strings.Contains(err.Error(), "closing issue") {
t.Fatalf("err = %v, want close-edit failure", err)
}
if _, blocked := l.Blocking("o/r", 7); !blocked {
t.Fatal("failed close cleared the blocker")
}
}

// TestHasReporterConfirmationRequestPaginates pins the pagination arm: a
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/github/issue_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

gh "github.com/google/go-github/v72/github"
)
Expand Down Expand Up @@ -77,6 +78,8 @@ func TestCloseIssueReporterConfirmationGate(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
l := swapSharedLedger(t)
l.Observe("o/r", 7, workflowsReport, time.Now())
var closed bool
var comments []string
var labels []string
Expand Down Expand Up @@ -137,6 +140,9 @@ func TestCloseIssueReporterConfirmationGate(t *testing.T) {
if closed != tt.wantClosed {
t.Fatalf("closed = %v, want %v", closed, tt.wantClosed)
}
if _, blocked := l.Blocking("o/r", 7); blocked == tt.wantClosed {
t.Fatalf("blocked = %v after close, want %v", blocked, !tt.wantClosed)
}
if tt.wantComment == "" {
if len(comments) != 0 {
t.Fatalf("comments = %q, want none", comments)
Expand Down
15 changes: 13 additions & 2 deletions src/pkg/github/webhook_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,21 @@ func (c *Client) HandleWebhookEvent(event string, payload []byte) (WebhookEventR
aliases := webhookRepoAliases(configured, p.Repository.FullName)
sharedWebhookTracker.recordEvent(aliases)

res.Item = webhookItemHint(event, p)
if n, ok := webhookTouchedIssue(event, p); ok {
res.TouchedIssues = []int{n}
if body, at, ok := webhookIssueCommentBody(event, p); ok {
if res.Item.Closed() {
// Closed issues no longer contribute to blocked_items. Comments
// delivered after closure must not recreate their blocker.
l := itemblocker.Shared()
l.Clear(configured, n)
// Comment webhooks use the configured name; sweep reports use
// owner/repo. Clear both when configuration uses a short name.
owner, repo := c.splitRepo(configured)
if full := owner + "/" + repo; full != configured {
l.Clear(full, n)
}
} else if body, at, ok := webhookIssueCommentBody(event, p); ok {
// A needs-human report that names a capability the App lacks
// becomes a structured blocker the moment it lands, so the
// tracker and "Let hive decide" read it before the next
Expand All @@ -502,7 +514,6 @@ func (c *Client) HandleWebhookEvent(event string, payload []byte) (WebhookEventR
}
}
}
res.Item = webhookItemHint(event, p)
if reviewRequestWakeEvent(event, p) {
c.reviewWake.wake()
res.WokeReviewWatcher = true
Expand Down
Loading