Skip to content

Commit

Permalink
Get method for size limitation on PR content (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored Mar 24, 2024
1 parent 557b8f1 commit 8b10260
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 deletions.
14 changes: 13 additions & 1 deletion vcsclient/azurerepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions vcsclient/bitbucketcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion vcsclient/bitbucketcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions vcsclient/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions vcsclient/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions vcsclient/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions vcsclient/gitlabcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 6 additions & 0 deletions vcsclient/vcsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b10260

Please sign in to comment.