-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.go
50 lines (43 loc) · 1.08 KB
/
remote.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
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/qjw/git-notify/remote"
"github.com/qjw/git-notify/remote/gitlab"
)
func GetGitlabFlags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
EnvVar: "GIT_NOTIFY_GITLAB",
Name: "gitlab",
Usage: "gitlab是否启用",
},
cli.StringFlag{
EnvVar: "GIT_NOTIFY_GITLAB_URL",
Name: "gitlab-server",
Usage: "gitlab仓库地址",
Value: "https://gitlab.com",
},
cli.StringFlag{
EnvVar: "GIT_NOTIFY_GITLAB_TOKEN",
Name: "gitlab-patoken",
Usage: "gitlab personal access token",
},
}
}
// helper function to setup the remote from the CLI arguments.
func setupRemote(c *cli.Context) (remote.Remote, error) {
switch {
case c.Bool("gitlab"):
return setupGitlab(c)
default:
return nil, fmt.Errorf("version control system not configured")
}
}
// helper function to setup the Gitlab remote from the CLI arguments.
func setupGitlab(c *cli.Context) (remote.Remote, error) {
return gitlab.New(gitlab.Opts{
URL: c.String("gitlab-server"),
Token: c.String("gitlab-patoken"),
})
}