Skip to content

Commit 55124f1

Browse files
committed
cmd/gopherbot: add task to ping "early-in-cycle" issues
There are two tasks we regularly do when reopening the tree for the next major Go version development: remove "wait-release" hashtags from CLs, and ping issues with "early-in-cycle" label. The former was automated in CL 129817. The latter is automated here. Maintner is used to find issues, and a GitHub API client is used to post comments. The Go 1.17 cycle was used as an opportunity to test this approach. It worked as expected; no unexpected problems were found. Like the unwait-release task, this is run manually via -only-run flag. In the future we may want to factor both of these tasks out of gopherbot and into a place that can be used by release automation. But this seems like the most sensible place to add it initially. Add a brief sleep in the hot loop for tasks that are invoked manually. This is to appease humans and can modified at will. It's unlikely to remain needed when these tasks are automated further. For golang/go#40279. Change-Id: I70c4eb7e98551d610f1518d1599661db21e2f271 Reviewed-on: https://go-review.googlesource.com/c/build/+/300570 Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Dmitri Shuralyov <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent ce4d62a commit 55124f1

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

cmd/gopherbot/gopherbot.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565
needsDecisionID = 373401956
6666
needsFixID = 373399998
6767
needsInvestigationID = 373402289
68+
earlyInCycleID = 626114143
6869
)
6970

7071
// Label names (that are used in multiple places).
@@ -355,6 +356,7 @@ var tasks = []struct {
355356
// Tasks that are specific to the golang/go repo.
356357
{"kicktrain", (*gopherbot).getOffKickTrain},
357358
{"unwait-release", (*gopherbot).unwaitRelease},
359+
{"ping-early-issues", (*gopherbot).pingEarlyIssues},
358360
{"label build issues", (*gopherbot).labelBuildIssues},
359361
{"label mobile issues", (*gopherbot).labelMobileIssues},
360362
{"label tools issues", (*gopherbot).labelToolsIssues},
@@ -792,6 +794,8 @@ func (b *gopherbot) unwaitRelease(ctx context.Context) error {
792794
log.Printf("[dry run] would remove hashtag 'wait-release' from CL %d", ci.ChangeNumber)
793795
continue
794796
}
797+
log.Printf("https://golang.org/cl/%d: removing wait-release", ci.ChangeNumber)
798+
time.Sleep(3 * time.Second) // Take a moment between updating CLs, since a human will be running this task manually.
795799
_, err := b.gerrit.SetHashtags(ctx, ci.ID, gerrit.HashtagsInput{
796800
Add: []string{"ex-wait-release"},
797801
Remove: []string{"wait-release"},
@@ -800,11 +804,55 @@ func (b *gopherbot) unwaitRelease(ctx context.Context) error {
800804
log.Printf("https://golang.org/cl/%d: modifying hash tags: %v", ci.ChangeNumber, err)
801805
return err
802806
}
803-
log.Printf("https://golang.org/cl/%d: removed wait-release", ci.ChangeNumber)
804807
}
805808
return nil
806809
}
807810

811+
// pingEarlyIssues pings early-in-cycle issues in the next major release milestone.
812+
// This is run manually (with --only-run) at the opening of a release cycle.
813+
func (b *gopherbot) pingEarlyIssues(ctx context.Context) error {
814+
// We only run this task if it was explicitly requested via
815+
// the --only-run flag.
816+
if *onlyRun == "" {
817+
return nil
818+
}
819+
820+
// Compute nextMajor, a value like "1.17" representing that Go 1.17
821+
// is the next major version (the version whose development just started).
822+
majorReleases, err := b.getMajorReleases(ctx)
823+
if err != nil {
824+
return err
825+
}
826+
nextMajor := majorReleases[len(majorReleases)-1]
827+
828+
// The message posted in this task links to an announcement that the tree is open
829+
// for general Go 1.x development. Update the openTreeURLs map appropriately when
830+
// running this task.
831+
openTreeURLs := map[string]string{
832+
"1.17": "https://groups.google.com/g/golang-dev/c/VNJFUxHWLHo/m/PBmGdYqoAAAJ",
833+
}
834+
if url, ok := openTreeURLs[nextMajor]; !ok {
835+
return fmt.Errorf("openTreeURLs[%q] is missing a value, please fill it in", nextMajor)
836+
} else if !strings.HasPrefix(url, "https://groups.google.com/g/golang-dev/c/") {
837+
return fmt.Errorf("openTreeURLs[%q] is %q, which doesn't begin with the usual prefix, so please double-check that the URL is correct", nextMajor, url)
838+
}
839+
840+
return b.gorepo.ForeachIssue(func(gi *maintner.GitHubIssue) error {
841+
if gi.NotExist || gi.Closed || gi.PullRequest || !gi.HasLabelID(earlyInCycleID) || gi.Milestone.Title != "Go"+nextMajor {
842+
return nil
843+
}
844+
if *dryRun {
845+
log.Printf("[dry run] would ping early-in-cycle issue %d", gi.Number)
846+
return nil
847+
}
848+
log.Printf("pinging early-in-cycle issue %d", gi.Number)
849+
time.Sleep(3 * time.Second) // Take a moment between pinging issues, since a human will be running this task manually.
850+
msg := fmt.Sprintf("This issue is currently labeled as early-in-cycle for Go %s.\n"+
851+
"That [time is now](%s), so a friendly reminder to look at it again.", nextMajor, openTreeURLs[nextMajor])
852+
return b.addGitHubComment(ctx, b.gorepo, gi.Number, msg)
853+
})
854+
}
855+
808856
// freezeOldIssues locks any issue that's old and closed.
809857
// (Otherwise people find ancient bugs via searches and start asking questions
810858
// into a void and it's sad for everybody.)
@@ -1472,6 +1520,9 @@ func (b *gopherbot) onLatestCL(ctx context.Context, cl *maintner.GerritCL, f fun
14721520

14731521
// getMajorReleases returns the two most recent major Go 1.x releases, and
14741522
// the next upcoming release, sorted and formatted like []string{"1.9", "1.10", "1.11"}.
1523+
//
1524+
// The data returned is fetched from Maintner Service occasionally
1525+
// and cached for some time.
14751526
func (b *gopherbot) getMajorReleases(ctx context.Context) ([]string, error) {
14761527
b.releases.Lock()
14771528
defer b.releases.Unlock()

0 commit comments

Comments
 (0)