Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit110f7d1

Browse files
authored
Added create PR with detailed data returned to the func (#155)
1 parent052bb2b commit110f7d1

File tree

10 files changed

+107
-4
lines changed

10 files changed

+107
-4
lines changed

‎README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Currently supported providers are: [GitHub](#github), [Bitbucket Server](#bitbuc
7575
-[Create Or Update Environment](#create-or-update-environment)
7676
-[CommitAndPushFiles](#commit-and-push-files)
7777
-[Merge Pull Request](#merge-pull-request)
78+
-[Create Pull Request Detailed](#create-pull-request-detailed)
7879
-[Webhook Parser](#webhook-parser)
7980

8081
###VCS Clients
@@ -1016,6 +1017,30 @@ commitMessage := "example commit message"
10161017
err = client.MergePullRequest(ctx, owner, repo, prNumber, commitMessage)
10171018
```
10181019

1020+
####Create Pull Request Detailed
1021+
1022+
Notice - Create Pull Request Detailed is currently supported on GitHub only.
1023+
1024+
```go
1025+
// Go context
1026+
ctx:= context.Background()
1027+
// Organization or username
1028+
owner:="jfrog"
1029+
// VCS repository
1030+
repository:="jfrog-cli"
1031+
// Source pull request branch
1032+
sourceBranch:="dev"
1033+
// Target pull request branch
1034+
targetBranch:="main"
1035+
// Pull request title
1036+
title:="Pull request title"
1037+
// Pull request description
1038+
description:="Pull request description"
1039+
1040+
// Creates a pull request and returns its number and URL.
1041+
prInfo,err:= client.CreatePullRequestDetailed(ctx, owner, repository, sourceBranch, targetBranch, title, description)
1042+
```
1043+
10191044
###Webhook Parser
10201045

10211046
```go

‎vcsclient/azurerepos.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,10 @@ func (client *AzureReposClient) MergePullRequest(ctx context.Context, owner, rep
776776
returngetUnsupportedInAzureError("merge pull request")
777777
}
778778

779+
func (client*AzureReposClient)CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error) {
780+
returnCreatedPullRequestInfo{},getUnsupportedInAzureError("create pull request detailed")
781+
}
782+
779783
funcparsePullRequestDetails(client*AzureReposClient,pullRequest git.GitPullRequest,owner,repositorystring,withBodybool)PullRequestInfo {
780784
// Trim the branches prefix and get the actual branches name
781785
shortSourceName:=plumbing.ReferenceName(*pullRequest.SourceRefName).Short()

‎vcsclient/bitbucketcloud.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,10 @@ func (client *BitbucketCloudClient) MergePullRequest(ctx context.Context, owner,
735735
returnerrBitbucketMergePullRequestNotSupported
736736
}
737737

738+
func (client*BitbucketCloudClient)CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error) {
739+
returnCreatedPullRequestInfo{},errBitbucketCreatePullRequestDetailedNotSupported
740+
}
741+
738742
typepullRequestsResponsestruct {
739743
Values []pullRequestsDetails`json:"values"`
740744
}

‎vcsclient/bitbucketcommon.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
errBitbucketCreateOrUpdateEnvironmentNotSupported=fmt.Errorf("create or update environment is %s",notSupportedOnBitbucket)
3434
errBitbucketMergePullRequestNotSupported=fmt.Errorf("merge pull request is %s",notSupportedOnBitbucket)
3535
errBitbucketListAppReposNotSupported=fmt.Errorf("list app repositories is %s",notSupportedOnBitbucket)
36+
errBitbucketCreatePullRequestDetailedNotSupported=fmt.Errorf("creating pull request detailed is %s",notSupportedOnBitbucket)
3637
)
3738

3839
typeBitbucketCommitInfostruct {

‎vcsclient/bitbucketserver.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,10 @@ func (client *BitbucketServerClient) MergePullRequest(ctx context.Context, owner
927927
returnerrBitbucketMergePullRequestNotSupported
928928
}
929929

930+
func (client*BitbucketServerClient)CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error) {
931+
returnCreatedPullRequestInfo{},errBitbucketCreatePullRequestDetailedNotSupported
932+
}
933+
930934
funcgetBitbucketServerRepositoryVisibility(publicbool)RepositoryVisibility {
931935
ifpublic {
932936
returnPublic

‎vcsclient/github.go‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,45 @@ func (client *GitHubClient) GetPullRequestDetailsSizeLimit() int {
341341
// CreatePullRequest on GitHub
342342
func (client*GitHubClient)CreatePullRequest(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring)error {
343343
returnclient.runWithRateLimitRetries(func() (*github.Response,error) {
344-
returnclient.executeCreatePullRequest(ctx,owner,repository,sourceBranch,targetBranch,title,description)
344+
_,githubResponse,err:=client.executeCreatePullRequest(ctx,owner,repository,sourceBranch,targetBranch,title,description)
345+
returngithubResponse,err
345346
})
346347
}
347348

348-
func (client*GitHubClient)executeCreatePullRequest(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (*github.Response,error) {
349+
func (client*GitHubClient)CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error) {
350+
varprInfoCreatedPullRequestInfo
351+
352+
err:=client.runWithRateLimitRetries(func() (*github.Response,error) {
353+
pr,ghResponse,err:=client.executeCreatePullRequest(ctx,owner,repository,sourceBranch,targetBranch,title,description)
354+
iferr!=nil {
355+
returnghResponse,err
356+
}
357+
prInfo=mapToPullRequestInfo(pr)
358+
returnghResponse,nil
359+
})
360+
361+
returnprInfo,err
362+
}
363+
364+
func (client*GitHubClient)executeCreatePullRequest(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (*github.PullRequest,*github.Response,error) {
349365
head:=owner+":"+sourceBranch
350366
client.logger.Debug(vcsutils.CreatingPullRequest,title)
351367

352-
_,ghResponse,err:=client.ghClient.PullRequests.Create(ctx,owner,repository,&github.NewPullRequest{
368+
pr,ghResponse,err:=client.ghClient.PullRequests.Create(ctx,owner,repository,&github.NewPullRequest{
353369
Title:&title,
354370
Body:&description,
355371
Head:&head,
356372
Base:&targetBranch,
357373
})
358-
returnghResponse,err
374+
returnpr,ghResponse,err
375+
}
376+
377+
funcmapToPullRequestInfo(pr*github.PullRequest)CreatedPullRequestInfo {
378+
returnCreatedPullRequestInfo{
379+
Number:pr.GetNumber(),
380+
URL:pr.GetHTMLURL(),
381+
StatusesUrl:pr.GetStatusesURL(),
382+
}
359383
}
360384

361385
// UpdatePullRequest on GitHub
@@ -1003,6 +1027,7 @@ func (client *GitHubClient) DownloadFileFromRepo(ctx context.Context, owner, rep
10031027
content,statusCode,ghResponse,err=client.executeDownloadFileFromRepo(ctx,owner,repository,branch,path)
10041028
returnghResponse,err
10051029
})
1030+
10061031
return
10071032
}
10081033

‎vcsclient/github_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,22 @@ func TestGitHubClient_MergePullRequest(t *testing.T) {
12031203
assert.Error(t,err)
12041204
}
12051205

1206+
funcTestGitHubClient_CreatePullRequestDetailed(t*testing.T) {
1207+
ctx:=context.Background()
1208+
expectedURL:="https://github.com/jfrog/repo1/pull/875"
1209+
expectedPrNumber:=1234
1210+
client,cleanUp:=createServerAndClient(t,vcsutils.GitHub,false, github.PullRequest{Number:github.Int(expectedPrNumber),HTMLURL:github.String(expectedURL)},"/repos/jfrog/repo-1/pulls",createGitHubHandler)
1211+
defercleanUp()
1212+
1213+
prInfo,err:=client.CreatePullRequestDetailed(ctx,owner,repo1,branch1,branch2,"PR title","PR body")
1214+
assert.NoError(t,err)
1215+
assert.Equal(t,expectedPrNumber,prInfo.Number)
1216+
assert.Equal(t,expectedURL,prInfo.URL)
1217+
1218+
_,err=createBadGitHubClient(t).CreatePullRequestDetailed(ctx,owner,repo1,branch1,branch2,"PR title","PR body")
1219+
assert.Error(t,err)
1220+
}
1221+
12061222
funccreateBadGitHubClient(t*testing.T)VcsClient {
12071223
client,err:=NewClientBuilder(vcsutils.GitHub).ApiEndpoint("https://badendpoint").Build()
12081224
assert.NoError(t,err)

‎vcsclient/gitlab.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,10 @@ func (client *GitLabClient) MergePullRequest(ctx context.Context, owner, repo st
815815
returnerrGitLabMergePullRequestNotSupported
816816
}
817817

818+
func (client*GitLabClient)CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error) {
819+
returnCreatedPullRequestInfo{},errGitlabCreatePullRequestDetailedNotSupported
820+
}
821+
818822
funcgetProjectID(owner,projectstring)string {
819823
returnfmt.Sprintf("%s/%s",owner,project)
820824
}

‎vcsclient/gitlabcommon.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var errGitLabGetRepoTeamsByPermissionsNotSupported = errors.New("get repository
1515
varerrGitLabCreateOrUpdateEnvironmentNotSupported=errors.New("create or update environment is not supported on Gitlab")
1616
varerrGitLabMergePullRequestNotSupported=errors.New("merging pull request is not supported on Gitlab")
1717
varerrGitLabListAppRepositories=errors.New("list app repositories is not supported on GitLab")
18+
varerrGitlabCreatePullRequestDetailedNotSupported=errors.New("creating pull request detailed is not supported on Gitlab")
1819

1920
const (
2021
// https://docs.gitlab.com/ee/api/merge_requests.html#create-mr

‎vcsclient/vcsclient.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ type AppRepositoryInfo struct {
101101
DefaultBranchstring
102102
}
103103

104+
// CreatedPullRequestInfo contains the data returned from a pull request creation
105+
// Number - The number of the pull request
106+
// URL - The URL of the pull request
107+
// StatusesUrl - The URL to the commit statuses of the pull request
108+
typeCreatedPullRequestInfostruct {
109+
Numberint
110+
URLstring
111+
StatusesUrlstring
112+
}
113+
104114
// VcsClient is a base class of all Vcs clients - GitHub, GitLab, Bitbucket server and cloud clients
105115
typeVcsClientinterface {
106116
// TestConnection Returns nil if connection and authorization established successfully
@@ -174,6 +184,15 @@ type VcsClient interface {
174184
// description - Pull request description
175185
CreatePullRequest(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring)error
176186

187+
// CreatePullRequestDetailed Creates a pull request between 2 different branches in the same repository
188+
// owner - User or organization
189+
// repository - VCS repository name
190+
// sourceBranch - Source branch
191+
// targetBranch - Target branch
192+
// title - Pull request title
193+
// description - Pull request description
194+
CreatePullRequestDetailed(ctx context.Context,owner,repository,sourceBranch,targetBranch,title,descriptionstring) (CreatedPullRequestInfo,error)
195+
177196
// UpdatePullRequest Updates pull requests metadata
178197
// owner - User or organization
179198
// repository - VCS repository name

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp