diff options
author | Unknwon <u@gogs.io> | 2015-12-05 13:24:13 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-05 13:24:13 -0500 |
commit | 404867f206f97ec4ea2e6032fea47bc0499d3497 (patch) | |
tree | b37be9387d2a00cd2447e65a1367bb292c6c0a09 /models | |
parent | f0ee33267c453cc7f77a87a2b4b784febbb604dd (diff) | |
download | gitea-404867f206f97ec4ea2e6032fea47bc0499d3497.tar.gz gitea-404867f206f97ec4ea2e6032fea47bc0499d3497.zip |
fix #2105 and fix #1857
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 19 | ||||
-rw-r--r-- | models/repo.go | 22 | ||||
-rw-r--r-- | models/webhook.go | 12 |
3 files changed, 30 insertions, 23 deletions
diff --git a/models/action.go b/models/action.go index 8dd80074bd..c54b180bc2 100644 --- a/models/action.go +++ b/models/action.go @@ -451,24 +451,9 @@ func CommitRepoAction( IsPrivate: repo.IsPrivate, }); err != nil { return fmt.Errorf("NotifyWatchers: %v", err) - } - repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) - payloadRepo := &api.PayloadRepo{ - ID: repo.ID, - Name: repo.LowerName, - URL: repoLink, - Description: repo.Description, - Website: repo.Website, - Watchers: repo.NumWatches, - Owner: &api.PayloadAuthor{ - Name: repo.Owner.DisplayName(), - Email: repo.Owner.Email, - UserName: repo.Owner.Name, - }, - Private: repo.IsPrivate, - } + payloadRepo := repo.ComposePayload() pusher_email, pusher_name := "", "" pusher, err := GetUserByName(userName) @@ -494,7 +479,7 @@ func CommitRepoAction( commits[i] = &api.PayloadCommit{ ID: cmt.Sha1, Message: cmt.Message, - URL: fmt.Sprintf("%s/commit/%s", repoLink, cmt.Sha1), + URL: fmt.Sprintf("%s/commit/%s", repo.RepoLink(), cmt.Sha1), Author: &api.PayloadAuthor{ Name: cmt.AuthorName, Email: cmt.AuthorEmail, diff --git a/models/repo.go b/models/repo.go index a3417ef308..5b66d2c0be 100644 --- a/models/repo.go +++ b/models/repo.go @@ -28,6 +28,7 @@ import ( "gopkg.in/ini.v1" "github.com/gogits/git-shell" + api "github.com/gogits/go-gogs-client" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/bindata" @@ -380,6 +381,27 @@ func (repo *Repository) SavePatch(index int64, patch []byte) error { return nil } +// ComposePayload composes and returns *api.PayloadRepo corresponding to the repository. +func (repo *Repository) ComposePayload() *api.PayloadRepo { + cl := repo.CloneLink() + return &api.PayloadRepo{ + ID: repo.ID, + Name: repo.LowerName, + URL: repo.RepoLink(), + SSHURL: cl.SSH, + CloneURL: cl.HTTPS, + Description: repo.Description, + Website: repo.Website, + Watchers: repo.NumWatches, + Owner: &api.PayloadAuthor{ + Name: repo.MustOwner().DisplayName(), + Email: repo.MustOwner().Email, + UserName: repo.MustOwner().Name, + }, + Private: repo.IsPrivate, + } +} + func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) { has, err := e.Get(&Repository{ OwnerID: u.Id, diff --git a/models/webhook.go b/models/webhook.go index cbc874a9ce..6d451f4eb6 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -335,7 +335,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { t.ResponseInfo = &HookResponse{} if err = json.Unmarshal([]byte(t.ResponseContent), t.ResponseInfo); err != nil { - log.Error(3, "Unmarshal[%d]: %v", t.ID, err) + log.Error(3, "Unmarshal [%d]: %v", t.ID, err) } } } @@ -343,7 +343,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { func (t *HookTask) MarshalJSON(v interface{}) string { p, err := json.Marshal(v) if err != nil { - log.Error(3, "Marshal[%d]: %v", t.ID, err) + log.Error(3, "Marshal [%d]: %v", t.ID, err) } return string(p) } @@ -590,24 +590,24 @@ func DeliverHooks() { // Update hook task status. for _, t := range tasks { if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask(%d): %v", t.ID, err) + log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) } } // Start listening on new hook requests. for repoID := range HookQueue.Queue() { - log.Trace("DeliverHooks[%v]: processing delivery hooks", repoID) + log.Trace("DeliverHooks [%v]: processing delivery hooks", repoID) HookQueue.Remove(repoID) tasks = make([]*HookTask, 0, 5) if err := x.Where("repo_id=? AND is_delivered=?", repoID, false).Find(&tasks); err != nil { - log.Error(4, "Get repository(%d) hook tasks: %v", repoID, err) + log.Error(4, "Get repository [%d] hook tasks: %v", repoID, err) continue } for _, t := range tasks { t.deliver() if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask[%d]: %v", t.ID, err) + log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) continue } } |