Browse Source

fix orgnization webhooks (#2422)

* fix org webhooks

* remove trace code
Lunny Xiao 2 years ago
parent
commit
04ec79579c
4 changed files with 18 additions and 6 deletions
  1. 16 3
      models/webhook.go
  2. 0 2
      models/webhook_discord.go
  3. 1 1
      routers/routes/routes.go
  4. 1 0
      templates/org/settings/hook_new.tmpl

+ 16 - 3
models/webhook.go

@@ -221,6 +221,13 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
221 221
 	return bean, nil
222 222
 }
223 223
 
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
+
224 231
 // GetWebhookByRepoID returns webhook of repository by given ID.
225 232
 func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) {
226 233
 	return getWebhook(&Webhook{
@@ -271,6 +278,12 @@ func UpdateWebhook(w *Webhook) error {
271 278
 	return err
272 279
 }
273 280
 
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
+
274 287
 // deleteWebhook uses argument bean as query condition,
275 288
 // ID must be specified and do not assign unnecessary fields.
276 289
 func deleteWebhook(bean *Webhook) (err error) {
@@ -603,7 +616,7 @@ func (t *HookTask) deliver() {
603 616
 		}
604 617
 
605 618
 		// Update webhook last delivery status.
606
-		w, err := GetWebhookByRepoID(t.RepoID, t.HookID)
619
+		w, err := GetWebhookByID(t.HookID)
607 620
 		if err != nil {
608 621
 			log.Error(5, "GetWebhookByID: %v", err)
609 622
 			return
@@ -613,8 +626,8 @@ func (t *HookTask) deliver() {
613 626
 		} else {
614 627
 			w.LastStatus = HookStatusFail
615 628
 		}
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)
618 631
 			return
619 632
 		}
620 633
 	}()

+ 0 - 2
models/webhook_discord.go

@@ -142,8 +142,6 @@ func getDiscordPushPayload(p *api.PushPayload, meta *DiscordMeta) (*DiscordPaylo
142 142
 		}
143 143
 	}
144 144
 
145
-	fmt.Println(text)
146
-
147 145
 	return &DiscordPayload{
148 146
 		Username:  meta.Username,
149 147
 		AvatarURL: meta.IconURL,

+ 1 - 1
routers/routes/routes.go

@@ -396,7 +396,7 @@ func RegisterRoutes(m *macaron.Macaron) {
396 396
 					m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
397 397
 					m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
398 398
 					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)
400 400
 					m.Get("/:id", repo.WebHooksEdit)
401 401
 					m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
402 402
 					m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)

+ 1 - 0
templates/org/settings/hook_new.tmpl

@@ -22,6 +22,7 @@
22 22
 					{{template "repo/settings/hook_gitea" .}}
23 23
 					{{template "repo/settings/hook_gogs" .}}
24 24
 					{{template "repo/settings/hook_slack" .}}
25
+					{{template "repo/settings/hook_discord" .}}
25 26
 				</div>
26 27
 
27 28
 				{{template "repo/settings/hook_history" .}}