@@ -18,29 +18,37 @@ const (
1818)
1919
2020func main () {
21- // Prepare GitHub
22- var ghClient * github.Client
21+ app := cli .NewApp (
22+ initGitHubClient (),
23+ )
24+ app .Run ()
25+ }
26+
27+ func initGitHubClient () * github.Client {
2328 netrcData , err := netrc .ParseFile (netrcPath )
24- if err == nil {
25- var ghAccessToken string
26- for _ , machine := range netrcData .Machines {
27- if machine .Name == netrcMachineGitHub {
28- ghAccessToken = machine .Password
29- break
30- }
31- }
29+ if err != nil {
30+ return nil
31+ }
3232
33- if ghAccessToken != "" {
34- ghTokenSrc := oauth2 .StaticTokenSource (
35- & oauth2.Token {
36- AccessToken : strings .TrimSpace (ghAccessToken ),
37- },
38- )
39- ghHTTPClient := oauth2 .NewClient (context .Background (), ghTokenSrc )
40- ghClient = github .NewClient (ghHTTPClient )
33+ var ghAccessToken string
34+ for _ , machine := range netrcData .Machines {
35+ if machine .Name == netrcMachineGitHub {
36+ ghAccessToken = machine .Password
37+ break
4138 }
4239 }
4340
44- app := cli .NewApp (ghClient )
45- app .Run ()
41+ if ghAccessToken == "" {
42+ return nil
43+ }
44+
45+ ghTokenSrc := oauth2 .StaticTokenSource (
46+ & oauth2.Token {
47+ AccessToken : strings .TrimSpace (ghAccessToken ),
48+ },
49+ )
50+ ghHTTPClient := oauth2 .NewClient (context .Background (), ghTokenSrc )
51+ ghClient := github .NewClient (ghHTTPClient )
52+
53+ return ghClient
4654}
0 commit comments