-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
54 lines (45 loc) · 1.15 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 (
"fmt"
"net/url"
"github.com/spf13/cobra"
)
var (
jenkinsEndpoint string
proxyEndpoint string
)
var rootCmd = &cobra.Command{
Use: "github-proxy [sub]",
Short: "github-proxy",
SilenceUsage: true,
}
var serverCmd = &cobra.Command{
Use: "server",
Short: "server",
SilenceUsage: true,
Run: func(c *cobra.Command, args []string) {
listen := proxyEndpoint
u, err := url.Parse(proxyEndpoint)
if err == nil {
listen = fmt.Sprintf("%s:%s", u.Hostname(), u.Port())
}
proxy := NewWebhookProxyServer(listen)
proxy.ListenAndServe()
},
}
var clientCmd = &cobra.Command{
Use: "client",
Short: "client",
SilenceUsage: true,
Run: func(c *cobra.Command, args []string) {
client := NewWebhookProxyClient()
client.Run()
},
}
func main() {
rootCmd.PersistentFlags().StringVar(&jenkinsEndpoint, "jenkins", "http://localhost:8080/ghprbhook/", "Jenkins ghprb endpoint")
rootCmd.PersistentFlags().StringVar(&proxyEndpoint, "proxy", "http://127.0.0.1:8081", "address and port for the webhook proxy")
rootCmd.AddCommand(clientCmd)
rootCmd.AddCommand(serverCmd)
rootCmd.Execute()
}