Skip to content

Commit 8b10260

Browse files
authoredMar 24, 2024··
Get method for size limitation on PR content (#133)
1 parent 557b8f1 commit 8b10260

8 files changed

+64
-2
lines changed
 

‎vcsclient/azurerepos.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import (
1919
"time"
2020
)
2121

22-
const defaultAzureBaseUrl = "https://dev.azure.com/"
22+
const (
23+
defaultAzureBaseUrl = "https://dev.azure.com/"
24+
azurePullRequestDetailsSizeLimit = 4000
25+
azurePullRequestCommentSizeLimit = 150000
26+
)
2327

2428
// Azure Devops API version 6
2529
type AzureReposClient struct {
@@ -158,6 +162,14 @@ func (client *AzureReposClient) sendDownloadRepoRequest(ctx context.Context, rep
158162
return
159163
}
160164

165+
func (client *AzureReposClient) GetPullRequestCommentSizeLimit() int {
166+
return azurePullRequestCommentSizeLimit
167+
}
168+
169+
func (client *AzureReposClient) GetPullRequestDetailsSizeLimit() int {
170+
return azurePullRequestDetailsSizeLimit
171+
}
172+
161173
// CreatePullRequest on Azure Repos
162174
func (client *AzureReposClient) CreatePullRequest(ctx context.Context, _, repository, sourceBranch, targetBranch, title, description string) error {
163175
azureReposGitClient, err := client.buildAzureReposClient(ctx)

‎vcsclient/bitbucketcloud.go

+8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ func (client *BitbucketCloudClient) DownloadRepository(ctx context.Context, owne
282282
return vcsutils.CreateDotGitFolderWithRemote(localPath, "origin", repositoryInfo.CloneInfo.HTTP)
283283
}
284284

285+
func (client *BitbucketCloudClient) GetPullRequestCommentSizeLimit() int {
286+
return bitbucketPrContentSizeLimit
287+
}
288+
289+
func (client *BitbucketCloudClient) GetPullRequestDetailsSizeLimit() int {
290+
return bitbucketPrContentSizeLimit
291+
}
292+
285293
// CreatePullRequest on Bitbucket cloud
286294
func (client *BitbucketCloudClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch,
287295
targetBranch, title, description string) error {

‎vcsclient/bitbucketcommon.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"time"
88
)
99

10-
const notSupportedOnBitbucket = "currently not supported on Bitbucket"
10+
const (
11+
notSupportedOnBitbucket = "currently not supported on Bitbucket"
12+
bitbucketPrContentSizeLimit = 32768
13+
)
1114

1215
var (
1316
errLabelsNotSupported = fmt.Errorf("labels are %s", notSupportedOnBitbucket)

‎vcsclient/bitbucketserver.go

+8
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ func (client *BitbucketServerClient) DownloadRepository(ctx context.Context, own
277277
repositoryInfo.CloneInfo.HTTP)
278278
}
279279

280+
func (client *BitbucketServerClient) GetPullRequestCommentSizeLimit() int {
281+
return bitbucketPrContentSizeLimit
282+
}
283+
284+
func (client *BitbucketServerClient) GetPullRequestDetailsSizeLimit() int {
285+
return bitbucketPrContentSizeLimit
286+
}
287+
280288
// CreatePullRequest on Bitbucket server
281289
func (client *BitbucketServerClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch,
282290
title, description string) error {

‎vcsclient/github.go

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
const (
2525
maxRetries = 5
2626
retriesIntervalMilliSecs = 60000
27+
// https://github.com/orgs/community/discussions/27190
28+
githubPrContentSizeLimit = 65536
2729
)
2830

2931
var rateLimitRetryStatuses = []int{http.StatusForbidden, http.StatusTooManyRequests}
@@ -321,6 +323,14 @@ func executeDownloadArchiveFromLink(baseURL string) (*http.Response, error) {
321323
return httpResponse, vcsutils.CheckResponseStatusWithBody(httpResponse, http.StatusOK)
322324
}
323325

326+
func (client *GitHubClient) GetPullRequestCommentSizeLimit() int {
327+
return githubPrContentSizeLimit
328+
}
329+
330+
func (client *GitHubClient) GetPullRequestDetailsSizeLimit() int {
331+
return githubPrContentSizeLimit
332+
}
333+
324334
// CreatePullRequest on GitHub
325335
func (client *GitHubClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch, title, description string) error {
326336
return client.runWithRateLimitRetries(func() (*github.Response, error) {

‎vcsclient/gitlab.go

+8
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ func (client *GitLabClient) DownloadRepository(ctx context.Context, owner, repos
225225
return vcsutils.CreateDotGitFolderWithRemote(localPath, vcsutils.RemoteName, repositoryInfo.CloneInfo.HTTP)
226226
}
227227

228+
func (client *GitLabClient) GetPullRequestCommentSizeLimit() int {
229+
return gitlabMergeRequestCommentSizeLimit
230+
}
231+
232+
func (client *GitLabClient) GetPullRequestDetailsSizeLimit() int {
233+
return gitlabMergeRequestDetailsSizeLimit
234+
}
235+
228236
// CreatePullRequest on GitLab
229237
func (client *GitLabClient) CreatePullRequest(ctx context.Context, owner, repository, sourceBranch, targetBranch,
230238
title, description string) error {

‎vcsclient/gitlabcommon.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ import (
66

77
var errGitLabCodeScanningNotSupported = errors.New("code scanning is not supported on Gitlab")
88
var errGitLabGetRepoEnvironmentInfoNotSupported = errors.New("get repository environment info is currently not supported on Bitbucket")
9+
10+
const (
11+
// https://docs.gitlab.com/ee/api/merge_requests.html#create-mr
12+
gitlabMergeRequestDetailsSizeLimit = 1048576
13+
// https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note
14+
gitlabMergeRequestCommentSizeLimit = 1000000
15+
)

‎vcsclient/vcsclient.go

+6
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ type VcsClient interface {
295295
// refBefore - A VCS reference: commit SHA, branch name, tag name
296296
// refAfter - A VCS reference: commit SHA, branch name, tag name
297297
GetModifiedFiles(ctx context.Context, owner, repository, refBefore, refAfter string) ([]string, error)
298+
299+
// GetPullRequestCommentSizeLimit returns the maximum size of a pull request comment
300+
GetPullRequestCommentSizeLimit() int
301+
302+
// GetPullRequestDetailsSizeLimit returns the maximum size of a pull request details
303+
GetPullRequestDetailsSizeLimit() int
298304
}
299305

300306
// CommitInfo contains the details of a commit

0 commit comments

Comments
 (0)
Please sign in to comment.