From 23a857d107b06b5639b337aba2e335d3d66ef9db Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 May 2014 08:18:03 -0400 Subject: [PATCH] Add repo info to web hook post --- gogs.go | 2 +- models/action.go | 24 +++++++++++++++++++++--- models/repo.go | 5 +++++ modules/hooks/hooks.go | 12 ++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gogs.go b/gogs.go index df1062e0eb..3d6b4807a6 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/base" ) -const APP_VER = "0.3.3.0507 Alpha" +const APP_VER = "0.3.3.0508 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/action.go b/models/action.go index ef9e260a0b..02639e5538 100644 --- a/models/action.go +++ b/models/action.go @@ -114,6 +114,10 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName) // New push event hook. + if err := repo.GetOwner(); err != nil { + return errors.New("action.CommitRepoAction(GetOwner): " + err.Error()) + } + ws, err := GetActiveWebhooksByRepoId(repoId) if err != nil { return errors.New("action.CommitRepoAction(GetWebhooksByRepoId): " + err.Error()) @@ -121,12 +125,13 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, return nil } + repoLink := fmt.Sprintf("%s%s/%s", base.AppUrl, repoUserName, repoName) commits := make([]*hooks.PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { commits[i] = &hooks.PayloadCommit{ Id: cmt.Sha1, Message: cmt.Message, - Url: fmt.Sprintf("%s%s/%s/commit/%s", base.AppUrl, repoUserName, repoName, cmt.Sha1), + Url: fmt.Sprintf("%s/commit/%s", repoLink, cmt.Sha1), Author: &hooks.PayloadAuthor{ Name: cmt.AuthorName, Email: cmt.AuthorEmail, @@ -136,9 +141,22 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, p := &hooks.Payload{ Ref: refFullName, Commits: commits, + Repo: &hooks.PayloadRepo{ + Id: repo.Id, + Name: repo.LowerName, + Url: repoLink, + Description: repo.Description, + Website: repo.Website, + Watchers: repo.NumWatches, + Owner: &hooks.PayloadAuthor{ + Name: repoUserName, + Email: actEmail, + }, + Private: repo.IsPrivate, + }, Pusher: &hooks.PayloadAuthor{ - Name: userName, - Email: actEmail, + Name: repo.Owner.LowerName, + Email: repo.Owner.Email, }, } diff --git a/models/repo.go b/models/repo.go index 0ca32bc28b..595d79b5c3 100644 --- a/models/repo.go +++ b/models/repo.go @@ -88,6 +88,11 @@ type Repository struct { Updated time.Time `xorm:"updated"` } +func (repo *Repository) GetOwner() (err error) { + repo.Owner, err = GetUserById(repo.OwnerId) + return err +} + // IsRepositoryExist returns true if the repository with given name under user has already existed. func IsRepositoryExist(user *User, repoName string) (bool, error) { repo := Repository{OwnerId: user.Id} diff --git a/modules/hooks/hooks.go b/modules/hooks/hooks.go index a3a59454e2..6ae4418b35 100644 --- a/modules/hooks/hooks.go +++ b/modules/hooks/hooks.go @@ -30,11 +30,23 @@ type PayloadCommit struct { Author *PayloadAuthor `json:"author"` } +type PayloadRepo struct { + Id int64 `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Description string `json:"description"` + Website string `json:"website"` + Watchers int `json:"watchers"` + Owner *PayloadAuthor `json:"author"` + Private bool `json:"private"` +} + // Payload represents payload information of hook. type Payload struct { Secret string `json:"secret"` Ref string `json:"ref"` Commits []*PayloadCommit `json:"commits"` + Repo *PayloadRepo `json:"repository"` Pusher *PayloadAuthor `json:"pusher"` }