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-19155-unpark-prose-decision.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The issue un-park sweep now treats a maintainer's first line of `Decision: <text>` (or `Decision (owner): <text>`) on a parked issue as `/hive decision <text>`, and replies with the `/hive decision` hint to `option N`, `decide` and bare option-letter comments instead of ignoring them ([#19155](https://github.com/hivecommons/hive/issues/19155)).
8 changes: 8 additions & 0 deletions src/docs/maintainer-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ and posted by someone who currently has `write`, `maintain`, or `admin`
permission on the repository. A `/hive decision` must include non-empty
instructions.

On an issue, a first line of `Decision: <text>` (or `Decision (owner): <text>`)
is read as `/hive decision <text>`, under the same permission, freshness and
unedited rules; the lines after it are kept as part of the decision. A first
line that names a decision without recording one (`Decision:` with no text,
`decide ...`, `option 1`, or a bare option letter such as `B`) un-parks nothing
and gets a reply telling the commenter to use `/hive decision <text>`. PRs keep
the strict `/hive decision` shape.

The on-demand `/hive help` workflow uses the same first-line command shape, is
ignored for bot comments, and allows `triage`, `write`, `maintain`, or `admin`
because it only posts reference text and changes no labels.
Expand Down
69 changes: 64 additions & 5 deletions src/pkg/github/issue_unpark_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -510,7 +511,7 @@ func (c *Client) tryUnparkIssue(ctx context.Context, displayRepo, owner, repo st
return acted, err
}
}
candidate, command, err := c.eligibleUnparkCommand(ctx, owner, repo, comments, answered, cutoff, labelDriven && la.enabled, verbs)
candidate, command, err := c.eligibleUnparkCommand(ctx, owner, repo, comments, answered, cutoff, labelDriven && la.enabled, verbs, true)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -988,15 +989,19 @@ const unparkCandidateLimit = 5
//
// verbs are the bound workflow model's replies for the item's current state
// (hivecommons/hive#17620); nil admits the built-in commands only.
func (c *Client) eligibleUnparkCommand(ctx context.Context, owner, repo string, comments []*gh.IssueComment, answered map[int64]bool, cutoff time.Time, allowTriage bool, verbs []string) (*gh.IssueComment, unparkCommand, error) {
//
// proseDecision admits a first line of `Decision: <text>` (or `Decision
// (owner): <text>`) as `/hive decision <text>` (hivecommons/hive#19155). Only
// the issue sweep sets it; PRs keep the strict `/hive` command shape.
func (c *Client) eligibleUnparkCommand(ctx context.Context, owner, repo string, comments []*gh.IssueComment, answered map[int64]bool, cutoff time.Time, allowTriage bool, verbs []string, proseDecision bool) (*gh.IssueComment, unparkCommand, error) {
checked := 0
for i := len(comments) - 1; i >= 0 && checked < unparkCandidateLimit; i-- {
cm := comments[i]
if cm == nil {
continue
}
if answered[cm.GetID()] {
if isUnparkWatermarkCommandFor(cm.GetBody(), verbs) {
if isUnparkWatermarkCommandFor(cm.GetBody(), verbs) || (proseDecision && isUnparkProseDecision(cm.GetBody())) {
break
}
continue
Expand All @@ -1010,7 +1015,13 @@ func (c *Client) eligibleUnparkCommand(ctx context.Context, owner, repo string,
continue
}
cmd, isCommand := parseUnparkCommandFor(cm.GetBody(), verbs)
if !isCommand && !isUnparkProseAssent(cm.GetBody()) {
if !isCommand && proseDecision {
cmd, isCommand = parseUnparkProseDecision(cm.GetBody())
}
// The decision hint (a bare `B`, `option 1`, `decide ...`) is only for
// the issue sweep. On a PR a one-letter reply is common, and as the
// newest candidate it would hide an older valid `/hive decision`.
if !isCommand && !isUnparkProseAssent(cm.GetBody()) && !(proseDecision && isUnparkProseDecisionHint(cm.GetBody())) {
continue
}
if !c.isHumanAuthor(cm.GetUser()) || isHiveSelfDecisionComment(cm.GetBody()) {
Expand Down Expand Up @@ -1085,6 +1096,36 @@ func parseUnparkCommand(body string) (unparkCommand, bool) {
return unparkCommand{}, false
}

// unparkProseDecisionPrefix matches a first line that records a decision the
// way maintainers habitually write it: `Decision: option 1 ...` or
// `Decision (owner): option 1 ...`.
var unparkProseDecisionPrefix = regexp.MustCompile(`(?i)^decision(?:\s*\([^)\n]*\))?\s*:\s*`)

// parseUnparkProseDecision reads a first line of `Decision: <text>` as
// `/hive decision <text>`. It is held to the same rules as the command: first
// line only, never inside a quote or fence, and the text must be non-empty. The
// caller still applies the permission, freshness and unedited checks.
func parseUnparkProseDecision(body string) (unparkCommand, bool) {
line := firstNonEmptyLine(body)
if strings.HasPrefix(line, ">") || strings.HasPrefix(line, "```") || strings.HasPrefix(line, "~~~") {
return unparkCommand{}, false
}
loc := unparkProseDecisionPrefix.FindStringIndex(line)
if loc == nil {
return unparkCommand{}, false
}
decision := strings.TrimSpace(line[loc[1]:])
if decision == "" {
return unparkCommand{}, false
}
return unparkCommand{Kind: unparkCommandDecision, Decision: decision, Text: decisionText(body, decision)}, true
}

func isUnparkProseDecision(body string) bool {
_, ok := parseUnparkProseDecision(body)
return ok
}

// decisionText joins the first-line decision with every line that follows
// the command line, so numbered instructions under `/hive decision approve`
// reach the author agent instead of being dropped (hivecommons/hive#14679).
Expand Down Expand Up @@ -1144,7 +1185,25 @@ func isUnparkProseAssent(body string) bool {
return false
}

const unparkProseHintReply = "To start work, reply `/hive approve` (or `/hive decision A`). A plain reply acknowledges the issue but leaves it parked."
// isUnparkProseDecisionHint reports whether a comment names a decision
// without the command (unparkProseDecisionHint). Like isUnparkProseAssent it
// only decides whether to print a hint, and only the issue sweep asks.
func isUnparkProseDecisionHint(body string) bool {
line := firstNonEmptyLine(body)
if line == "" || strings.HasPrefix(line, ">") || strings.HasPrefix(line, "/") {
return false
}
return unparkProseDecisionHint.MatchString(line)
}

// unparkProseDecisionHint matches a first line that names a decision without
// the command: `Decision ...` / `Decide ...` (a `Decision:` with text is acted
// on, so only the empty and malformed forms land here), `option 1` / `Option B`
// and a bare option letter. The reply tells the commenter to use
// `/hive decision <text>` (hivecommons/hive#19155).
var unparkProseDecisionHint = regexp.MustCompile(`^(?i:decision\b|decide\b|options?\s+[a-z0-9]\b)|^[A-Z][.!]?$`)

const unparkProseHintReply = "To start work, reply `/hive approve` (or `/hive decision A`, or `/hive decision <your instructions>` to record a decision). A plain reply acknowledges the issue but leaves it parked."

// unparkLabelDrivenReply answers `/hive approve`, `/hive decision` and
// `/hive help` on a repo with project.repo_policies[].label_driven set.
Expand Down
111 changes: 110 additions & 1 deletion src/pkg/github/issue_unpark_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,100 @@ func TestSweepIssueUnparkCommandsDecisionRecordsText(t *testing.T) {
}
}

func TestSweepIssueUnparkCommandsProseDecisionUnparks(t *testing.T) {
for _, body := range []string{
"Decision: option 1. Ship the small fix.",
"Decision (owner): option 1. Ship the small fix.",
} {
issues := []unparkWireIssue{parkedIssue(8, humanComment(21, "maintainer", body))}
server, rec := newUnparkServer(t, "org", "repo", issues, map[string]string{"maintainer": "maintain"})
c := newTestClient(t, server, "org", []string{"repo"})

result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{})
if err != nil {
t.Fatalf("sweep %q: %v", body, err)
}
if len(result.Unparked) != 1 || result.Unparked[0].Decision != "option 1. Ship the small fix." {
t.Fatalf("%q: decision not recorded: %+v", body, result.Unparked)
}
if !strings.Contains(strings.Join(rec.posted[8], "\n"), "Decision: option 1. Ship the small fix.") {
t.Fatalf("%q: expected the decision in the reply, got %v", body, rec.posted[8])
}
}
}

func TestSweepIssueUnparkCommandsProseDecisionKeepsGates(t *testing.T) {
cases := []struct {
name string
comment unparkWireComment
perms map[string]string
}{
{"read only", humanComment(31, "drive-by", "Decision: option 1"), map[string]string{"drive-by": "read"}},
{"bot account", humanComment(32, "other[bot]", "Decision: option 1"), map[string]string{"other[bot]": "admin"}},
{"quoted", humanComment(33, "maintainer", "> Decision: option 1\n\nnot mine"), map[string]string{"maintainer": "admin"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
issues := []unparkWireIssue{parkedIssue(9, tc.comment)}
server, rec := newUnparkServer(t, "org", "repo", issues, tc.perms)
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) != 0 || len(rec.removed[9]) != 0 {
t.Fatalf("must not un-park: %+v removed=%v", result.Unparked, rec.removed[9])
}
})
}
}

func TestSweepIssueUnparkCommandsDecisionHintReplies(t *testing.T) {
for _, body := range []string{"Decision:", "option 1", "Option B", "B", "Decide: later"} {
issues := []unparkWireIssue{parkedIssue(12, humanComment(62, "maintainer", body))}
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 %q: %v", body, err)
}
if len(result.Unparked) != 0 || result.Replies != 1 {
t.Fatalf("%q: want one hint and no un-park, got %+v replies=%d", body, result.Unparked, result.Replies)
}
if !strings.Contains(strings.Join(rec.posted[12], "\n"), "/hive decision") {
t.Fatalf("%q: hint must name /hive decision, got %v", body, rec.posted[12])
}
}
}

func TestParseUnparkProseDecision(t *testing.T) {
cases := []struct {
body string
want string
ok bool
}{
{"Decision: option 1", "option 1", true},
{"decision (owner): B\n\nfollow-up detail", "B", true},
{"DECISION:go with A", "go with A", true},
{"Decision:", "", false},
{"Decision (owner): ", "", false},
{"Decision taken by hive: A", "", false},
{"> Decision: A", "", false},
{"thanks\nDecision: A", "", false},
{"/hive decision A", "", false},
}
for _, tc := range cases {
cmd, ok := parseUnparkProseDecision(tc.body)
if ok != tc.ok || cmd.Decision != tc.want || (ok && cmd.Kind != unparkCommandDecision) {
t.Errorf("parseUnparkProseDecision(%q) = %+v, %v; want %q/%v", tc.body, cmd, ok, tc.want, tc.ok)
}
}
if cmd, _ := parseUnparkProseDecision("Decision: A\n\nmore"); cmd.Text != "A\n\nmore" {
t.Errorf("Text = %q, want the trailing lines kept", cmd.Text)
}
}

func TestSweepIssueUnparkCommandsIgnoresIneligibleCommenters(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -750,13 +844,28 @@ func TestIsUnparkProseAssent(t *testing.T) {
t.Errorf("isUnparkProseAssent(%q) = false, want true", body)
}
}
for _, body := range []string{"/hive approve", "/fixed approved", "> approved", "what do you think?", ""} {
// The decision forms are the issue sweep's hint (isUnparkProseDecisionHint),
// not assent: the PR sweep must not treat a bare `B` as a candidate.
for _, body := range []string{"/hive approve", "/fixed approved", "> approved", "what do you think?", "", "Bravo team", "optional", "Decision:", "option 1", "B"} {
if isUnparkProseAssent(body) {
t.Errorf("isUnparkProseAssent(%q) = true, want false", body)
}
}
}

func TestIsUnparkProseDecisionHint(t *testing.T) {
for _, body := range []string{"Decision:", "decide later", "option 1", "Option B", "B"} {
if !isUnparkProseDecisionHint(body) {
t.Errorf("isUnparkProseDecisionHint(%q) = false, want true", body)
}
}
for _, body := range []string{"/hive decision B", "> option 1", "", "Bravo team", "optional", "approved"} {
if isUnparkProseDecisionHint(body) {
t.Errorf("isUnparkProseDecisionHint(%q) = true, want false", body)
}
}
}

func TestHasIssueParkingLabel(t *testing.T) {
if !hasIssueParkingLabel([]string{"Needs-Human"}) || !hasIssueParkingLabel([]string{"needs-decision"}) || !hasIssueParkingLabel([]string{"Needs-Direction"}) {
t.Fatal("parking labels must be recognised case-insensitively")
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/pr_unpark_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *Client) tryUnparkPullRequest(ctx context.Context, displayRepo, owner, r
return false, err
}
answered := c.answeredUnparkCommentIDs(comments)
candidate, command, err := c.eligibleUnparkCommand(ctx, owner, repo, comments, answered, cutoff, false, nil)
candidate, command, err := c.eligibleUnparkCommand(ctx, owner, repo, comments, answered, cutoff, false, nil, false)
if err != nil {
return false, err
}
Expand Down
22 changes: 22 additions & 0 deletions src/pkg/github/pr_unpark_decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,25 @@ func (s reviewOnlyStore) For(repo string, n int, head string) (review.HumanChang
func (s reviewOnlyStore) Forget(repo string, n int, source string, sourceID int64) error {
return s.inner.Forget(repo, n, source, sourceID)
}

// The decision hint added for issues (#19155) must not reach the PR sweep: on
// a PR a newer one-letter reply such as `B` would become the newest candidate
// and hide an older valid `/hive decision` (review on #19168).
func TestSweepIssueUnparkCommandsPRBareLetterDoesNotHideDecision(t *testing.T) {
issues := []unparkWireIssue{hiveParkedPR(
humanComment(4242, "clubanderson", "/hive decision "+liveDecisionText),
humanComment(4243, "clubanderson", "B"),
)}
c, _ := newUnparkPRClient(t, issues, map[string]string{"clubanderson": "admin"})

result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{
HumanChangeRequests: review.NewHumanChangeRequests(""),
TrustedMerger: trustedMergerSet("clubanderson"),
})
if err != nil {
t.Fatalf("sweep: %v", err)
}
if len(result.PRDecisions) != 1 || result.PRDecisions[0].Decision != liveDecisionText {
t.Fatalf("result = %+v, want the older /hive decision recorded despite the newer bare letter", result)
}
}
Loading