Browse Source

webhook: fix organizational webhook last delivery status cannot be updated

pull/3854/merge
Unknwon 8 years ago
parent
commit
5ea0592f61
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 15
      models/webhook.go
  2. 2
      routers/api/v1/repo/hook.go

15
models/webhook.go

@ -197,6 +197,15 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
return bean, nil return bean, nil
} }
// GetWebhookByID returns webhook by given ID.
// Use this function with caution of accessing unauthorized webhook,
// which means should only be used in non-user interactive functions.
func GetWebhookByID(id int64) (*Webhook, error) {
return getWebhook(&Webhook{
ID: id,
})
}
// GetWebhookOfRepoByID returns webhook of repository by given ID. // GetWebhookOfRepoByID returns webhook of repository by given ID.
func GetWebhookOfRepoByID(repoID, id int64) (*Webhook, error) { func GetWebhookOfRepoByID(repoID, id int64) (*Webhook, error) {
return getWebhook(&Webhook{ return getWebhook(&Webhook{
@ -557,9 +566,9 @@ func (t *HookTask) deliver() {
} }
// Update webhook last delivery status. // Update webhook last delivery status.
w, err := GetWebhookOfRepoByID(t.RepoID, t.HookID) w, err := GetWebhookByID(t.HookID)
if err != nil { if err != nil {
log.Error(5, "GetWebhookByID: %v", err) log.Error(3, "GetWebhookByID: %v", err)
return return
} }
if t.IsSucceed { if t.IsSucceed {
@ -568,7 +577,7 @@ func (t *HookTask) deliver() {
w.LastStatus = HOOK_STATUS_FAILED w.LastStatus = HOOK_STATUS_FAILED
} }
if err = UpdateWebhook(w); err != nil { if err = UpdateWebhook(w); err != nil {
log.Error(5, "UpdateWebhook: %v", err) log.Error(3, "UpdateWebhook: %v", err)
return return
} }
}() }()

2
routers/api/v1/repo/hook.go

@ -104,7 +104,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.Status(404)
} else { } else {
ctx.Error(500, "GetWebhookByID", err) ctx.Error(500, "GetWebhookOfRepoByID", err)
} }
return return
} }

Loading…
Cancel
Save