From 8b102603458044b434689fc3832e12d30af12d15 Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Sun, 24 Mar 2024 09:56:17 +0200 Subject: [PATCH] Get method for size limitation on PR content (#133) --- vcsclient/azurerepos.go | 14 +++++++++++++- vcsclient/bitbucketcloud.go | 8 ++++++++ vcsclient/bitbucketcommon.go | 5 ++++- vcsclient/bitbucketserver.go | 8 ++++++++ vcsclient/github.go | 10 ++++++++++ vcsclient/gitlab.go | 8 ++++++++ vcsclient/gitlabcommon.go | 7 +++++++ vcsclient/vcsclient.go | 6 ++++++ 8 files changed, 64 insertions(+), 2 deletions(-) diff --git a/vcsclient/azurerepos.go b/vcsclient/azurerepos.go index 7413900e..d9e36de6 100644 --- a/vcsclient/azurerepos.go +++ b/vcsclient/azurerepos.go @@ -19,7 +19,11 @@ import ( "time" ) -const defaultAzureBaseUrl = "https://dev.azure.com/" +const ( + defaultAzureBaseUrl = "https://dev.azure.com/" + azurePullRequestDetailsSizeLimit = 4000 + azurePullRequestCommentSizeLimit = 150000 +) // Azure Devops API version 6 type AzureReposClient struct { @@ -158,6 +162,14 @@ func (client *AzureReposClient) sendDownloadRepoRequest(ctx context.Context, rep return } +func (client *AzureReposClient) GetPullRequestCommentSizeLimit() int { + return azurePullRequestCommentSizeLimit +} + +func (client *AzureReposClient) GetPullRequestDetailsSizeLimit() int { + return azurePullRequestDetailsSizeLimit +} + // CreatePullRequest on Azure Repos func (client *AzureReposClient) CreatePullRequest(ctx context.Context, _, repository, sourceBranch, targetBranch, title, description string) error { azureReposGitClient, err := client.buildAzureReposClient(ctx) diff --git a/vcsclient/bitbucketcloud.go b/vcsclient/bitbucketcloud.go index 335ffff1..a76efd1e 100644 --- a/vcsclient/bitbucketcloud.go +++ b/vcsclient/bitbucketcloud.go @@ -282,6 +282,14 @@ func (client *BitbucketCloudClient) DownloadRepository(ctx context.Context, owne return vcsutils.CreateDotGitFolderWithRemote(localPath, "origin", repositoryInfo.CloneInfo.HTTP) } +func (client *BitbucketCloudClient) GetPullRequestCommentSizeLimit() int { + return bitbucketPrContentSizeLimit +} + +func (client *BitbucketCloudClient) GetPullRequestDetailsSizeLimit() int { + return bitbucketPrContentSizeLimit +} + // CreatePullRequest on Bitbucket cloud func (client *BitbucketCloudClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch, title, description string) error { diff --git a/vcsclient/bitbucketcommon.go b/vcsclient/bitbucketcommon.go index c33c125d..4897cc36 100644 --- a/vcsclient/bitbucketcommon.go +++ b/vcsclient/bitbucketcommon.go @@ -7,7 +7,10 @@ import ( "time" ) -const notSupportedOnBitbucket = "currently not supported on Bitbucket" +const ( + notSupportedOnBitbucket = "currently not supported on Bitbucket" + bitbucketPrContentSizeLimit = 32768 +) var ( errLabelsNotSupported = fmt.Errorf("labels are %s", notSupportedOnBitbucket) diff --git a/vcsclient/bitbucketserver.go b/vcsclient/bitbucketserver.go index 865852c1..34239fd9 100644 --- a/vcsclient/bitbucketserver.go +++ b/vcsclient/bitbucketserver.go @@ -277,6 +277,14 @@ func (client *BitbucketServerClient) DownloadRepository(ctx context.Context, own repositoryInfo.CloneInfo.HTTP) } +func (client *BitbucketServerClient) GetPullRequestCommentSizeLimit() int { + return bitbucketPrContentSizeLimit +} + +func (client *BitbucketServerClient) GetPullRequestDetailsSizeLimit() int { + return bitbucketPrContentSizeLimit +} + // CreatePullRequest on Bitbucket server func (client *BitbucketServerClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch, title, description string) error { diff --git a/vcsclient/github.go b/vcsclient/github.go index 9e2bd112..f02cf3dd 100644 --- a/vcsclient/github.go +++ b/vcsclient/github.go @@ -24,6 +24,8 @@ import ( const ( maxRetries = 5 retriesIntervalMilliSecs = 60000 + // https://github.com/orgs/community/discussions/27190 + githubPrContentSizeLimit = 65536 ) var rateLimitRetryStatuses = []int{http.StatusForbidden, http.StatusTooManyRequests} @@ -321,6 +323,14 @@ func executeDownloadArchiveFromLink(baseURL string) (*http.Response, error) { return httpResponse, vcsutils.CheckResponseStatusWithBody(httpResponse, http.StatusOK) } +func (client *GitHubClient) GetPullRequestCommentSizeLimit() int { + return githubPrContentSizeLimit +} + +func (client *GitHubClient) GetPullRequestDetailsSizeLimit() int { + return githubPrContentSizeLimit +} + // CreatePullRequest on GitHub func (client *GitHubClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch, title, description string) error { return client.runWithRateLimitRetries(func() (*github.Response, error) { diff --git a/vcsclient/gitlab.go b/vcsclient/gitlab.go index d5b59b0f..48b5a767 100644 --- a/vcsclient/gitlab.go +++ b/vcsclient/gitlab.go @@ -225,6 +225,14 @@ func (client *GitLabClient) DownloadRepository(ctx context.Context, owner, repos return vcsutils.CreateDotGitFolderWithRemote(localPath, vcsutils.RemoteName, repositoryInfo.CloneInfo.HTTP) } +func (client *GitLabClient) GetPullRequestCommentSizeLimit() int { + return gitlabMergeRequestCommentSizeLimit +} + +func (client *GitLabClient) GetPullRequestDetailsSizeLimit() int { + return gitlabMergeRequestDetailsSizeLimit +} + // CreatePullRequest on GitLab func (client *GitLabClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch, title, description string) error { diff --git a/vcsclient/gitlabcommon.go b/vcsclient/gitlabcommon.go index 47d06e23..ebac8720 100644 --- a/vcsclient/gitlabcommon.go +++ b/vcsclient/gitlabcommon.go @@ -6,3 +6,10 @@ import ( var errGitLabCodeScanningNotSupported = errors.New("code scanning is not supported on Gitlab") var errGitLabGetRepoEnvironmentInfoNotSupported = errors.New("get repository environment info is currently not supported on Bitbucket") + +const ( + // https://docs.gitlab.com/ee/api/merge_requests.html#create-mr + gitlabMergeRequestDetailsSizeLimit = 1048576 + // https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note + gitlabMergeRequestCommentSizeLimit = 1000000 +) diff --git a/vcsclient/vcsclient.go b/vcsclient/vcsclient.go index 6c3d4366..4b6b9a65 100644 --- a/vcsclient/vcsclient.go +++ b/vcsclient/vcsclient.go @@ -295,6 +295,12 @@ type VcsClient interface { // refBefore - A VCS reference: commit SHA, branch name, tag name // refAfter - A VCS reference: commit SHA, branch name, tag name GetModifiedFiles(ctx context.Context, owner, repository, refBefore, refAfter string) ([]string, error) + + // GetPullRequestCommentSizeLimit returns the maximum size of a pull request comment + GetPullRequestCommentSizeLimit() int + + // GetPullRequestDetailsSizeLimit returns the maximum size of a pull request details + GetPullRequestDetailsSizeLimit() int } // CommitInfo contains the details of a commit