Skip to content

Commit b8243eb

Browse files
committed
cmd/gopherbot: don't fight over NeedsDecision removal
This is a followup to CL 180925 to prevent gopherbot from fighting people (too much) if they decide to override gopherbot's behavior and re-add the NeedsDecision label. It's done by adding a check for whether gopherbot has already taken the action and avoid repeating it if so. Since this action is removing a label, we can't just check for any "labeled" event, as those are likely to happen for other reasons. So add a more precise check for whether gopherbot has previously removed the "NeedsDecision" label from the target issue. Updates golang/go#31788 Updates golang/go#21312 Change-Id: Iaf4dd69a5bfd637694995ee60869f94362110a7d Reviewed-on: https://go-review.googlesource.com/c/build/+/183624 Reviewed-by: Andrew Bonventre <[email protected]>
1 parent 1b388d2 commit b8243eb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

cmd/gopherbot/gopherbot.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ var (
5252
onlyRun = flag.String("only-run", "", "if non-empty, the name of a task to run. Mostly for debugging, but tasks (like 'kicktrain') may choose to only run in explicit mode")
5353
)
5454

55+
const (
56+
gopherbotGitHubID = 8566911
57+
)
58+
5559
// GitHub Label IDs for the golang/go repo.
5660
const (
5761
needsDecisionID = 373401956
@@ -751,8 +755,8 @@ func (b *gopherbot) labelProposals(ctx context.Context) error {
751755
}
752756
}
753757

754-
// Remove NeedsDecision if exists
755-
if gi.HasLabel("NeedsDecision") {
758+
// Remove NeedsDecision label if exists:
759+
if gi.HasLabel("NeedsDecision") && !gopherbotRemovedLabel(gi, "NeedsDecision") {
756760
if err := b.removeLabel(ctx, gi, "NeedsDecision"); err != nil {
757761
return err
758762
}
@@ -761,6 +765,26 @@ func (b *gopherbot) labelProposals(ctx context.Context) error {
761765
})
762766
}
763767

768+
// gopherbotRemovedLabel reports whether gopherbot has
769+
// previously removed label in the GitHub issue gi.
770+
//
771+
// Note that until golang.org/issue/28226 is resolved,
772+
// there's a brief delay before maintner catches up on
773+
// GitHub issue events and learns that it has happened.
774+
func gopherbotRemovedLabel(gi *maintner.GitHubIssue, label string) bool {
775+
var hasRemoved bool
776+
gi.ForeachEvent(func(e *maintner.GitHubIssueEvent) error {
777+
if e.Actor != nil && e.Actor.ID == gopherbotGitHubID &&
778+
e.Type == "unlabeled" &&
779+
e.Label == label {
780+
hasRemoved = true
781+
return errStopIteration
782+
}
783+
return nil
784+
})
785+
return hasRemoved
786+
}
787+
764788
func (b *gopherbot) setSubrepoMilestones(ctx context.Context) error {
765789
return b.gorepo.ForeachIssue(func(gi *maintner.GitHubIssue) error {
766790
if gi.Closed || gi.PullRequest || !gi.Milestone.IsNone() || gi.HasEvent("demilestoned") || gi.HasEvent("milestoned") {

0 commit comments

Comments
 (0)