cmd/releasebot: trim pre-release suffix in getMilestone

Pre-release versions like go1.15beta1 use the same milestone
as the release version go1.15, a milestone named "Go1.15".
Handle this in getMilestone by trimming the pre-release suffix.

Also simplify ForeachMilestone error handling. The only error
ForeachMilestone returns is that of fn, which isn't interesting.

For golang/go#39345.

Change-Id: I19ddca7736d97791cc6d7d6986fd39c61db437e2
Reviewed-on: https://go-review.googlesource.com/c/build/+/236259
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
diff --git a/cmd/releasebot/main.go b/cmd/releasebot/main.go
index 51faa50..f9614e1 100644
--- a/cmd/releasebot/main.go
+++ b/cmd/releasebot/main.go
@@ -200,19 +200,24 @@
 // getMilestone returns the GitHub milestone corresponding to the specified version,
 // or an error if it cannot be found.
 func getMilestone(version string) (*maintner.GitHubMilestone, error) {
-	errFoundMilestone := errors.New("found milestone")
+	// Pre-release versions of Go share the same milestone as the
+	// release version, so trim the pre-release suffix, if any.
+	if i := strings.Index(version, "beta"); i != -1 {
+		version = version[:i]
+	} else if i := strings.Index(version, "rc"); i != -1 {
+		version = version[:i]
+	}
+
 	var found *maintner.GitHubMilestone
-	err := goRepo.ForeachMilestone(func(m *maintner.GitHubMilestone) error {
+	goRepo.ForeachMilestone(func(m *maintner.GitHubMilestone) error {
 		if strings.ToLower(m.Title) != version {
 			return nil
 		}
 		found = m
-		return errFoundMilestone
+		return errors.New("stop iteration")
 	})
-	if err == nil {
+	if found == nil {
 		return nil, fmt.Errorf("no milestone found for version %q", version)
-	} else if err != errFoundMilestone {
-		return nil, err
 	}
 	return found, nil
 }