summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlstahlman <lstahlman@users.noreply.github.com>2016-08-09 22:01:57 -0700
committer无闻 <u@gogs.io>2016-08-09 22:01:57 -0700
commit89f71b44f7e15c044ace56b4201b3e278947e91d (patch)
tree3b4d20b6176c755dd384f9b4c0101fc8301d76c1
parentc5d4a9e046045f949ec9606b49dc37b928e83fb3 (diff)
downloadgitea-89f71b44f7e15c044ace56b4201b3e278947e91d.tar.gz
gitea-89f71b44f7e15c044ace56b4201b3e278947e91d.zip
Add committer information to API and Webhooks. Also fixes #3271 (#3414)
-rw-r--r--models/action.go23
-rw-r--r--models/update.go12
-rw-r--r--routers/api/v1/convert/convert.go22
-rw-r--r--routers/repo/webhook.go4
4 files changed, 48 insertions, 13 deletions
diff --git a/models/action.go b/models/action.go
index 4f57d1b3b5..5bfa5b75b2 100644
--- a/models/action.go
+++ b/models/action.go
@@ -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,
}
}
diff --git a/models/update.go b/models/update.go
index 9b2078c986..be50a15e5a 100644
--- a/models/update.go
+++ b/models/update.go
@@ -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}
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go
index 0dc73fcd67..cda1d86b45 100644
--- a/routers/api/v1/convert/convert.go
+++ b/routers/api/v1/convert/convert.go
@@ -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,
}
}
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go
index 715c6a4c72..8b0153e689 100644
--- a/routers/repo/webhook.go
+++ b/routers/repo/webhook.go
@@ -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(),