Skip to content

Commit 891e3b6

Browse files
jbagopherbot
authored andcommitted
internal/telemetry/cmd/stacks: cmd/compile reopen
Support re-opening issues for the compiler. Fixes golang/go#71045. Change-Id: I6e5dad81220c74923919b4c72f7bc1089af6c37d Reviewed-on: https://go-review.googlesource.com/c/tools/+/644018 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 4f1e910 commit 891e3b6

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

gopls/internal/telemetry/cmd/stacks/stacks.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,23 @@ func shouldReopen(issue *Issue, stacks map[string]map[Info]int64) bool {
626626
if !ok {
627627
return false
628628
}
629-
// TODO(jba?): handle other programs
630-
if issueProgram != "gopls" {
631-
return false
629+
630+
matchProgram := func(infoProg string) bool {
631+
switch issueProgram {
632+
case "gopls":
633+
return path.Base(infoProg) == issueProgram
634+
case "go":
635+
// At present, we only care about compiler stacks.
636+
// Issues should have milestones like "Go1.24".
637+
return infoProg == "cmd/compile"
638+
default:
639+
return false
640+
}
632641
}
642+
633643
for _, stack := range issue.newStacks {
634644
for info := range stacks[stack] {
635-
if path.Base(info.Program) == issueProgram && semver.Compare(info.ProgramVersion, issueVersion) >= 0 {
645+
if matchProgram(info.Program) && semver.Compare(semVer(info.ProgramVersion), issueVersion) >= 0 {
636646
log.Printf("reopening issue #%d: purportedly fixed in %s@%s, but found a new stack from version %s",
637647
issue.Number, issueProgram, issueVersion, info.ProgramVersion)
638648
return true
@@ -647,19 +657,46 @@ func (i *Issue) isFixed() bool {
647657
return i.State == "closed" && i.StateReason == "completed"
648658
}
649659

650-
// parseMilestone parses a the title of a GitHub milestone that is in the format
651-
// PROGRAM/VERSION. For example, "gopls/v0.17.0".
660+
// parseMilestone parses a the title of a GitHub milestone.
661+
// If it is in the format PROGRAM/VERSION (for example, "gopls/v0.17.0"),
662+
// then it returns PROGRAM and VERSION.
663+
// If it is in the format Go1.X, then it returns "go" as the program and
664+
// "v1.X" or "v1.X.0" as the version.
665+
// Otherwise, the last return value is false.
652666
func parseMilestone(m *Milestone) (program, version string, ok bool) {
653667
if m == nil {
654668
return "", "", false
655669
}
670+
if strings.HasPrefix(m.Title, "Go") {
671+
v := semVer(m.Title)
672+
if !semver.IsValid(v) {
673+
return "", "", false
674+
}
675+
return "go", v, true
676+
}
656677
program, version, ok = morestrings.CutLast(m.Title, "/")
657678
if !ok || program == "" || version == "" || version[0] != 'v' {
658679
return "", "", false
659680
}
660681
return program, version, true
661682
}
662683

684+
// semVer returns a semantic version for its argument, which may already be
685+
// a semantic version, or may be a Go version.
686+
//
687+
// v1.2.3 => v1.2.3
688+
// go1.24 => v1.24
689+
// Go1.23.5 => v1.23.5
690+
// goHome => vHome
691+
//
692+
// It returns "", false if the go version is in the wrong format.
693+
func semVer(v string) string {
694+
if strings.HasPrefix(v, "go") || strings.HasPrefix(v, "Go") {
695+
return "v" + v[2:]
696+
}
697+
return v
698+
}
699+
663700
// stackID returns a 32-bit identifier for a stack
664701
// suitable for use in GitHub issue titles.
665702
func stackID(stack string) string {

gopls/internal/telemetry/cmd/stacks/stacks_test.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ func TestMarshalUpdateIssueFields(t *testing.T) {
269269
func TestShouldReopen(t *testing.T) {
270270
const stack = "stack"
271271
const gopls = "golang.org/x/tools/gopls"
272-
const milestoneVersion = "v0.2.0"
272+
goplsMilestone := &Milestone{Title: "gopls/v0.2.0"}
273+
goMilestone := &Milestone{Title: "Go1.23"}
273274

274275
for _, tc := range []struct {
275276
name string
@@ -279,44 +280,61 @@ func TestShouldReopen(t *testing.T) {
279280
}{
280281
{
281282
"issue open",
282-
Issue{State: "open"},
283+
Issue{State: "open", Milestone: goplsMilestone},
283284
Info{Program: gopls, ProgramVersion: "v0.2.0"},
284285
false,
285286
},
286287
{
287288
"issue closed but not fixed",
288-
Issue{State: "closed", StateReason: "not_planned"},
289+
Issue{State: "closed", StateReason: "not_planned", Milestone: goplsMilestone},
289290
Info{Program: gopls, ProgramVersion: "v0.2.0"},
290291
false,
291292
},
292293
{
293294
"different program",
294-
Issue{State: "closed", StateReason: "completed"},
295+
Issue{State: "closed", StateReason: "completed", Milestone: goplsMilestone},
295296
Info{Program: "other", ProgramVersion: "v0.2.0"},
296297
false,
297298
},
298299
{
299300
"later version",
300-
Issue{State: "closed", StateReason: "completed"},
301+
Issue{State: "closed", StateReason: "completed", Milestone: goplsMilestone},
301302
Info{Program: gopls, ProgramVersion: "v0.3.0"},
302303
true,
303304
},
304305
{
305306
"earlier version",
306-
Issue{State: "closed", StateReason: "completed"},
307+
Issue{State: "closed", StateReason: "completed", Milestone: goplsMilestone},
307308
Info{Program: gopls, ProgramVersion: "v0.1.0"},
308309
false,
309310
},
310311
{
311312
"same version",
312-
Issue{State: "closed", StateReason: "completed"},
313+
Issue{State: "closed", StateReason: "completed", Milestone: goplsMilestone},
313314
Info{Program: gopls, ProgramVersion: "v0.2.0"},
314315
true,
315316
},
317+
{
318+
"compiler later version",
319+
Issue{State: "closed", StateReason: "completed", Milestone: goMilestone},
320+
Info{Program: "cmd/compile", ProgramVersion: "go1.24"},
321+
true,
322+
},
323+
{
324+
"compiler earlier version",
325+
Issue{State: "closed", StateReason: "completed", Milestone: goMilestone},
326+
Info{Program: "cmd/compile", ProgramVersion: "go1.22"},
327+
false,
328+
},
329+
{
330+
"compiler same version",
331+
Issue{State: "closed", StateReason: "completed", Milestone: goMilestone},
332+
Info{Program: "cmd/compile", ProgramVersion: "go1.23"},
333+
true,
334+
},
316335
} {
317336
t.Run(tc.name, func(t *testing.T) {
318337
tc.issue.Number = 1
319-
tc.issue.Milestone = &Milestone{Title: "gopls/" + milestoneVersion}
320338
tc.issue.newStacks = []string{stack}
321339
got := shouldReopen(&tc.issue, map[string]map[Info]int64{stack: map[Info]int64{tc.info: 1}})
322340
if got != tc.want {

0 commit comments

Comments
 (0)