Skip to content

Commit 04ec795

Browse files
authored
fix orgnization webhooks (#2422)
* fix org webhooks * remove trace code
1 parent 5de94a6 commit 04ec795

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

models/webhook.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
221221
return bean, nil
222222
}
223223

224+
// GetWebhookByID returns webhook of repository by given ID.
225+
func GetWebhookByID(id int64) (*Webhook, error) {
226+
return getWebhook(&Webhook{
227+
ID: id,
228+
})
229+
}
230+
224231
// GetWebhookByRepoID returns webhook of repository by given ID.
225232
func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) {
226233
return getWebhook(&Webhook{
@@ -271,6 +278,12 @@ func UpdateWebhook(w *Webhook) error {
271278
return err
272279
}
273280

281+
// UpdateWebhookLastStatus updates last status of webhook.
282+
func UpdateWebhookLastStatus(w *Webhook) error {
283+
_, err := x.ID(w.ID).Cols("last_status").Update(w)
284+
return err
285+
}
286+
274287
// deleteWebhook uses argument bean as query condition,
275288
// ID must be specified and do not assign unnecessary fields.
276289
func deleteWebhook(bean *Webhook) (err error) {
@@ -603,7 +616,7 @@ func (t *HookTask) deliver() {
603616
}
604617

605618
// Update webhook last delivery status.
606-
w, err := GetWebhookByRepoID(t.RepoID, t.HookID)
619+
w, err := GetWebhookByID(t.HookID)
607620
if err != nil {
608621
log.Error(5, "GetWebhookByID: %v", err)
609622
return
@@ -613,8 +626,8 @@ func (t *HookTask) deliver() {
613626
} else {
614627
w.LastStatus = HookStatusFail
615628
}
616-
if err = UpdateWebhook(w); err != nil {
617-
log.Error(5, "UpdateWebhook: %v", err)
629+
if err = UpdateWebhookLastStatus(w); err != nil {
630+
log.Error(5, "UpdateWebhookLastStatus: %v", err)
618631
return
619632
}
620633
}()

models/webhook_discord.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ func getDiscordPushPayload(p *api.PushPayload, meta *DiscordMeta) (*DiscordPaylo
142142
}
143143
}
144144

145-
fmt.Println(text)
146-
147145
return &DiscordPayload{
148146
Username: meta.Username,
149147
AvatarURL: meta.IconURL,

routers/routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func RegisterRoutes(m *macaron.Macaron) {
396396
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
397397
m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
398398
m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
399-
m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
399+
m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
400400
m.Get("/:id", repo.WebHooksEdit)
401401
m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
402402
m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)

templates/org/settings/hook_new.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
{{template "repo/settings/hook_gitea" .}}
2323
{{template "repo/settings/hook_gogs" .}}
2424
{{template "repo/settings/hook_slack" .}}
25+
{{template "repo/settings/hook_discord" .}}
2526
</div>
2627

2728
{{template "repo/settings/hook_history" .}}

0 commit comments

Comments
 (0)