1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-22 17:34:03 +03:00

#3274 fix can't get webhook detail of organization

This commit is contained in:
Unknwon 2016-07-16 01:02:55 +08:00
parent fff615d5fc
commit 3d93532c87
5 changed files with 26 additions and 9 deletions

View File

@ -174,8 +174,8 @@ func CreateWebhook(w *Webhook) error {
return err return err
} }
// GetWebhookByID returns webhook of repository by given ID. // GetWebhookByRepoID returns webhook of repository by given ID.
func GetWebhookByID(repoID, id int64) (*Webhook, error) { func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) {
w := new(Webhook) w := new(Webhook)
has, err := x.Id(id).And("repo_id=?", repoID).Get(w) has, err := x.Id(id).And("repo_id=?", repoID).Get(w)
if err != nil { if err != nil {
@ -186,6 +186,18 @@ func GetWebhookByID(repoID, id int64) (*Webhook, error) {
return w, nil return w, nil
} }
// GetWebhookByOrgID returns webhook of organization by given ID.
func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) {
w := new(Webhook)
has, err := x.Id(id).And("org_id=?", orgID).Get(w)
if err != nil {
return nil, err
} else if !has {
return nil, ErrWebhookNotExist{id}
}
return w, nil
}
// GetActiveWebhooksByRepoID returns all active webhooks of repository. // GetActiveWebhooksByRepoID returns all active webhooks of repository.
func GetActiveWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) { func GetActiveWebhooksByRepoID(repoID int64) (ws []*Webhook, err error) {
err = x.Where("repo_id=?", repoID).And("is_active=?", true).Find(&ws) err = x.Where("repo_id=?", repoID).And("is_active=?", true).Find(&ws)
@ -221,8 +233,8 @@ func DeleteWebhook(id int64) (err error) {
return sess.Commit() return sess.Commit()
} }
// GetWebhooksByOrgId returns all webhooks for an organization. // GetWebhooksByOrgID returns all webhooks for an organization.
func GetWebhooksByOrgId(orgID int64) (ws []*Webhook, err error) { func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
err = x.Find(&ws, &Webhook{OrgID: orgID}) err = x.Find(&ws, &Webhook{OrgID: orgID})
return ws, err return ws, err
} }
@ -548,7 +560,7 @@ func (t *HookTask) deliver() {
} }
// Update webhook last delivery status. // Update webhook last delivery status.
w, err := GetWebhookByID(t.RepoID, t.HookID) w, err := GetWebhookByRepoID(t.RepoID, t.HookID)
if err != nil { if err != nil {
log.Error(5, "GetWebhookByID: %v", err) log.Error(5, "GetWebhookByID: %v", err)
return return

View File

@ -98,7 +98,7 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook // https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
func EditHook(ctx *context.APIContext, form api.EditHookOption) { func EditHook(ctx *context.APIContext, form api.EditHookOption) {
w, err := models.GetWebhookByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) w, err := models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.Status(404)

View File

@ -154,7 +154,7 @@ func Webhooks(ctx *context.Context) {
return return
} }
ws, err := models.GetWebhooksByOrgId(ctx.Org.Organization.Id) ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.Id)
if err != nil { if err != nil {
ctx.Handle(500, "GetWebhooksByOrgId", err) ctx.Handle(500, "GetWebhooksByOrgId", err)
return return

View File

@ -220,7 +220,12 @@ func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
} }
ctx.Data["BaseLink"] = orCtx.Link ctx.Data["BaseLink"] = orCtx.Link
w, err := models.GetWebhookByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) var w *models.Webhook
if orCtx.RepoID > 0 {
w, err = models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
} else {
w, err = models.GetWebhookByOrgID(ctx.Org.Organization.Id, ctx.ParamsInt64(":id"))
}
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Handle(404, "GetWebhookByID", nil) ctx.Handle(404, "GetWebhookByID", nil)

View File

@ -9,7 +9,7 @@
<div class="ui secondary menu"> <div class="ui secondary menu">
{{if .PullRequestCtx.Allowed}} {{if .PullRequestCtx.Allowed}}
<div class="fitted item"> <div class="fitted item">
<a href="{{.BaseRepo.RepoLink}}/compare/{{.BaseRepo.DefaultBranch}}...{{.PullRequestCtx.HeadInfo}}"> <a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch}}...{{.PullRequestCtx.HeadInfo}}">
<button class="ui green small button"><i class="octicon octicon-git-compare"></i></button> <button class="ui green small button"><i class="octicon octicon-git-compare"></i></button>
</a> </a>
</div> </div>