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-16591.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The un-park sweep no longer posts the "What to reply" notice or the `/hive approve` hint on an issue held after a human decision (`needs-human` + `approved-direction`, no stage/045), while still answering `/hive decision`, `/hive help` and `/fixed` on it ([#16591](https://github.com/hivecommons/hive/issues/16591)).
20 changes: 19 additions & 1 deletion src/pkg/github/issue_unpark_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ func (c *Client) tryUnparkIssue(ctx context.Context, displayRepo, owner, repo st
if err != nil {
return false, err
}
if !labelDriven {
// A held issue (hivecommons/hive#16591) has nothing open to decide: no
// "What to reply" notice and no prose hint, but every command it does
// get is still answered.
held := isHeldAfterDecision(issueLabelNames(issue.Labels))
if !labelDriven && !held {
if err := c.ensureUnparkNoticeComment(ctx, owner, repo, number, issue.GetBody(), comments); err != nil {
return false, err
}
Expand Down Expand Up @@ -503,6 +507,9 @@ func (c *Client) tryUnparkIssue(ctx context.Context, displayRepo, owner, repo st
return true, nil
case unparkCommandNone:
// Prose assent, no command. Say what to type; do not act on it.
if held {
return false, nil
}
if err := c.postUnparkReply(ctx, owner, repo, number, candidate.GetID(), unparkProseHintReply); err != nil {
return false, err
}
Expand Down Expand Up @@ -1283,3 +1290,14 @@ func renderUnparkFixedReply(actor, note string, removed []string) string {
b.WriteString("; any `hold` label is left exactly as it was.\n\nIf this was closed by mistake, the reporter or a maintainer can comment `/reopen`.")
return b.String()
}

// isHeldAfterDecision reports an issue held after a human decision:
// `needs-human` beside the approval label and without a stage/045 park label.
// Nothing is open to decide on it, so the sweep stops offering `/hive approve`
// / `/hive decision` (hivecommons/hive#16591) while still answering any
// command a maintainer posts.
func isHeldAfterDecision(labels []string) bool {
return hasIssueNeedsHumanLabel(labels) && labelPresent(labels, HumanAckLabel) &&
!labelPresent(labels, NeedsDecisionStageLabel) && !labelPresent(labels, legacyIssueNeedsDecisionStageLabel) &&
!labelPresent(labels, issueNeedsDecisionLabel) && !labelPresent(labels, issueNeedsDirectionLabel)
}
86 changes: 86 additions & 0 deletions src/pkg/github/issue_unpark_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,3 +1269,89 @@ func TestParseUnparkCommandKeepsDecisionTextAfterFirstLine(t *testing.T) {
t.Fatalf("single-line decision = %+v", single)
}
}

func heldIssue(number int, comments ...unparkWireComment) unparkWireIssue {
issue := parkedIssue(number, comments...)
issue.Labels = []wireLabel{{Name: "needs-human"}, {Name: HumanAckLabel}, {Name: "hold"}}
return issue
}

func TestIsHeldAfterDecision(t *testing.T) {
if !isHeldAfterDecision([]string{"needs-human", HumanAckLabel}) {
t.Fatal("needs-human + approved-direction without a park stage is held")
}
if isHeldAfterDecision([]string{"needs-human", HumanAckLabel, NeedsDecisionStageLabel}) {
t.Fatal("a stage/045 park label means something is still open to decide")
}
if isHeldAfterDecision([]string{"needs-human"}) {
t.Fatal("needs-human alone is parked, not held")
}
if !hasIssueParkingLabel([]string{"needs-human", HumanAckLabel}) {
t.Fatal("a held issue stays in the sweep so its commands are still answered")
}
}

func TestSweepIssueUnparkCommandsHeldIssueGetsNoNoticeOrProseHint(t *testing.T) {
issues := []unparkWireIssue{
heldIssue(61),
heldIssue(62, humanComment(71, "maintainer", "sounds good, go ahead")),
}
server, rec := newUnparkServer(t, "org", "repo", issues, map[string]string{"maintainer": "admin"})
c := newTestClient(t, server, "org", []string{"repo"})

result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{})
if err != nil {
t.Fatalf("sweep: %v", err)
}
if result.Seen != 2 || len(result.Unparked) != 0 || result.Replies != 0 {
t.Fatalf("seen=%d unparked=%+v replies=%d", result.Seen, result.Unparked, result.Replies)
}
for _, n := range []int{61, 62} {
if len(rec.posted[n]) != 0 {
t.Fatalf("held issue %d must not be re-offered a decision, got %v", n, rec.posted[n])
}
}
if len(rec.edited) != 0 {
t.Fatalf("no notice to edit on a held issue, got %v", rec.edited)
}
}

func TestSweepIssueUnparkCommandsHeldIssueStillAnswersDecision(t *testing.T) {
issues := []unparkWireIssue{heldIssue(63, humanComment(72, "maintainer", "/hive decision ship it as is"))}
server, rec := newUnparkServer(t, "org", "repo", issues, map[string]string{"maintainer": "admin"})
c := newTestClient(t, server, "org", []string{"repo"})

result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{})
if err != nil {
t.Fatalf("sweep: %v", err)
}
if len(result.Unparked) != 1 || result.Unparked[0].Number != 63 || result.Unparked[0].Decision != "ship it as is" {
t.Fatalf("a /hive decision on a held issue must still be answered, got %+v", result.Unparked)
}
if len(rec.posted[63]) != 1 || !strings.Contains(rec.posted[63][0], "Decision: ship it as is") {
t.Fatalf("expected exactly the acceptance reply, got %v", rec.posted[63])
}
if strings.Contains(rec.posted[63][0], unparkNoticeMarker) {
t.Fatalf("the notice must not be posted on a held issue: %v", rec.posted[63])
}
if strings.Contains(strings.Join(rec.removed[63], ","), "hold") {
t.Fatalf("hold must never be removed, got %v", rec.removed[63])
}
}

func TestSweepIssueUnparkCommandsHeldIssueStillAnswersHelp(t *testing.T) {
issues := []unparkWireIssue{heldIssue(64, humanComment(73, "maintainer", "/hive help"))}
server, rec := newUnparkServer(t, "org", "repo", issues, map[string]string{"maintainer": "admin"})
c := newTestClient(t, server, "org", []string{"repo"})

result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{})
if err != nil {
t.Fatalf("sweep: %v", err)
}
if result.Replies != 1 || len(rec.posted[64]) != 1 {
t.Fatalf("expected one help reply, replies=%d posted=%v", result.Replies, rec.posted[64])
}
if strings.Contains(rec.posted[64][0], unparkNoticeMarker) {
t.Fatalf("the help reply must be the only comment, got %v", rec.posted[64])
}
}
Loading