Skip to content

Commit

Permalink
cmd/gopherbot: compare Gerrit users by email only
Browse files Browse the repository at this point in the history
maintner represents Gerrit users via its underlying low-level
git author representation, such as:

	Foo Bar <GerritUserID@GerritServerID>

The server ID represents the Gerrit instance and doesn't change.
The user ID uniquely identifies a Gerrit user on the Gerrit instance.

However, Gerrit is not consistent about the name it uses. Sometimes
it's the actual name, but other times it's "Gerrit User <NumericID>".
For example, both of these forms come up:

	Dmitri Shuralyov <6005@62eb7196-b449-3ce5-99f1-c037f21e1705>
	Gerrit User 6005 <6005@62eb7196-b449-3ce5-99f1-c037f21e1705>

Fix the author comparison logic in unwaitCLs task by comparing only
the git email of Gerrit users.

Fixes golang/go#30172

Change-Id: Ib193de844ecc6212723344765fc920bc08d906a4
Reviewed-on: https://go-review.googlesource.com/c/161977
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
dmitshur committed Feb 14, 2019
1 parent 05a16de commit 5d2b366
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/gopherbot/gopherbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func (b *gopherbot) unwaitCLs(ctx context.Context) error {
// the last time the "wait-author" tag was
// added.
if tags.Contains("wait-author") {
// Figure out othe last index at which "wait-author" was added.
// Figure out the last index at which "wait-author" was added.
waitAuthorIndex := -1
for i := len(cl.Metas) - 1; i >= 0; i-- {
if cl.Metas[i].HashtagsAdded().Contains("wait-author") {
Expand All @@ -1145,17 +1145,17 @@ func (b *gopherbot) unwaitCLs(ctx context.Context) error {
}
}

// Find the author has replied since
author := cl.Metas[0].Commit.Author.Str
// Find out whether the author has replied since.
authorEmail := cl.Metas[0].Commit.Author.Email() // Equivalent to "{{cl.OwnerID}}@62eb7196-b449-3ce5-99f1-c037f21e1705".
hasReplied := false
for _, m := range cl.Metas[waitAuthorIndex+1:] {
if m.Commit.Author.Str == author {
if m.Commit.Author.Email() == authorEmail {
hasReplied = true
break
}
}
if hasReplied {
log.Printf("https://golang.org/cl/%d -- remove wait-author; reply from %s", cl.Number, author)
log.Printf("https://golang.org/cl/%d -- remove wait-author; reply from %s", cl.Number, cl.Owner())
err := b.onLatestCL(ctx, cl, func() error {
if *dryRun {
log.Printf("[dry run] would remove hashtag 'wait-author' from CL %d", cl.Number)
Expand Down
3 changes: 3 additions & 0 deletions maintner/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ func (p *GitPerson) Name() string {
return strings.TrimSpace(p.Str[:i])
}

// String implements fmt.Stringer.
func (p *GitPerson) String() string { return p.Str }

// requires c.mu be held for writing.
func (c *Corpus) enqueueCommitLocked(h GitHash) {
if _, ok := c.gitCommit[h]; ok {
Expand Down

0 comments on commit 5d2b366

Please sign in to comment.