From 5ea0592f61f85a8a3a63326661dd31da4dd12369 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 22 Feb 2017 22:55:28 -0500 Subject: [PATCH] webhook: fix organizational webhook last delivery status cannot be updated --- models/webhook.go | 15 ++++++++++++--- routers/api/v1/repo/hook.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/models/webhook.go b/models/webhook.go index 58c1b88d2..1dcfb8b82 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -197,6 +197,15 @@ func getWebhook(bean *Webhook) (*Webhook, error) { 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. func GetWebhookOfRepoByID(repoID, id int64) (*Webhook, error) { return getWebhook(&Webhook{ @@ -557,9 +566,9 @@ func (t *HookTask) deliver() { } // Update webhook last delivery status. - w, err := GetWebhookOfRepoByID(t.RepoID, t.HookID) + w, err := GetWebhookByID(t.HookID) if err != nil { - log.Error(5, "GetWebhookByID: %v", err) + log.Error(3, "GetWebhookByID: %v", err) return } if t.IsSucceed { @@ -568,7 +577,7 @@ func (t *HookTask) deliver() { w.LastStatus = HOOK_STATUS_FAILED } if err = UpdateWebhook(w); err != nil { - log.Error(5, "UpdateWebhook: %v", err) + log.Error(3, "UpdateWebhook: %v", err) return } }() diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index fa66fe471..466d3625c 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -104,7 +104,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) { if models.IsErrWebhookNotExist(err) { ctx.Status(404) } else { - ctx.Error(500, "GetWebhookByID", err) + ctx.Error(500, "GetWebhookOfRepoByID", err) } return }