-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstash.go
81 lines (71 loc) · 1.58 KB
/
stash.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
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// See https://confluence.atlassian.com/display/STASH/POST+service+webhook+for+Stash
type StashNotification struct {
Repository StashRepository
RefChanges []StashRefChange
Changesets interface{}
}
type StashRepository struct {
ID int
Slug string
Name string
ScmID string
State string
StatusMessage string
Forkable bool
Project StashProject
Public bool
}
type StashProject struct {
ID int
Key string
Name string
Public bool
Type string
IsPersonal bool
Owner StashUser
}
type StashRefChange struct {
RefID string
FromHash string
ToHash string
Type string
}
type StashUser struct {
Name string
EmailAddress string
ID int
DisplayName string
Active bool
Slug string
Type string
}
func StashParse(r *http.Request) (n Notification, err error) {
defer r.Body.Close()
bytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
}
return stashParseBytes(bytes)
}
func stashParseBytes(bytes []byte) (n StashNotification, err error) {
err = json.Unmarshal(bytes, &n)
return
}
func (n StashNotification) RepositoryURL() (repositoryURL string) {
repositoryURL = n.Repository.Project.Key + "/" + n.Repository.Name
if repositoryURL[len(repositoryURL)-1] == '/' {
repositoryURL = repositoryURL[:len(repositoryURL)-1]
}
return
}
// not supported
func (n StashNotification) Branches() (branches map[string]bool) {
branches = make(map[string]bool)
return
}