/
helpers.go
50 lines (41 loc) · 1.34 KB
/
helpers.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
package pull
import "github.com/google/go-github/github"
type runnerFunc func(*Handler, github.PullRequestEvent)
func Success(url string, desc string, c string) *github.RepoStatus {
return &github.RepoStatus{
State: github.String("success"),
TargetURL: github.String(url),
Description: github.String(desc),
Context: github.String("pull/" + c),
}
}
func Failure(url string, desc string, c string) *github.RepoStatus {
return &github.RepoStatus{
State: github.String("failure"),
TargetURL: github.String(url),
Description: github.String(desc),
Context: github.String("pull/" + c),
}
}
func Data(req *github.PullRequest) (user string, repository string, number int) {
user = *req.Base.User.Login
repository = *req.Base.Repo.Name
number = *req.Number
return
}
func pending(client *github.Client, event *github.PullRequest) {
user, repo, number := Data(event)
commits, _, _ := client.PullRequests.ListCommits(user, repo, number, nil)
for _, c := range commits {
status := &github.RepoStatus{
State: github.String("pending"),
Description: github.String("Running tests."),
}
client.Repositories.CreateStatus(user, repo, *c.SHA, status)
}
}
func runner(handler *Handler, event github.PullRequestEvent) {
for _, m := range handler.Middlewares[*event.Action] {
m(handler.Client, event.PullRequest)
}
}