/
main.go
53 lines (42 loc) · 1.2 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
package main
import (
"errors"
"fmt"
"github.com/codegangsta/cli"
"github.com/toqueteos/webbrowser"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "go-pr"
app.Usage = "Create a Pull Request for the current branch"
app.UsageText = `
go-pr @target-branch # default target-user to your Github user
go-pr target-user/target-repo@target-branch
go-pr target-user/target-repo # default target-branch to master
go-pr target-user # default target-branch to master and target-repo to the name of your Github repo
`
app.Version = "0.0.2"
app.Author = "Bao Pham"
app.Email = "gbaopham@gmail.com"
app.Before = func(c *cli.Context) error {
if len(c.Args()) < 1 {
return errors.New("Target is required")
}
return nil
}
app.Action = func(c *cli.Context) {
remote := getRemote()
branch := getBranch()
currentRepo := NewRepo(remote, branch)
target := parseTarget(c.Args().First(), currentRepo)
if !currentRepo.IsGithub() {
println("Only support Github for now")
os.Exit(1)
}
webbrowser.Open(fmt.Sprintf("https://github.com/%s/%s/compare/%s...%s:%s",
target.username, target.name, target.branch,
currentRepo.username, currentRepo.branch))
}
app.Run(os.Args)
}