Skip to content

Commit

Permalink
GitHub - Add retry mechanism for rate limit errors (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Nov 29, 2023
1 parent 98830f1 commit 678003d
Show file tree
Hide file tree
Showing 28 changed files with 926 additions and 600 deletions.
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@ module github.com/jfrog/froggit-go
go 1.20

require (
github.com/gfleury/go-bitbucket-v1 v0.0.0-20230626192437-8d7be5866751
github.com/go-git/go-git/v5 v5.8.1
github.com/google/go-github/v45 v45.2.0
github.com/gfleury/go-bitbucket-v1 v0.0.0-20230825095122-9bc1711434ab
github.com/go-git/go-git/v5 v5.10.0
github.com/google/go-github/v56 v56.0.0
github.com/google/uuid v1.3.0
github.com/grokify/mogo v0.50.0
github.com/jfrog/gofrog v1.3.0
github.com/jfrog/gofrog v1.3.1
github.com/ktrysmt/go-bitbucket v0.9.63
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5
github.com/microsoft/azure-devops-go-api/azuredevops/v7 v7.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/stretchr/testify v1.8.4
github.com/xanzy/go-gitlab v0.88.0
github.com/xanzy/go-gitlab v0.94.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/oauth2 v0.10.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand All @@ -41,11 +42,11 @@ require (
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
56 changes: 27 additions & 29 deletions go.sum

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions vcsclient/azurerepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/jfrog/froggit-go/vcsutils"
"github.com/jfrog/gofrog/datastructures"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/microsoft/azure-devops-go-api/azuredevops/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/git"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
"io"
"net/http"
"os"
Expand All @@ -25,11 +25,11 @@ const defaultAzureBaseUrl = "https://dev.azure.com/"
type AzureReposClient struct {
vcsInfo VcsInfo
connectionDetails *azuredevops.Connection
logger Log
logger vcsutils.Log
}

// NewAzureReposClient create a new AzureReposClient
func NewAzureReposClient(vcsInfo VcsInfo, logger Log) (*AzureReposClient, error) {
func NewAzureReposClient(vcsInfo VcsInfo, logger vcsutils.Log) (*AzureReposClient, error) {
client := &AzureReposClient{vcsInfo: vcsInfo, logger: logger}
baseUrl := strings.TrimSuffix(client.vcsInfo.APIEndpoint, "/")
client.connectionDetails = azuredevops.NewPatConnection(baseUrl, client.vcsInfo.Token)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (client *AzureReposClient) DownloadRepository(ctx context.Context, owner, r
if err != nil {
return err
}
client.logger.Info(successfulRepoExtraction)
client.logger.Info(vcsutils.SuccessfulRepoExtraction)
repoInfo, err := client.GetRepositoryInfo(ctx, owner, repository)
if err != nil {
return err
Expand Down Expand Up @@ -154,7 +154,7 @@ func (client *AzureReposClient) sendDownloadRepoRequest(ctx context.Context, rep
if err = vcsutils.CheckResponseStatusWithBody(res, http.StatusOK); err != nil {
return &http.Response{}, err
}
client.logger.Info(repository, successfulRepoDownload)
client.logger.Info(repository, vcsutils.SuccessfulRepoDownload)
return
}

Expand All @@ -166,7 +166,7 @@ func (client *AzureReposClient) CreatePullRequest(ctx context.Context, _, reposi
}
sourceBranch = vcsutils.AddBranchPrefix(sourceBranch)
targetBranch = vcsutils.AddBranchPrefix(targetBranch)
client.logger.Debug(creatingPullRequest, title)
client.logger.Debug(vcsutils.CreatingPullRequest, title)
_, err = azureReposGitClient.CreatePullRequest(ctx, git.CreatePullRequestArgs{
GitPullRequestToCreate: &git.GitPullRequest{
Description: &description,
Expand All @@ -187,7 +187,7 @@ func (client *AzureReposClient) UpdatePullRequest(ctx context.Context, _, reposi
return err
}
targetBranchName = vcsutils.AddBranchPrefix(targetBranchName)
client.logger.Debug(updatingPullRequest, prId)
client.logger.Debug(vcsutils.UpdatingPullRequest, prId)
_, err = azureReposGitClient.UpdatePullRequest(ctx, git.UpdatePullRequestArgs{
GitPullRequestToUpdate: &git.GitPullRequest{
Description: vcsutils.GetNilIfZeroVal(body),
Expand Down Expand Up @@ -338,7 +338,7 @@ func (client *AzureReposClient) getOpenPullRequests(ctx context.Context, owner,
if err != nil {
return nil, err
}
client.logger.Debug(fetchingOpenPullRequests, repository)
client.logger.Debug(vcsutils.FetchingOpenPullRequests, repository)
pullRequests, err := azureReposGitClient.GetPullRequests(ctx, git.GetPullRequestsArgs{
RepositoryId: &repository,
Project: &client.vcsInfo.Project,
Expand All @@ -361,7 +361,7 @@ func (client *AzureReposClient) GetPullRequestByID(ctx context.Context, owner, r
if err != nil {
return
}
client.logger.Debug(fetchingPullRequestById, repository)
client.logger.Debug(vcsutils.FetchingPullRequestById, repository)
pullRequest, err := azureReposGitClient.GetPullRequestById(ctx, git.GetPullRequestByIdArgs{
PullRequestId: &pullRequestId,
Project: &client.vcsInfo.Project,
Expand Down Expand Up @@ -698,7 +698,7 @@ func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRe
sourceRepoOwner := owner
if pullRequest.ForkSource != nil {
if sourceRepoOwner = extractOwnerFromForkedRepoUrl(pullRequest.ForkSource); sourceRepoOwner == "" {
client.logger.Warn(failedForkedRepositoryExtraction)
client.logger.Warn(vcsutils.FailedForkedRepositoryExtraction)
}
}

Expand Down
6 changes: 3 additions & 3 deletions vcsclient/azurerepos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"encoding/json"
"fmt"
"github.com/jfrog/froggit-go/vcsutils"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/microsoft/azure-devops-go-api/azuredevops/git"
"github.com/microsoft/azure-devops-go-api/azuredevops/webapi"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/webapi"
"github.com/stretchr/testify/assert"
"net/http"
"os"
Expand Down
16 changes: 8 additions & 8 deletions vcsclient/bitbucketcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
type BitbucketCloudClient struct {
vcsInfo VcsInfo
url *url.URL
logger Log
logger vcsutils.Log
}

// NewBitbucketCloudClient create a new BitbucketCloudClient
func NewBitbucketCloudClient(vcsInfo VcsInfo, logger Log) (*BitbucketCloudClient, error) {
func NewBitbucketCloudClient(vcsInfo VcsInfo, logger vcsutils.Log) (*BitbucketCloudClient, error) {
bitbucketClient := &BitbucketCloudClient{
vcsInfo: vcsInfo,
logger: logger,
Expand Down Expand Up @@ -268,12 +268,12 @@ func (client *BitbucketCloudClient) DownloadRepository(ctx context.Context, owne
if err = vcsutils.CheckResponseStatusWithBody(response, http.StatusOK); err != nil {
return err
}
client.logger.Info(repository, successfulRepoDownload)
client.logger.Info(repository, vcsutils.SuccessfulRepoDownload)
err = vcsutils.Untar(localPath, response.Body, true)
if err != nil {
return err
}
client.logger.Info(successfulRepoExtraction)
client.logger.Info(vcsutils.SuccessfulRepoExtraction)
repositoryInfo, err := client.GetRepositoryInfo(ctx, owner, repository)
if err != nil {
return err
Expand All @@ -286,7 +286,7 @@ func (client *BitbucketCloudClient) DownloadRepository(ctx context.Context, owne
func (client *BitbucketCloudClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch,
targetBranch, title, description string) error {
bitbucketClient := client.buildBitbucketCloudClient(ctx)
client.logger.Debug(creatingPullRequest, title)
client.logger.Debug(vcsutils.CreatingPullRequest, title)
options := &bitbucket.PullRequestsOptions{
Owner: owner,
SourceRepository: owner + "/" + repository,
Expand All @@ -303,7 +303,7 @@ func (client *BitbucketCloudClient) CreatePullRequest(ctx context.Context, owner
// UpdatePullRequest on Bitbucket cloud
func (client *BitbucketCloudClient) UpdatePullRequest(ctx context.Context, owner, repository, title, body, targetBranchName string, prId int, state vcsutils.PullRequestState) error {
bitbucketClient := client.buildBitbucketCloudClient(ctx)
client.logger.Debug(creatingPullRequest, title)
client.logger.Debug(vcsutils.CreatingPullRequest, title)
options := &bitbucket.PullRequestsOptions{
Owner: owner,
SourceRepository: owner + "/" + repository,
Expand Down Expand Up @@ -334,7 +334,7 @@ func (client *BitbucketCloudClient) getOpenPullRequests(ctx context.Context, own
return nil, err
}
bitbucketClient := client.buildBitbucketCloudClient(ctx)
client.logger.Debug(fetchingOpenPullRequests, repository)
client.logger.Debug(vcsutils.FetchingOpenPullRequests, repository)
options := &bitbucket.PullRequestsOptions{
Owner: owner,
RepoSlug: repository,
Expand All @@ -357,7 +357,7 @@ func (client *BitbucketCloudClient) GetPullRequestByID(ctx context.Context, owne
return
}
bitbucketClient := client.buildBitbucketCloudClient(ctx)
client.logger.Debug(fetchingPullRequestById, repository)
client.logger.Debug(vcsutils.FetchingPullRequestById, repository)
prIdStr := strconv.Itoa(pullRequestId)
options := &bitbucket.PullRequestsOptions{
Owner: owner,
Expand Down
8 changes: 4 additions & 4 deletions vcsclient/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
// BitbucketServerClient API version 1.0
type BitbucketServerClient struct {
vcsInfo VcsInfo
logger Log
logger vcsutils.Log
}

// NewBitbucketServerClient create a new BitbucketServerClient
func NewBitbucketServerClient(vcsInfo VcsInfo, logger Log) (*BitbucketServerClient, error) {
func NewBitbucketServerClient(vcsInfo VcsInfo, logger vcsutils.Log) (*BitbucketServerClient, error) {
bitbucketServerClient := &BitbucketServerClient{
vcsInfo: vcsInfo,
logger: logger,
Expand Down Expand Up @@ -260,12 +260,12 @@ func (client *BitbucketServerClient) DownloadRepository(ctx context.Context, own
if err != nil {
return err
}
client.logger.Info(repository, successfulRepoDownload)
client.logger.Info(repository, vcsutils.SuccessfulRepoDownload)
err = vcsutils.Untar(localPath, bytes.NewReader(response.Payload), false)
if err != nil {
return err
}
client.logger.Info(successfulRepoExtraction)
client.logger.Info(vcsutils.SuccessfulRepoExtraction)
repositoryInfo, err := client.GetRepositoryInfo(ctx, owner, repository)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions vcsclient/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
type ClientBuilder struct {
vcsProvider vcsutils.VcsProvider
vcsInfo VcsInfo
logger Log
logger vcsutils.Log
}

// NewClientBuilder creates new ClientBuilder
func NewClientBuilder(vcsProvider vcsutils.VcsProvider) *ClientBuilder {
return &ClientBuilder{vcsProvider: vcsProvider, logger: EmptyLogger{}}
return &ClientBuilder{vcsProvider: vcsProvider, logger: vcsutils.EmptyLogger{}}
}

// ApiEndpoint sets the API endpoint
Expand All @@ -35,7 +35,7 @@ func (builder *ClientBuilder) Token(token string) *ClientBuilder {
}

// Logger sets the logger
func (builder *ClientBuilder) Logger(logger Log) *ClientBuilder {
func (builder *ClientBuilder) Logger(logger vcsutils.Log) *ClientBuilder {
builder.logger = logger
return builder
}
Expand Down
Loading

0 comments on commit 678003d

Please sign in to comment.