Add committer information to API and Webhooks. Also fixes #3271 (#3414)

This commit is contained in:
lstahlman 2016-08-09 22:01:57 -07:00 committed by 无闻
parent c5d4a9e046
commit 89f71b44f7
4 changed files with 48 additions and 13 deletions

View File

@ -238,6 +238,8 @@ type PushCommit struct {
Message string Message string
AuthorEmail string AuthorEmail string
AuthorName string AuthorName string
CommitterEmail string
CommitterName string
Timestamp time.Time Timestamp time.Time
} }
@ -263,6 +265,12 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
if err == nil { if err == nil {
authorUsername = author.Name authorUsername = author.Name
} }
committerUsername := ""
committer, err := GetUserByEmail(commit.CommitterEmail)
if err == nil {
// TODO: check errors other than email not found.
committerUsername = committer.Name
}
commits[i] = &api.PayloadCommit{ commits[i] = &api.PayloadCommit{
ID: commit.Sha1, ID: commit.Sha1,
Message: commit.Message, Message: commit.Message,
@ -272,6 +280,11 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
Email: commit.AuthorEmail, Email: commit.AuthorEmail,
UserName: authorUsername, UserName: authorUsername,
}, },
Committer: &api.PayloadCommitter{
Name: commit.CommitterName,
Email: commit.CommitterEmail,
UserName: committerUsername,
},
Timestamp: commit.Timestamp, Timestamp: commit.Timestamp,
} }
} }

View File

@ -61,6 +61,8 @@ func ListToPushCommits(l *list.List) *PushCommits {
Message: commit.Message(), Message: commit.Message(),
AuthorEmail: commit.Author.Email, AuthorEmail: commit.Author.Email,
AuthorName: commit.Author.Name, AuthorName: commit.Author.Name,
CommitterEmail: commit.Committer.Email,
CommitterName: commit.Committer.Name,
Timestamp: commit.Author.When, Timestamp: commit.Author.When,
}) })
} }

View File

@ -69,15 +69,31 @@ func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
} }
func ToCommit(c *git.Commit) *api.PayloadCommit { func ToCommit(c *git.Commit) *api.PayloadCommit {
authorUsername := ""
author, err := models.GetUserByEmail(c.Author.Email)
if err == nil {
authorUsername = author.Name
}
committerUsername := ""
committer, err := models.GetUserByEmail(c.Committer.Email)
if err == nil {
committerUsername = committer.Name
}
return &api.PayloadCommit{ return &api.PayloadCommit{
ID: c.ID.String(), ID: c.ID.String(),
Message: c.Message(), Message: c.Message(),
URL: "Not implemented", URL: "Not implemented",
Author: &api.PayloadAuthor{ Author: &api.PayloadAuthor{
Name: c.Author.Name,
Email: c.Author.Email,
UserName: authorUsername,
},
Committer: &api.PayloadCommitter{
Name: c.Committer.Name, Name: c.Committer.Name,
Email: c.Committer.Email, Email: c.Committer.Email,
/* UserName: c.Committer.UserName, */ UserName: committerUsername,
}, },
Timestamp: c.Author.When,
} }
} }

View File

@ -359,6 +359,10 @@ func TestWebhook(ctx *context.Context) {
Name: ctx.Repo.Commit.Author.Name, Name: ctx.Repo.Commit.Author.Name,
Email: ctx.Repo.Commit.Author.Email, Email: ctx.Repo.Commit.Author.Email,
}, },
Committer: &api.PayloadCommitter{
Name: ctx.Repo.Commit.Committer.Name,
Email: ctx.Repo.Commit.Committer.Email,
},
}, },
}, },
Repo: ctx.Repo.Repository.ComposePayload(), Repo: ctx.Repo.Repository.ComposePayload(),