refactor: move init github client
parent
4d1cae4002
commit
e1b77493c6
|
@ -18,10 +18,18 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// Prepare GitHub
|
||||
var ghClient *github.Client
|
||||
app := cli.NewApp(
|
||||
initGitHubClient(),
|
||||
)
|
||||
app.Run()
|
||||
}
|
||||
|
||||
func initGitHubClient() *github.Client {
|
||||
netrcData, err := netrc.ParseFile(netrcPath)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ghAccessToken string
|
||||
for _, machine := range netrcData.Machines {
|
||||
if machine.Name == netrcMachineGitHub {
|
||||
|
@ -30,17 +38,17 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
if ghAccessToken != "" {
|
||||
if ghAccessToken == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
ghTokenSrc := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{
|
||||
AccessToken: strings.TrimSpace(ghAccessToken),
|
||||
},
|
||||
)
|
||||
ghHTTPClient := oauth2.NewClient(context.Background(), ghTokenSrc)
|
||||
ghClient = github.NewClient(ghHTTPClient)
|
||||
}
|
||||
}
|
||||
ghClient := github.NewClient(ghHTTPClient)
|
||||
|
||||
app := cli.NewApp(ghClient)
|
||||
app.Run()
|
||||
return ghClient
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue