Skip to content

Commit 590a834

Browse files
author
Ivan Palladino
committed
cmd/gopherbot, maintner: add the author of the change to the notification on github
When a new change is pushed, the bot posts a message on Github following this new format: Change https://golang.org/cl/NNNN by AUTHOR mentions this issue A new method to the CL's API in the maintner package is added to provide the related absolute url. Fixes #26816
1 parent a3d123a commit 590a834

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

cmd/gopherbot/gopherbot.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ func (b *gopherbot) closeStaleWaitingForInfo(ctx context.Context) error {
899899

900900
}
901901

902-
// cl2issue writes "Change https://golang.org/cl/NNNN mentions this issue"
902+
// cl2issue writes "Change https://golang.org/cl/NNNN by AUTHOR mentions this issue"
903903
// and the change summary on GitHub when a new Gerrit change references a GitHub issue.
904904
func (b *gopherbot) cl2issue(ctx context.Context) error {
905905
monthAgo := time.Now().Add(-30 * 24 * time.Hour)
@@ -915,6 +915,7 @@ func (b *gopherbot) cl2issue(ctx context.Context) error {
915915
// already processed this issue.
916916
return nil
917917
}
918+
prefix := fmt.Sprintf("Change %s", cl.URL().String())
918919
for _, ref := range cl.GitHubIssueRefs {
919920
if id := ref.Repo.ID(); id.Owner != "golang" || id.Repo != "go" {
920921
continue
@@ -924,17 +925,17 @@ func (b *gopherbot) cl2issue(ctx context.Context) error {
924925
continue
925926
}
926927
hasComment := false
927-
substr := fmt.Sprintf("%d mentions this issue", cl.Number)
928928
gi.ForeachComment(func(c *maintner.GitHubComment) error {
929-
if strings.Contains(c.Body, substr) {
929+
if strings.HasPrefix(c.Body, prefix) {
930930
hasComment = true
931931
return errStopIteration
932932
}
933933
return nil
934934
})
935935
if !hasComment {
936936
printIssue("cl2issue", gi)
937-
msg := fmt.Sprintf("Change https://golang.org/cl/%d mentions this issue: `%s`", cl.Number, cl.Commit.Summary())
937+
author := cl.Owner().Name()
938+
msg := fmt.Sprintf("%s by %s mentions this issue: `%s`", prefix, author, cl.Commit.Summary())
938939
if err := b.addGitHubComment(ctx, "golang", "go", gi.Number, msg); err != nil {
939940
return err
940941
}

maintner/gerrit.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ func (cl *GerritCL) CommitAtVersion(version int32) *GitCommit {
509509
return cl.Project.commit[hash]
510510
}
511511

512+
// URL returns the absolute url of the CL.
513+
func (cl *GerritCL) URL() *url.URL {
514+
s := fmt.Sprintf("https://golang.org/cl/%d", cl.Number)
515+
u, err := url.Parse(s)
516+
if err != nil {
517+
return &url.URL{}
518+
}
519+
return u
520+
}
521+
512522
func (cl *GerritCL) updateGithubIssueRefs() {
513523
gp := cl.Project
514524
gerrit := gp.gerrit

maintner/gerrit_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,20 @@ func TestGerritHashtagsLen(t *testing.T) {
559559
}
560560
}
561561
}
562+
563+
func TestGerritURL(t *testing.T) {
564+
tests := []struct {
565+
set int32
566+
want string
567+
}{
568+
{0, "https://golang.org/cl/0"},
569+
{1238812784, "https://golang.org/cl/1238812784"},
570+
}
571+
for _, tt := range tests {
572+
cl := &GerritCL{Number: tt.set}
573+
got := cl.URL().String()
574+
if got != tt.want {
575+
t.Errorf("For set %d, url = %#v; want %v", tt.set, got, tt.want)
576+
}
577+
}
578+
}

0 commit comments

Comments
 (0)