-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
64 lines (46 loc) · 1.01 KB
/
server.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
package main
import (
"github.com/go-martini/martini"
"github.com/google/go-github/github"
"github.com/joho/godotenv"
"golang.org/x/oauth2"
"log"
"os"
)
func getClient() *github.Client {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env")
}
authToken := os.Getenv("GITHUB_TOKEN")
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: authToken},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
return github.NewClient(tc)
}
func setAssignee(pull *github.PullRequest) error {
log.Printf(github.Stringify(pull.User))
return nil
}
func main() {
m := martini.Classic()
m.Get("/webhook", func() string {
client := getClient()
pull, _, err := client.PullRequests.Get("reflect", "reflect-js", 100)
if err != nil {
log.Fatal(err)
return "Error getting pull request"
}
err = setAssignee(pull)
if err != nil {
log.Fatal(err)
return "Error setting assignee"
}
return "well done!"
})
m.Get("/", func() string {
return "Hello world!"
})
m.Run()
}