diff options
author | Unknwon <u@gogs.io> | 2016-08-14 04:17:26 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-14 04:17:26 -0700 |
commit | dccb0c15b996ac4dc0307cbfed140ce1558d7e3c (patch) | |
tree | 97593eae3a1023296c2c03258e6bc4ae4c02b6bf /models/action.go | |
parent | 3f7f4852efaaa56a0dada832dc652a1fc8869ae7 (diff) | |
download | gitea-dccb0c15b996ac4dc0307cbfed140ce1558d7e3c.tar.gz gitea-dccb0c15b996ac4dc0307cbfed140ce1558d7e3c.zip |
Replace convert.To with APIFormat calls
Diffstat (limited to 'models/action.go')
-rw-r--r-- | models/action.go | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/models/action.go b/models/action.go index 584543d9c1..c727c05992 100644 --- a/models/action.go +++ b/models/action.go @@ -246,7 +246,7 @@ type PushCommit struct { type PushCommits struct { Len int Commits []*PushCommit - CompareUrl string + CompareURL string avatars map[string]string } @@ -275,12 +275,12 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit ID: commit.Sha1, Message: commit.Message, URL: fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1), - Author: &api.PayloadAuthor{ + Author: &api.PayloadUser{ Name: commit.AuthorName, Email: commit.AuthorEmail, UserName: authorUsername, }, - Committer: &api.PayloadCommitter{ + Committer: &api.PayloadUser{ Name: commit.CommitterName, Email: commit.CommitterEmail, UserName: committerUsername, @@ -475,7 +475,7 @@ func CommitRepoAction( } else { // if not the first commit, set the compareUrl if !strings.HasPrefix(oldCommitID, "0000000") { - commit.CompareUrl = repo.ComposeCompareURL(oldCommitID, newCommitID) + commit.CompareURL = repo.ComposeCompareURL(oldCommitID, newCommitID) } else { isNewBranch = true } @@ -495,7 +495,6 @@ func CommitRepoAction( } refName := git.RefEndName(refFullName) - if err = NotifyWatchers(&Action{ ActUserID: u.ID, ActUserName: userName, @@ -511,35 +510,24 @@ func CommitRepoAction( return fmt.Errorf("NotifyWatchers: %v", err) } - payloadRepo := repo.ComposePayload() - - var pusherEmail, pusherName string pusher, err := GetUserByName(userName) - if err == nil { - pusherEmail = pusher.Email - pusherName = pusher.DisplayName() - } - payloadSender := &api.PayloadUser{ - UserName: pusher.Name, - ID: pusher.ID, - AvatarUrl: pusher.AvatarLink(), + if err != nil { + return fmt.Errorf("GetUserByName: %v", err) } + apiPusher := pusher.APIFormat() + apiRepo := repo.APIFormat(nil) switch opType { case ACTION_COMMIT_REPO: // Push if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{ Ref: refFullName, Before: oldCommitID, After: newCommitID, - CompareUrl: setting.AppUrl + commit.CompareUrl, + CompareURL: setting.AppUrl + commit.CompareURL, Commits: commit.ToApiPayloadCommits(repo.FullLink()), - Repo: payloadRepo, - Pusher: &api.PayloadAuthor{ - Name: pusherName, - Email: pusherEmail, - UserName: userName, - }, - Sender: payloadSender, + Repo: apiRepo, + Pusher: apiPusher, + Sender: apiPusher, }); err != nil { return fmt.Errorf("PrepareWebhooks: %v", err) } @@ -548,8 +536,8 @@ func CommitRepoAction( return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{ Ref: refName, RefType: "branch", - Repo: payloadRepo, - Sender: payloadSender, + Repo: apiRepo, + Sender: apiPusher, }) } @@ -557,8 +545,8 @@ func CommitRepoAction( return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{ Ref: refName, RefType: "tag", - Repo: payloadRepo, - Sender: payloadSender, + Repo: apiRepo, + Sender: apiPusher, }) } |