-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (70 loc) · 1.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"errors"
"github.com/8bitjonny/linear-git/auth"
"github.com/8bitjonny/linear-git/config"
"github.com/urfave/cli/v2"
"log"
"os"
"os/exec"
)
func main() {
app := &cli.App{
Name: "gli",
Version: "v0.1.0",
Usage: "A nice git command line helper for linear",
Commands: []*cli.Command{
{
Name: "login",
Description: "Authenticate gli to read issue information from linear",
Usage: "login to linear",
Action: func(cCtx *cli.Context) error {
server := auth.CreateAuthCallbackServer()
if err := auth.OpenAuthScreen(); err != nil {
return err
}
println("Complete authorization in opened browser tab\nWaiting...")
token := server.GetAuthToken()
// Save token
appConfig, err := config.ReadFromFilesystem()
if err != nil {
return err
}
appConfig.AuthToken = token
err = appConfig.WriteToFilesystem()
if err != nil {
return err
}
println("Logged in successfully")
return nil
},
}, {
Name: "branch",
Description: "Create branch for specified linear ticket. It just wraps 'git checkout -b' meaning it'll create a new branch from your current one.",
Usage: "create branch for linear ticket",
ArgsUsage: "[linearIssueId]",
Action: func(cCtx *cli.Context) error {
issueID := cCtx.Args().First()
appConfig, err := config.ReadFromFilesystem()
if err != nil {
return err
} else if appConfig.AuthToken == "" {
return errors.New("not authorized yet. You have to run 'gli login' first")
}
branchName, err := GetBranchName(issueID, appConfig.AuthToken)
if err != nil {
return err
}
if err = exec.Command("git", "checkout", "-b", branchName).Start(); err != nil {
return err
}
println("Switched to Branch: ", branchName)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}