cmd/gopherbot: compare Gerrit users by email only

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 <bradfitz@golang.org>
This commit is contained in:
Dmitri Shuralyov 2019-02-11 13:39:17 -05:00
Родитель 05a16dea4c
Коммит 5d2b36639e
2 изменённых файлов: 8 добавлений и 5 удалений

Просмотреть файл

@ -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") {
@ -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)

Просмотреть файл

@ -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 {