feat: make github client optional

main
sudo pacman -Syu 2023-08-15 19:00:22 +07:00 committed by sudo pacman -Syu
parent 22d16a8947
commit 4d1cae4002
3 changed files with 26 additions and 20 deletions

View File

@ -23,6 +23,10 @@ update-go-mod --deps-url "https://example.txt"
# Don't do anythin
update-go-mod --dry-run
# Take a look
# Require GitHub access token in ~/.netrc
update-go-mod overlook
```
## Thanks

View File

@ -2,7 +2,6 @@ package main
import (
"context"
"log"
"strings"
"github.com/google/go-github/v53/github"
@ -20,29 +19,27 @@ const (
func main() {
// Prepare GitHub
var ghClient *github.Client
netrcData, err := netrc.ParseFile(netrcPath)
if err != nil {
log.Fatalln("Failed to read file netrc", err)
}
if err == nil {
var ghAccessToken string
for _, machine := range netrcData.Machines {
if machine.Name == netrcMachineGitHub {
ghAccessToken = machine.Password
break
}
}
var ghAccessToken string
for _, machine := range netrcData.Machines {
if machine.Name == netrcMachineGitHub {
ghAccessToken = machine.Password
break
if ghAccessToken != "" {
ghTokenSrc := oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: strings.TrimSpace(ghAccessToken),
},
)
ghHTTPClient := oauth2.NewClient(context.Background(), ghTokenSrc)
ghClient = github.NewClient(ghHTTPClient)
}
}
if ghAccessToken == "" {
log.Fatalln("Empty GitHub token in netrc")
}
ghTokenSrc := oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: strings.TrimSpace(ghAccessToken),
},
)
ghHTTPClient := oauth2.NewClient(context.Background(), ghTokenSrc)
ghClient := github.NewClient(ghHTTPClient)
app := cli.NewApp(ghClient)
app.Run()

View File

@ -20,6 +20,11 @@ type GitHubRepoData struct {
}
func (a *action) Overlook(c *cli.Context) error {
// Optional
if a.ghClient == nil {
return nil
}
a.getFlags(c)
mapImportedModules, err := a.runGetImportedModules(c)