Browse code

Add support for GitLab Push Event

vanloswang authored on 2016/09/21 17:49:38
Showing 1 changed files
... ...
@@ -16,7 +16,7 @@ import (
16 16
 )
17 17
 
18 18
 var (
19
-	ErrNoGitHubEvent = errors.New("missing X-GitHub-Event or X-Gogs-Event")
19
+	ErrNoGitHubEvent = errors.New("missing X-GitHub-Event, X-Gogs-Event or X-Gitlab-Event")
20 20
 )
21 21
 
22 22
 // WebHook used for processing github webhook requests.
... ...
@@ -57,8 +57,8 @@ func (p *WebHook) Extract(buildCfg *api.BuildConfig, secret, path string, req *h
57 57
 		return revision, envvars, proceed, err
58 58
 	}
59 59
 	method := getEvent(req.Header)
60
-	if method != "ping" && method != "push" {
61
-		return revision, envvars, proceed, fmt.Errorf("Unknown X-GitHub-Event or X-Gogs-Event %s", method)
60
+	if method != "ping" && method != "push" && method != "Push Hook" {
61
+		return revision, envvars, proceed, fmt.Errorf("Unknown X-GitHub-Event, X-Gogs-Event or X-Gitlab-Event %s", method)
62 62
 	}
63 63
 	if method == "ping" {
64 64
 		return revision, envvars, proceed, err
... ...
@@ -110,5 +110,8 @@ func getEvent(header http.Header) string {
110 110
 	if len(event) == 0 {
111 111
 		event = header.Get("X-Gogs-Event")
112 112
 	}
113
+	if len(event) == 0 {
114
+		event = header.Get("X-Gitlab-Event")
115
+	}
113 116
 	return event
114 117
 }