MCPcopy Create free account
hub / github.com/ejoffe/spr / NewGitHubClient

Function NewGitHubClient

github/githubclient/client.go:146–181  ·  view source on GitHub ↗
(ctx context.Context, config *config.Config)

Source from the content-addressed store, hash-verified

144`
145
146func 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
183type client struct {
184 config *config.Config

Callers 2

mainFunction · 0.92
mainFunction · 0.92

Calls 3

NewClientFunction · 0.92
findTokenFunction · 0.85
checkFunction · 0.70

Tested by

no test coverage detected