-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpullrequest.go
48 lines (41 loc) · 1005 Bytes
/
pullrequest.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
package gittt
import (
"encoding/json"
"log"
)
type PullRequest struct {
State string `json:"action"`
PRInfo PullRequestInfo `json:"pull_request"`
}
type PullRequestInfo struct {
Title string `json:"title"`
FromBranch Branch `json:"head"`
IntoBranch Branch `json:"base"`
Merged bool `json:"merged"`
}
func PullRequestTrigger(g *Gittt, data []byte) error {
var pr PullRequest
err := json.Unmarshal(data, &pr)
if err != nil {
return err
}
log.Println("Pull Request Event Received")
actions := g.matchConditionals(PREvent, pr)
for _, action := range actions {
action.Do(pr)
}
return nil
}
func (g *Gittt) ConditionPRMergedInAnyOf(data interface{}, branches ...interface{}) bool {
if pr, ok := data.(PullRequest); ok {
if pr.State == "closed" {
for _, branch := range branches {
if pr.PRInfo.IntoBranch.Ref == branch.(string) {
log.Printf("Condition match: PR merged on %s\n", branch.(string))
return true
}
}
}
}
return false
}