-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (42 loc) · 1.11 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"gopkg.in/go-playground/webhooks.v4"
"gopkg.in/go-playground/webhooks.v4/github"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
const (
path = "/webhooks"
)
func main() {
flag.String("port", "3000", "port to listen to")
flag.String("secret", "", "github secret to use")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
port := viper.GetString("port")
secret := viper.GetString("secret")
hook := github.New(&github.Config{Secret: secret})
hook.RegisterEvents(handlePush, github.PushEvent)
err := webhooks.Run(hook, ":"+port, path)
if err != nil {
fmt.Println(err)
}
}
func handlePush(payload interface{}, header webhooks.Header) {
pl := payload.(github.PushPayload)
switch pl.Repository.FullName {
case "arcana261/ucoder":
log.Printf("Handling push event for arcana261/ucoder\n")
handleUcoder()
default:
log.Printf("Repository not recognized: %s\n", pl.Repository.FullName)
}
}
func handleUcoder() {
cwd := "/usr/share/nginx/ucoder.ir"
run(cwd, "/bin/bash", "/srv/ucoder.ir/bin/redeploy.sh")
}