-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (46 loc) · 1.35 KB
/
main.go
File metadata and controls
66 lines (46 loc) · 1.35 KB
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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/ComputerScienceHouse/github-sync-bot/ghauth"
"github.com/joho/godotenv"
)
func HandleWebhook(w http.ResponseWriter, r *http.Request, tokenInfo *ghauth.GhTokenInfo) {
result := make(map[string]interface{})
json.NewDecoder(r.Body).Decode(&result)
webhookType := r.Header.Get("X-Github-Event")
switch webhookType {
case "pull_request_review":
HandlePRReview(result, tokenInfo)
}
fmt.Println(result)
}
func HandlePRReview(result map[string]interface{}, tokenInfo *ghauth.GhTokenInfo) {
// client := http.Client{}
println(result["review"])
_, err := http.NewRequest("GET", "https://api.github.com/repos/ComputerScienceHouse", nil)
if err != nil {
log.Println("error creating request")
return
}
}
func main() {
err := godotenv.Load()
if err != nil {
log.Println("No env file detected, make sure all secrets are loaded into the environment")
// panic("Error loading .env file")
}
ghTokenInfo, err := ghauth.SetupGHAuth()
if err != nil {
log.Println("failed to retrieve github access token: ", err.Error())
return
}
http.HandleFunc("POST /webhook", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
HandleWebhook(w, r, ghTokenInfo)
}))
port := "8080"
log.Printf("Listening on port %s\n", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}