ensureClient builds an GitHub API client if none exists and stores it on the struct.
()
| 73 | |
| 74 | // ensureClient builds an GitHub API client if none exists and stores it on the struct. |
| 75 | func (gh *Storage) ensureClient() error { |
| 76 | if gh.client != nil { |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | if gh.AccessToken == "" { |
| 81 | return fmt.Errorf("Please specify access_token in storage configuration") |
| 82 | } |
| 83 | |
| 84 | gh.client = github.NewClient(oauth2.NewClient( |
| 85 | oauth2.NoContext, |
| 86 | oauth2.StaticTokenSource( |
| 87 | &oauth2.Token{AccessToken: gh.AccessToken}, |
| 88 | ), |
| 89 | )) |
| 90 | |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | // fullPathName ensures the configured Dir value is present in the filename and |
| 95 | // returns a filename with the Dir prefixed before the input filename if necessary. |