summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorChristopher Brickley <brickley@gmail.com>2014-09-04 07:17:00 -0400
committerChristopher Brickley <brickley@gmail.com>2014-09-05 07:19:34 -0400
commit85c35a6b8bb7430568d375d1e792e1417bbd7f4b (patch)
treed269e4a890036a76d8f8cd60f8d65e7a0c80d865 /models
parent7269b06fd5992776c07ae0303f85e0d05b1e62e9 (diff)
downloadgitea-85c35a6b8bb7430568d375d1e792e1417bbd7f4b.tar.gz
gitea-85c35a6b8bb7430568d375d1e792e1417bbd7f4b.zip
add organization-level webhooks
Diffstat (limited to 'models')
-rw-r--r--models/action.go16
-rw-r--r--models/webhook.go13
2 files changed, 27 insertions, 2 deletions
diff --git a/models/action.go b/models/action.go
index f739fc353d..c0992dba68 100644
--- a/models/action.go
+++ b/models/action.go
@@ -220,8 +220,20 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
ws, err := GetActiveWebhooksByRepoId(repoId)
if err != nil {
- return errors.New("action.CommitRepoAction(GetWebhooksByRepoId): " + err.Error())
- } else if len(ws) == 0 {
+ return errors.New("action.CommitRepoAction(GetActiveWebhooksByRepoId): " + err.Error())
+ }
+
+ // check if repo belongs to org and append additional webhooks
+ if repo.Owner.IsOrganization() {
+ // get hooks for org
+ orgws, err := GetActiveWebhooksByOrgId(repo.OwnerId)
+ if err != nil {
+ return errors.New("action.CommitRepoAction(GetActiveWebhooksByOrgId): " + err.Error())
+ }
+ ws = append(ws, orgws...)
+ }
+
+ if len(ws) == 0 {
return nil
}
diff --git a/models/webhook.go b/models/webhook.go
index 0b7b3a9948..5acc83f592 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -45,6 +45,7 @@ type Webhook struct {
IsActive bool
HookTaskType HookTaskType
Meta string `xorm:"TEXT"` // store hook-specific attributes
+ OrgId int64
}
// GetEvent handles conversion from Events to HookEvent.
@@ -120,6 +121,18 @@ func DeleteWebhook(hookId int64) error {
return err
}
+// GetWebhooksByOrgId returns all webhooks for an organization.
+func GetWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) {
+ err = x.Find(&ws, &Webhook{OrgId: orgId})
+ return ws, err
+}
+
+// GetActiveWebhooksByOrgId returns all active webhooks for an organization.
+func GetActiveWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) {
+ err = x.Find(&ws, &Webhook{OrgId: orgId, IsActive: true})
+ return ws, err
+}
+
// ___ ___ __ ___________ __
// / | \ ____ ____ | | _\__ ___/____ _____| | __
// / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ /