Browse Source

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

for-closed-social
lstahlman 8 years ago
committed by 无闻
parent
commit
89f71b44f7
4 changed files with 48 additions and 13 deletions
  1. +18
    -5
      models/action.go
  2. +7
    -5
      models/update.go
  3. +19
    -3
      routers/api/v1/convert/convert.go
  4. +4
    -0
      routers/repo/webhook.go

+ 18
- 5
models/action.go View File

@ -234,11 +234,13 @@ func issueIndexTrimRight(c rune) bool {
}
type PushCommit struct {
Sha1 string
Message string
AuthorEmail string
AuthorName string
Timestamp time.Time
Sha1 string
Message string
AuthorEmail string
AuthorName string
CommitterEmail string
CommitterName string
Timestamp time.Time
}
type PushCommits struct {
@ -263,6 +265,12 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
if err == nil {
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{
ID: commit.Sha1,
Message: commit.Message,
@ -272,6 +280,11 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
Email: commit.AuthorEmail,
UserName: authorUsername,
},
Committer: &api.PayloadCommitter{
Name: commit.CommitterName,
Email: commit.CommitterEmail,
UserName: committerUsername,
},
Timestamp: commit.Timestamp,
}
}

+ 7
- 5
models/update.go View File

@ -57,11 +57,13 @@ func ListToPushCommits(l *list.List) *PushCommits {
}
commits = append(commits,
&PushCommit{
Sha1: commit.ID.String(),
Message: commit.Message(),
AuthorEmail: commit.Author.Email,
AuthorName: commit.Author.Name,
Timestamp: commit.Author.When,
Sha1: commit.ID.String(),
Message: commit.Message(),
AuthorEmail: commit.Author.Email,
AuthorName: commit.Author.Name,
CommitterEmail: commit.Committer.Email,
CommitterName: commit.Committer.Name,
Timestamp: commit.Author.When,
})
}
return &PushCommits{l.Len(), commits, "", nil}

+ 19
- 3
routers/api/v1/convert/convert.go View File

@ -69,15 +69,31 @@ func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
}
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{
ID: c.ID.String(),
Message: c.Message(),
URL: "Not implemented",
Author: &api.PayloadAuthor{
Name: c.Committer.Name,
Email: c.Committer.Email,
/* UserName: c.Committer.UserName, */
Name: c.Author.Name,
Email: c.Author.Email,
UserName: authorUsername,
},
Committer: &api.PayloadCommitter{
Name: c.Committer.Name,
Email: c.Committer.Email,
UserName: committerUsername,
},
Timestamp: c.Author.When,
}
}

+ 4
- 0
routers/repo/webhook.go View File

@ -359,6 +359,10 @@ func TestWebhook(ctx *context.Context) {
Name: ctx.Repo.Commit.Author.Name,
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(),

Loading…
Cancel
Save