aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-14 03:32:24 -0700
committerUnknwon <u@gogs.io>2016-08-14 03:32:24 -0700
commit3f7f4852efaaa56a0dada832dc652a1fc8869ae7 (patch)
treee3bb1769b2967dea560b2400abf830dc6cf70067 /models/webhook.go
parent0f33b04c876593e592887450302774654fef2787 (diff)
downloadgitea-3f7f4852efaaa56a0dada832dc652a1fc8869ae7.tar.gz
gitea-3f7f4852efaaa56a0dada832dc652a1fc8869ae7.zip
#2246 fully support of webhooks for pull request
Diffstat (limited to 'models/webhook.go')
-rw-r--r--models/webhook.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/models/webhook.go b/models/webhook.go
index 79d60da3a2..ad4ac189bb 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -58,8 +58,9 @@ func IsValidHookContentType(name string) bool {
}
type HookEvents struct {
- Create bool `json:"create"`
- Push bool `json:"push"`
+ Create bool `json:"create"`
+ Push bool `json:"push"`
+ PullRequest bool `json:"pull_request"`
}
// HookEvent represents events that will delivery hook.
@@ -157,6 +158,12 @@ func (w *Webhook) HasPushEvent() bool {
(w.ChooseEvents && w.HookEvents.Push)
}
+// HasPullRequestEvent returns true if hook enabled pull request event.
+func (w *Webhook) HasPullRequestEvent() bool {
+ return w.SendEverything ||
+ (w.ChooseEvents && w.HookEvents.PullRequest)
+}
+
func (w *Webhook) EventsArray() []string {
events := make([]string, 0, 2)
if w.HasCreateEvent() {
@@ -309,8 +316,9 @@ func IsValidHookTaskType(name string) bool {
type HookEventType string
const (
- HOOK_EVENT_CREATE HookEventType = "create"
- HOOK_EVENT_PUSH HookEventType = "push"
+ HOOK_EVENT_CREATE HookEventType = "create"
+ HOOK_EVENT_PUSH HookEventType = "push"
+ HOOK_EVENT_PULL_REQUEST HookEventType = "pull_request"
)
// HookRequest represents hook task request information.
@@ -422,17 +430,13 @@ func UpdateHookTask(t *HookTask) error {
// PrepareWebhooks adds new webhooks to task queue for given payload.
func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error {
- if err := repo.GetOwner(); err != nil {
- return fmt.Errorf("GetOwner: %v", err)
- }
-
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.Owner.IsOrganization() {
+ if repo.MustOwner().IsOrganization() {
// get hooks for org
orgws, err := GetActiveWebhooksByOrgID(repo.OwnerID)
if err != nil {
@@ -456,6 +460,10 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err
if !w.HasPushEvent() {
continue
}
+ case HOOK_EVENT_PULL_REQUEST:
+ if !w.HasPullRequestEvent() {
+ continue
+ }
}
// Use separate objects so modifcations won't be made on payload on non-Gogs type hooks.
@@ -477,7 +485,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err
URL: w.URL,
Payloader: payloader,
ContentType: w.ContentType,
- EventType: HOOK_EVENT_PUSH,
+ EventType: event,
IsSSL: w.IsSSL,
}); err != nil {
return fmt.Errorf("CreateHookTask: %v", err)