]> source.dussan.org Git - gitea.git/commitdiff
clarify name/username/owner/pusher for webhook
authorChristopher Brickley <brickley@gmail.com>
Wed, 17 Sep 2014 13:11:51 +0000 (09:11 -0400)
committerChristopher Brickley <brickley@gmail.com>
Wed, 17 Sep 2014 13:20:14 +0000 (09:20 -0400)
models/action.go
models/user.go
models/webhook.go

index 295a61ccdb2eaa5b8f30dd8db12e7d9c852769b2..a6b22b161d70b9fa84f11931e98cabb5ceab5075 100644 (file)
@@ -243,15 +243,29 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
        if !strings.HasPrefix(oldCommitId, "0000000") {
                compareUrl = fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId)
        }
+
+       pusher_email, pusher_name := "", ""
+       pusher, err := GetUserByName(userName)
+       if err == nil {
+               pusher_email = pusher.Email
+               pusher_name = pusher.GetFullNameFallback()
+       }
+
        commits := make([]*PayloadCommit, len(commit.Commits))
        for i, cmt := range commit.Commits {
+               author_username := ""
+               author, err := GetUserByEmail(cmt.AuthorEmail)
+               if err == nil {
+                       author_username = author.Name
+               }
                commits[i] = &PayloadCommit{
                        Id:      cmt.Sha1,
                        Message: cmt.Message,
                        Url:     fmt.Sprintf("%s/commit/%s", repoLink, cmt.Sha1),
                        Author: &PayloadAuthor{
-                               Name:  cmt.AuthorName,
-                               Email: cmt.AuthorEmail,
+                               Name:     cmt.AuthorName,
+                               Email:    cmt.AuthorEmail,
+                               UserName: author_username,
                        },
                }
        }
@@ -266,14 +280,16 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
                        Website:     repo.Website,
                        Watchers:    repo.NumWatches,
                        Owner: &PayloadAuthor{
-                               Name:  repoUserName,
-                               Email: actEmail,
+                               Name:     repo.Owner.GetFullNameFallback(),
+                               Email:    repo.Owner.Email,
+                               UserName: repo.Owner.Name,
                        },
                        Private: repo.IsPrivate,
                },
                Pusher: &PayloadAuthor{
-                       Name:  repo.Owner.LowerName,
-                       Email: repo.Owner.Email,
+                       Name:     pusher_name,
+                       Email:    pusher_email,
+                       UserName: userName,
                },
                Before:     oldCommitId,
                After:      newCommitId,
index 96881ea355444eea403410386459b29ab8ac0c02..b3ea816177b0099aaaad3e18d7aca7cae2c2a018 100644 (file)
@@ -167,6 +167,14 @@ func (u *User) GetOrganizations() error {
        return nil
 }
 
+// GetFullNameFallback returns Full Name if set, otherwise username
+func (u *User) GetFullNameFallback() string {
+       if u.FullName == "" {
+               return u.Name
+       }
+       return u.FullName
+}
+
 // IsUserExist checks if given user name exist,
 // the user name should be noncased unique.
 func IsUserExist(name string) (bool, error) {
index 3c07cc81797d7ed16bd1134c2da767aec3b0faae..9508c98a5e68f1dff44e9ea1979ec56c3c97d517 100644 (file)
@@ -154,8 +154,9 @@ const (
 )
 
 type PayloadAuthor struct {
-       Name  string `json:"name"`
-       Email string `json:"email"`
+       Name     string `json:"name"`
+       Email    string `json:"email"`
+       UserName string `json:"username"`
 }
 
 type PayloadCommit struct {
@@ -172,7 +173,7 @@ type PayloadRepo struct {
        Description string         `json:"description"`
        Website     string         `json:"website"`
        Watchers    int            `json:"watchers"`
-       Owner       *PayloadAuthor `json:"author"`
+       Owner       *PayloadAuthor `json:"owner"`
        Private     bool           `json:"private"`
 }