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-16841-tooling-release-hive-label-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A tooling-failure blocked verdict now releases the `blocked` label only when the hive applied it; a human-applied `blocked` label is left in place ([#16841](https://github.com/hivecommons/hive/issues/16841)).
8 changes: 8 additions & 0 deletions src/pkg/dashboard/contribute_blocked_tooling.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func (h *ContributeWSHub) releaseToolingBlockedLabel(ctx context.Context, repo s
return ghpkg.ErrNoGitHubClient
}
client := h.server.deps.GHClient
ours, err := client.BlockedLabelAppliedByHive(ctx, repo, number)
if err != nil {
return err
}
if !ours {
// A human-applied `blocked` is theirs to lift.
return nil
}
if err := client.RemoveLabel(ctx, repo, number, blockedWorkflowLabel); err != nil {
return err
}
Expand Down
58 changes: 58 additions & 0 deletions src/pkg/dashboard/contribute_blocked_tooling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"time"

"github.com/gorilla/websocket"

ghpkg "github.com/hivecommons/hive/pkg/github"
)

// hivecommons/hive#11775 / #11776: a contributor's agent could not push to its
Expand Down Expand Up @@ -248,3 +250,59 @@ func TestBlockedVerdictToolingFailure_GenuineBlockedUntouched(t *testing.T) {
t.Fatalf("no release may happen for a genuine blocked verdict, got %v", fx.calls)
}
}

// A human-applied `blocked` must survive a tooling-failure verdict; only the
// label the hive applied itself is released.
func TestReleaseToolingBlockedLabel_OnlyHiveAppliedLabel(t *testing.T) {
cases := []struct {
name string
timeline string
wantDelete bool
}{
{"hive bot applied", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"hive-app[bot]","type":"Bot"}}]`, true},
{"human applied", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"maintainer","type":"User"}}]`, false},
{"human re-applied after bot", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"hive-app[bot]","type":"Bot"}},{"event":"labeled","created_at":"2026-10-20T11:00:00Z","label":{"name":"blocked"},"actor":{"login":"maintainer","type":"User"}}]`, false},
{"no labeled event", `[]`, false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var mu sync.Mutex
var calls []string
ts := 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/5/timeline":
_, _ = fmt.Fprint(w, tc.timeline)
case r.Method == "GET":
_, _ = fmt.Fprint(w, `[]`)
default:
_, _ = fmt.Fprint(w, `{}`)
}
}))
defer ts.Close()

hub, s := covK2Hub(t)
client := ghpkg.NewClientForTest(ts.URL, "o", []string{"r"}, covBLogger())
client.SetAppBotLogin("hive-app[bot]")
s.deps.GHClient = client

if err := hub.releaseToolingBlockedLabel(context.Background(), "o/r", 5, "u", "r"); err != nil {
t.Fatalf("release: %v", err)
}
mu.Lock()
defer mu.Unlock()
deleted := false
for _, c := range calls {
if strings.HasPrefix(c, "DELETE ") || strings.HasPrefix(c, "POST ") {
deleted = true
}
}
if deleted != tc.wantDelete {
t.Fatalf("mutating calls = %v, want label removal %v", calls, tc.wantDelete)
}
})
}
}
11 changes: 11 additions & 0 deletions src/pkg/github/issue_blocked.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,17 @@ func (c *Client) blockedLabelActor(ctx context.Context, repo string, number int)
return "", false, nil
}

// BlockedLabelAppliedByHive reports whether the most recent application of
// `blocked` to the issue was by this hive. A human-applied label, a missing
// labeled event, or a client with no hive identity reports false.
func (c *Client) BlockedLabelAppliedByHive(ctx context.Context, repo string, number int) (bool, error) {
actor, found, err := c.blockedLabelActor(ctx, repo, number)
if err != nil || !found {
return false, err
}
return c.isOwnBotLogin(actor) || c.IsHiveAuthorLogin(actor), nil
}

// parseBlockedOnReason reads "blocked on owner/repo#N" back into its parts.
func parseBlockedOnReason(reason string) (repo string, pr int, ok bool) {
rest, found := strings.CutPrefix(strings.TrimSpace(reason), blockedFilterReasonPrefix+" on ")
Expand Down
Loading