-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitlab.go
68 lines (57 loc) · 1.4 KB
/
gitlab.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type GitlabNotification struct {
Before string
After string
Ref string
UserID int `json:"User_Id"`
UserName string `json:"User_Name"`
ProjectID int `json:"Project_Id"`
Repository GitlabRepository
Commits []GitlabCommit
TotalCommitsCount int `json:"Total_Commits_Count"`
}
type GitlabRepository struct {
Name string
URL string
Description string
Homepage string
}
type GitlabCommit struct {
ID string
Message string
Timestamp string
URL string
Author GitlabAuthor
}
type GitlabAuthor struct {
Name string
Email string
}
func GitlabParse(r *http.Request) (n Notification, err error) {
defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body)
log.Printf("Received body %s", body)
return gitlabParseBytes(body)
}
func gitlabParseBytes(bytes []byte) (n GitlabNotification, err error) {
err = json.Unmarshal(bytes, &n)
return
}
func (n GitlabNotification) RepositoryURL() (repositoryURL string) {
repositoryURL = n.Repository.Homepage
if repositoryURL[len(repositoryURL)-1] == '/' {
repositoryURL = repositoryURL[:len(repositoryURL)-1]
}
return
}
// not supported by Gitlab push webhook
func (n GitlabNotification) Branches() (branches map[string]bool) {
branches = make(map[string]bool)
return
}