NewRepoClient returns a Client which implements RepoClient interface. It can be configured with various [Option]s.
(ctx context.Context, opts ...Option)
| 345 | // NewRepoClient returns a Client which implements RepoClient interface. |
| 346 | // It can be configured with various [Option]s. |
| 347 | func NewRepoClient(ctx context.Context, opts ...Option) (clients.RepoClient, error) { |
| 348 | var config repoClientConfig |
| 349 | |
| 350 | for _, option := range opts { |
| 351 | if err := option(&config); err != nil { |
| 352 | return nil, err |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if config.rt == nil { |
| 357 | logger := log.NewLogger(log.DefaultLevel) |
| 358 | config.rt = roundtripper.NewTransport(ctx, logger) |
| 359 | } |
| 360 | |
| 361 | httpClient := &http.Client{ |
| 362 | Transport: config.rt, |
| 363 | } |
| 364 | |
| 365 | var client *github.Client |
| 366 | var graphClient *githubv4.Client |
| 367 | githubHost, isGhHost := os.LookupEnv("GH_HOST") |
| 368 | |
| 369 | if isGhHost && githubHost != defaultGhHost { |
| 370 | githubRestURL := fmt.Sprintf("https://%s/api/v3", strings.TrimSpace(githubHost)) |
| 371 | githubGraphqlURL := fmt.Sprintf("https://%s/api/graphql", strings.TrimSpace(githubHost)) |
| 372 | |
| 373 | var err error |
| 374 | client, err = github.NewClient(httpClient).WithEnterpriseURLs(githubRestURL, githubRestURL) |
| 375 | if err != nil { |
| 376 | panic(fmt.Errorf("error during CreateGithubRepoClientWithTransport:EnterpriseClient: %w", err)) |
| 377 | } |
| 378 | |
| 379 | graphClient = githubv4.NewEnterpriseClient(githubGraphqlURL, httpClient) |
| 380 | } else { |
| 381 | client = github.NewClient(httpClient) |
| 382 | graphClient = githubv4.NewClient(httpClient) |
| 383 | } |
| 384 | |
| 385 | return &Client{ |
| 386 | ctx: ctx, |
| 387 | repoClient: client, |
| 388 | graphClient: &graphqlHandler{ |
| 389 | client: graphClient, |
| 390 | }, |
| 391 | contributors: &contributorsHandler{ |
| 392 | ghClient: client, |
| 393 | }, |
| 394 | branches: &branchesHandler{ |
| 395 | ghClient: client, |
| 396 | graphClient: graphClient, |
| 397 | }, |
| 398 | releases: &releasesHandler{ |
| 399 | client: client, |
| 400 | }, |
| 401 | workflows: &workflowsHandler{ |
| 402 | client: client, |
| 403 | }, |
| 404 | checkruns: &checkrunsHandler{ |
no test coverage detected