|
|
@ -482,44 +482,25 @@ func UpdateHookTask(t *HookTask) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// PrepareWebhooks adds new webhooks to task queue for given payload.
|
|
|
|
// PrepareWebhook adds special webhook to task queue for given payload.
|
|
|
|
func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error { |
|
|
|
func PrepareWebhook(w *Webhook, repo *Repository, event HookEventType, p api.Payloader) error { |
|
|
|
ws, err := GetActiveWebhooksByRepoID(repo.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("GetActiveWebhooksByRepoID: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check if repo belongs to org and append additional webhooks
|
|
|
|
|
|
|
|
if repo.MustOwner().IsOrganization() { |
|
|
|
|
|
|
|
// get hooks for org
|
|
|
|
|
|
|
|
orgHooks, err := GetActiveWebhooksByOrgID(repo.OwnerID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("GetActiveWebhooksByOrgID: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ws = append(ws, orgHooks...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(ws) == 0 { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var payloader api.Payloader |
|
|
|
|
|
|
|
for _, w := range ws { |
|
|
|
|
|
|
|
switch event { |
|
|
|
switch event { |
|
|
|
case HookEventCreate: |
|
|
|
case HookEventCreate: |
|
|
|
if !w.HasCreateEvent() { |
|
|
|
if !w.HasCreateEvent() { |
|
|
|
continue |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
case HookEventPush: |
|
|
|
case HookEventPush: |
|
|
|
if !w.HasPushEvent() { |
|
|
|
if !w.HasPushEvent() { |
|
|
|
continue |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
case HookEventPullRequest: |
|
|
|
case HookEventPullRequest: |
|
|
|
if !w.HasPullRequestEvent() { |
|
|
|
if !w.HasPullRequestEvent() { |
|
|
|
continue |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var payloader api.Payloader |
|
|
|
|
|
|
|
var err error |
|
|
|
// Use separate objects so modifications won't be made on payload on non-Gogs/Gitea type hooks.
|
|
|
|
// Use separate objects so modifications won't be made on payload on non-Gogs/Gitea type hooks.
|
|
|
|
switch w.HookTaskType { |
|
|
|
switch w.HookTaskType { |
|
|
|
case SLACK: |
|
|
|
case SLACK: |
|
|
@ -549,6 +530,34 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err |
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return fmt.Errorf("CreateHookTask: %v", err) |
|
|
|
return fmt.Errorf("CreateHookTask: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PrepareWebhooks adds new webhooks to task queue for given payload.
|
|
|
|
|
|
|
|
func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error { |
|
|
|
|
|
|
|
ws, err := GetActiveWebhooksByRepoID(repo.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("GetActiveWebhooksByRepoID: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check if repo belongs to org and append additional webhooks
|
|
|
|
|
|
|
|
if repo.MustOwner().IsOrganization() { |
|
|
|
|
|
|
|
// get hooks for org
|
|
|
|
|
|
|
|
orgHooks, err := GetActiveWebhooksByOrgID(repo.OwnerID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("GetActiveWebhooksByOrgID: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ws = append(ws, orgHooks...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(ws) == 0 { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, w := range ws { |
|
|
|
|
|
|
|
if err = PrepareWebhook(w, repo, event, p); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|