| 144 | ` |
| 145 | |
| 146 | func NewGitHubClient(ctx context.Context, config *config.Config) *client { |
| 147 | token := findToken(config.Repo.GitHubHost) |
| 148 | if token == "" { |
| 149 | fmt.Printf(tokenHelpText, config.Repo.GitHubHost) |
| 150 | os.Exit(3) |
| 151 | } |
| 152 | ts := oauth2.StaticTokenSource( |
| 153 | &oauth2.Token{AccessToken: token}, |
| 154 | ) |
| 155 | tc := oauth2.NewClient(ctx, ts) |
| 156 | |
| 157 | var api genclient.Client |
| 158 | var endpoint string |
| 159 | if strings.HasSuffix(config.Repo.GitHubHost, "github.com") { |
| 160 | endpoint = "https://api.github.com/graphql" |
| 161 | } else { |
| 162 | var scheme, host string |
| 163 | gitHubRemoteUrl, err := url.Parse(config.Repo.GitHubHost) |
| 164 | check(err) |
| 165 | if gitHubRemoteUrl.Host == "" { |
| 166 | host = config.Repo.GitHubHost |
| 167 | scheme = "https" |
| 168 | } else { |
| 169 | host = gitHubRemoteUrl.Host |
| 170 | scheme = gitHubRemoteUrl.Scheme |
| 171 | } |
| 172 | endpoint = fmt.Sprintf("%s://%s/api/graphql", scheme, host) |
| 173 | } |
| 174 | api = genclient.NewClient(endpoint, tc) |
| 175 | return &client{ |
| 176 | config: config, |
| 177 | api: api, |
| 178 | graphqlEndpoint: endpoint, |
| 179 | httpClient: tc, |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | type client struct { |
| 184 | config *config.Config |