Add repo info to web hook post

tokarchuk/v1.17
Unknown 11 years ago
parent 495d939ca5
commit 23a857d107
  1. 2
      gogs.go
  2. 24
      models/action.go
  3. 5
      models/repo.go
  4. 12
      modules/hooks/hooks.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
) )
const APP_VER = "0.3.3.0507 Alpha" const APP_VER = "0.3.3.0508 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

@ -114,6 +114,10 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName) qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName)
// New push event hook. // New push event hook.
if err := repo.GetOwner(); err != nil {
return errors.New("action.CommitRepoAction(GetOwner): " + err.Error())
}
ws, err := GetActiveWebhooksByRepoId(repoId) ws, err := GetActiveWebhooksByRepoId(repoId)
if err != nil { if err != nil {
return errors.New("action.CommitRepoAction(GetWebhooksByRepoId): " + err.Error()) return errors.New("action.CommitRepoAction(GetWebhooksByRepoId): " + err.Error())
@ -121,12 +125,13 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
return nil return nil
} }
repoLink := fmt.Sprintf("%s%s/%s", base.AppUrl, repoUserName, repoName)
commits := make([]*hooks.PayloadCommit, len(commit.Commits)) commits := make([]*hooks.PayloadCommit, len(commit.Commits))
for i, cmt := range commit.Commits { for i, cmt := range commit.Commits {
commits[i] = &hooks.PayloadCommit{ commits[i] = &hooks.PayloadCommit{
Id: cmt.Sha1, Id: cmt.Sha1,
Message: cmt.Message, 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{ Author: &hooks.PayloadAuthor{
Name: cmt.AuthorName, Name: cmt.AuthorName,
Email: cmt.AuthorEmail, Email: cmt.AuthorEmail,
@ -136,10 +141,23 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
p := &hooks.Payload{ p := &hooks.Payload{
Ref: refFullName, Ref: refFullName,
Commits: commits, Commits: commits,
Pusher: &hooks.PayloadAuthor{ Repo: &hooks.PayloadRepo{
Name: userName, Id: repo.Id,
Name: repo.LowerName,
Url: repoLink,
Description: repo.Description,
Website: repo.Website,
Watchers: repo.NumWatches,
Owner: &hooks.PayloadAuthor{
Name: repoUserName,
Email: actEmail, Email: actEmail,
}, },
Private: repo.IsPrivate,
},
Pusher: &hooks.PayloadAuthor{
Name: repo.Owner.LowerName,
Email: repo.Owner.Email,
},
} }
for _, w := range ws { for _, w := range ws {

@ -88,6 +88,11 @@ type Repository struct {
Updated time.Time `xorm:"updated"` 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. // IsRepositoryExist returns true if the repository with given name under user has already existed.
func IsRepositoryExist(user *User, repoName string) (bool, error) { func IsRepositoryExist(user *User, repoName string) (bool, error) {
repo := Repository{OwnerId: user.Id} repo := Repository{OwnerId: user.Id}

@ -30,11 +30,23 @@ type PayloadCommit struct {
Author *PayloadAuthor `json:"author"` 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. // Payload represents payload information of hook.
type Payload struct { type Payload struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Ref string `json:"ref"` Ref string `json:"ref"`
Commits []*PayloadCommit `json:"commits"` Commits []*PayloadCommit `json:"commits"`
Repo *PayloadRepo `json:"repository"`
Pusher *PayloadAuthor `json:"pusher"` Pusher *PayloadAuthor `json:"pusher"`
} }

Loading…
Cancel
Save