diff --git a/maintner/gerrit.go b/maintner/gerrit.go index 69e77eea..c906ae1b 100644 --- a/maintner/gerrit.go +++ b/maintner/gerrit.go @@ -298,6 +298,7 @@ type GerritCL struct { Private bool // GitHubIssueRefs are parsed references to GitHub issues. + // Multiple references to the same issue are deduplicated. GitHubIssueRefs []GitHubIssueRef // Messages contains all of the messages for this CL, in sorted order. diff --git a/maintner/github.go b/maintner/github.go index 33960ae9..8eb7858e 100644 --- a/maintner/github.go +++ b/maintner/github.go @@ -2155,6 +2155,8 @@ func makeGithubResponse(res *http.Response) *github.Response { var rxReferences = regexp.MustCompile(`(?:\b([\w\-]+)/([\w\-]+))?\#(\d+)\b`) +// parseGithubRefs parses references to GitHub issues from commit message commitMsg. +// Multiple references to the same issue are deduplicated. func (c *Corpus) parseGithubRefs(gerritProj string, commitMsg string) []GitHubIssueRef { // Use of rxReferences by itself caused this function to take 20% of the CPU time. // TODO(bradfitz): stop using regexps here. @@ -2203,12 +2205,25 @@ func (c *Corpus) parseGithubRefs(gerritProj string, commitMsg string) []GitHubIs continue } } - gr := github.getOrCreateRepo(owner, repo) - refs = append(refs, GitHubIssueRef{gr, int32(num)}) + ref := GitHubIssueRef{github.getOrCreateRepo(owner, repo), int32(num)} + if contains(refs, ref) { + continue + } + refs = append(refs, ref) } return refs } +// contains reports whether refs contains the reference ref. +func contains(refs []GitHubIssueRef, ref GitHubIssueRef) bool { + for _, r := range refs { + if r == ref { + return true + } + } + return false +} + type limitTransport struct { limiter *rate.Limiter base http.RoundTripper diff --git a/maintner/github_test.go b/maintner/github_test.go index d8f6213e..35f73172 100644 --- a/maintner/github_test.go +++ b/maintner/github_test.go @@ -573,6 +573,8 @@ func TestParseGithubRefs(t *testing.T) { {"go.googlesource.com/go", "Fixes golang/go#1234", []string{"golang/go#1234"}}, {"go.googlesource.com/go", "Fixes golang/go#1234\n", []string{"golang/go#1234"}}, {"go.googlesource.com/go", "Fixes golang/go#1234.", []string{"golang/go#1234"}}, + {"go.googlesource.com/go", "Mention issue #1234 a second time.\n\nFixes #1234.", []string{"golang/go#1234"}}, + {"go.googlesource.com/go", "Mention issue #1234 a second time.\n\nFixes #1234.\nUpdates #1235.", []string{"golang/go#1234", "golang/go#1235"}}, {"go.googlesource.com/net", "Fixes golang/go#1234.", []string{"golang/go#1234"}}, {"go.googlesource.com/net", "Fixes #1234", nil}, }