(ctx context.Context, entity params.ForgeEntity)
| 659 | } |
| 660 | |
| 661 | func Client(ctx context.Context, entity params.ForgeEntity) (common.GithubClient, error) { |
| 662 | httpClient, err := entity.Credentials.GetHTTPClient(ctx) |
| 663 | if err != nil { |
| 664 | return nil, fmt.Errorf("error fetching http client: %w", err) |
| 665 | } |
| 666 | |
| 667 | slog.DebugContext( |
| 668 | ctx, "creating client for entity", |
| 669 | "entity", entity.String(), "base_url", entity.Credentials.APIBaseURL, |
| 670 | "upload_url", entity.Credentials.UploadBaseURL) |
| 671 | |
| 672 | ghClient := github.NewClient(httpClient) |
| 673 | switch entity.Credentials.ForgeType { |
| 674 | case params.GithubEndpointType: |
| 675 | ghClient, err = ghClient.WithEnterpriseURLs(entity.Credentials.APIBaseURL, entity.Credentials.UploadBaseURL) |
| 676 | case params.GiteaEndpointType: |
| 677 | ghClient, err = withGiteaURLs(ghClient, entity.Credentials.APIBaseURL) |
| 678 | } |
| 679 | |
| 680 | if err != nil { |
| 681 | return nil, fmt.Errorf("error fetching github client: %w", err) |
| 682 | } |
| 683 | |
| 684 | cli := &githubClient{ |
| 685 | ActionsService: ghClient.Actions, |
| 686 | org: ghClient.Organizations, |
| 687 | repo: ghClient.Repositories, |
| 688 | enterprise: ghClient.Enterprise, |
| 689 | rateLimit: ghClient.RateLimit, |
| 690 | cli: ghClient, |
| 691 | entity: entity, |
| 692 | } |
| 693 | |
| 694 | limits, err := cli.RateLimit(ctx) |
| 695 | if err == nil && limits != nil { |
| 696 | core := limits.GetCore() |
| 697 | if core != nil { |
| 698 | cli.recordLimits(*core) |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return cli, nil |
| 703 | } |
no test coverage detected