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

Commit708a8b2

Browse files
authored
AddListPullRequestReviews &ListPullRequestsAssociatedWithCommit (#145)
1 parentd5b6210 commit708a8b2

21 files changed

+1338
-194
lines changed

‎README.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Currently supported providers are: [GitHub](#github), [Bitbucket Server](#bitbuc
3333
-[Test Connection](#test-connection)
3434
-[List Repositories](#list-repositories)
3535
-[List Branches](#list-branches)
36+
-[List Pull Request Reviews](#list-pull-request-reviews)
3637
-[Download Repository](#download-repository)
3738
-[Create Webhook](#create-webhook)
3839
-[Update Webhook](#update-webhook)
@@ -54,6 +55,7 @@ Currently supported providers are: [GitHub](#github), [Bitbucket Server](#bitbuc
5455
-[Get Commits With Options](#get-commits-with-options)
5556
-[Get Latest Commit](#get-latest-commit)
5657
-[Get Commit By SHA](#get-commit-by-sha)
58+
-[List Pull Requests associated with a Commit](#list-pull-requests-associated-with-a-commit)
5759
-[Get List of Modified Files](#get-list-of-modified-files)
5860
-[Add Public SSH Key](#add-public-ssh-key)
5961
-[Get Repository Info](#get-repository-info)
@@ -205,6 +207,22 @@ repository := "jfrog-cli"
205207
repositoryBranches,err:= client.ListBranches(ctx, owner, repository)
206208
```
207209

210+
####List Pull Request Reviews
211+
212+
```go
213+
// Go context
214+
ctx:= context.Background()
215+
// Organization or username
216+
owner:="jfrog"
217+
// VCS repository
218+
repository:="jfrog-cli"
219+
// Pull Request ID
220+
pullRequestID:=1
221+
222+
// List all reviews for pull request 1
223+
reviews,err:= client.ListPullRequestReviews(ctx, owner, repository, pullRequestID)
224+
```
225+
208226
####Download Repository
209227

210228
```go
@@ -600,6 +618,21 @@ sha := "abcdef0123abcdef4567abcdef8987abcdef6543"
600618
commitInfo,err:= client.GetCommitBySha(ctx, owner, repository, sha)
601619
```
602620

621+
###
622+
```go
623+
// Go context
624+
ctx:= context.Background()
625+
// Organization or username
626+
owner:="jfrog"
627+
// VCS repository
628+
repository:="jfrog-cli"
629+
// Commit SHA
630+
commitSHA:="abcdef0123abcdef4567abcdef8987abcdef6543"
631+
632+
// List pull requests associated with a specific commit
633+
pullRequests,err:= client.ListPullRequestsAssociatedWithCommit(ctx, owner, repository, commitSHA)
634+
```
635+
603636
####Get List of Modified Files
604637

605638
The`refBefore...refAfter` syntax is used.

‎vcsclient/azurerepos.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"net/http"
1616
"os"
1717
"sort"
18+
"strconv"
1819
"strings"
1920
"time"
2021
)
@@ -265,6 +266,41 @@ func getThreadArgs(repository, project string, prId int, comment PullRequestComm
265266
}
266267
}
267268

269+
func (client*AzureReposClient)ListPullRequestReviews(ctx context.Context,owner,repositorystring,pullRequestIDint) ([]PullRequestReviewDetails,error) {
270+
azureReposGitClient,err:=client.buildAzureReposClient(ctx)
271+
iferr!=nil {
272+
returnnil,err
273+
}
274+
275+
reviewers,err:=azureReposGitClient.GetPullRequestReviewers(ctx, git.GetPullRequestReviewersArgs{
276+
RepositoryId:&repository,
277+
PullRequestId:&pullRequestID,
278+
Project:&client.vcsInfo.Project,
279+
})
280+
iferr!=nil {
281+
returnnil,err
282+
}
283+
284+
varreviews []PullRequestReviewDetails
285+
for_,reviewer:=range*reviewers {
286+
id,err:=strconv.ParseInt(*reviewer.Id,10,64)
287+
iferr!=nil {
288+
returnnil,err
289+
}
290+
reviews=append(reviews,PullRequestReviewDetails{
291+
ID:id,
292+
Reviewer:*reviewer.DisplayName,
293+
State:mapVoteToState(*reviewer.Vote),
294+
})
295+
}
296+
297+
returnreviews,nil
298+
}
299+
300+
func (client*AzureReposClient)ListPullRequestsAssociatedWithCommit(ctx context.Context,owner,repositorystring,commitSHAstring) ([]PullRequestInfo,error) {
301+
returnnil,getUnsupportedInAzureError("list pull requests associated with commit")
302+
}
303+
268304
// ListPullRequestReviewComments on Azure Repos
269305
func (client*AzureReposClient)ListPullRequestReviewComments(ctx context.Context,owner,repositorystring,pullRequestIDint) ([]CommentInfo,error) {
270306
returnclient.ListPullRequestComments(ctx,owner,repository,pullRequestID)
@@ -780,3 +816,18 @@ func azureMapPullRequestState(state vcsutils.PullRequestState) *git.PullRequestS
780816
returnnil
781817
}
782818
}
819+
820+
funcmapVoteToState(voteint)string {
821+
switchvote {
822+
case10:
823+
return"APPROVED"
824+
case5:
825+
return"APPROVED_WITH_SUGGESTIONS"
826+
case-5:
827+
return"CHANGES_REQUESTED"
828+
case-10:
829+
return"REJECTED"
830+
default:
831+
return"UNKNOWN"
832+
}
833+
}

‎vcsclient/azurerepos_test.go‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,62 @@ func TestListPullRequestReviewComments(t *testing.T) {
403403
TestListPullRequestComments(t)
404404
}
405405

406+
funcTestAzureRepos_ListPullRequestReviews(t*testing.T) {
407+
ctx:=context.Background()
408+
repository:="repo"
409+
pullRequestID:=1
410+
mockResponse:=struct {
411+
Countint
412+
Value []git.IdentityRefWithVote
413+
}{
414+
Count:2,
415+
Value: []git.IdentityRefWithVote{
416+
{
417+
ReviewerUrl:vcsutils.PointerOf("https://dev.azure.com/owner/project/_apis/git/repositories/repo/pullRequests/1/reviewers/1"),
418+
Vote:vcsutils.PointerOf(10),
419+
DisplayName:vcsutils.PointerOf("Reviewer One"),
420+
Id:vcsutils.PointerOf("1"),
421+
},
422+
{
423+
ReviewerUrl:vcsutils.PointerOf("https://dev.azure.com/owner/project/_apis/git/repositories/repo/pullRequests/1/reviewers/2"),
424+
Vote:vcsutils.PointerOf(-5),
425+
DisplayName:vcsutils.PointerOf("Reviewer Two"),
426+
Id:vcsutils.PointerOf("2"),
427+
},
428+
},
429+
}
430+
responseBytes,err:=json.Marshal(mockResponse)
431+
assert.NoError(t,err)
432+
433+
client,cleanUp:=createServerAndClient(t,vcsutils.AzureRepos,true,responseBytes,
434+
fmt.Sprintf("/_apis/git/repositories/%s/pullRequests/%d/reviewers",repository,pullRequestID),createAzureReposHandler)
435+
defercleanUp()
436+
437+
result,err:=client.ListPullRequestReviews(ctx,owner,repository,pullRequestID)
438+
assert.NoError(t,err)
439+
assert.Len(t,result,2)
440+
assert.Equal(t,PullRequestReviewDetails{
441+
ID:1,
442+
Reviewer:"Reviewer One",
443+
State:"APPROVED",
444+
},result[0])
445+
assert.Equal(t,PullRequestReviewDetails{
446+
ID:2,
447+
Reviewer:"Reviewer Two",
448+
State:"CHANGES_REQUESTED",
449+
},result[1])
450+
}
451+
funcTestAzureRepos_ListPullRequestsAssociatedWithCommit(t*testing.T) {
452+
ctx:=context.Background()
453+
repository:="repo"
454+
commitSHA:="commitSHA"
455+
client,cleanUp:=createServerAndClient(t,vcsutils.AzureRepos,true,nil,
456+
fmt.Sprintf("/_apis/git/repositories/%s/commits/%s/pullRequests",repository,commitSHA),createAzureReposHandler)
457+
defercleanUp()
458+
459+
_,err:=client.ListPullRequestsAssociatedWithCommit(ctx,owner,repository,commitSHA)
460+
assert.Error(t,err)
461+
}
406462
funcTestListPullRequestComments(t*testing.T) {
407463
typeListPullRequestCommentsResponsestruct {
408464
Value []git.GitPullRequestCommentThread

‎vcsclient/bitbucketcloud.go‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,47 @@ func (client *BitbucketCloudClient) ListPullRequestReviewComments(_ context.Cont
428428
returnnil,errBitbucketListPullRequestReviewCommentsNotSupported
429429
}
430430

431+
func (client*BitbucketCloudClient)ListPullRequestReviews(ctx context.Context,owner,repositorystring,pullRequestIDint) ([]PullRequestReviewDetails,error) {
432+
err:=validateParametersNotBlank(map[string]string{"owner":owner,"repository":repository})
433+
iferr!=nil {
434+
returnnil,err
435+
}
436+
437+
bitbucketClient:=client.buildBitbucketCloudClient(ctx)
438+
options:=&bitbucket.PullRequestsOptions{
439+
Owner:owner,
440+
RepoSlug:repository,
441+
ID:fmt.Sprint(pullRequestID),
442+
}
443+
444+
comments,err:=bitbucketClient.Repositories.PullRequests.GetComments(options)
445+
iferr!=nil {
446+
returnnil,err
447+
}
448+
449+
parsedComments,err:=vcsutils.RemapFields[commentsResponse](comments,"json")
450+
iferr!=nil {
451+
returnnil,err
452+
}
453+
454+
varreviewInfos []PullRequestReviewDetails
455+
for_,comment:=rangeparsedComments.Values {
456+
reviewInfos=append(reviewInfos,PullRequestReviewDetails{
457+
ID:comment.ID,
458+
Reviewer:comment.User.DisplayName,
459+
Body:comment.Content.Raw,
460+
SubmittedAt:comment.Created.Format(time.RFC3339),
461+
CommitID:"",// Bitbucket Cloud comments do not have a commit ID
462+
})
463+
}
464+
465+
returnreviewInfos,nil
466+
}
467+
468+
func (client*BitbucketCloudClient)ListPullRequestsAssociatedWithCommit(ctx context.Context,owner,repository,commitSHAstring) ([]PullRequestInfo,error) {
469+
returnnil,errBitbucketListPullRequestAssociatedCommitsNotSupported
470+
}
471+
431472
// ListPullRequestComments on Bitbucket cloud
432473
func (client*BitbucketCloudClient)ListPullRequestComments(ctx context.Context,owner,repositorystring,pullRequestIDint) (res []CommentInfo,errerror) {
433474
err=validateParametersNotBlank(map[string]string{"owner":owner,"repository":repository})

‎vcsclient/bitbucketcloud_test.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,40 @@ func TestBitbucketCloudClient_GetCommitStatus(t *testing.T) {
621621
})
622622
}
623623

624+
funcTestBitbucketCloud_ListPullRequestReviews(t*testing.T) {
625+
ctx:=context.Background()
626+
response,err:=os.ReadFile(filepath.Join("testdata","bitbucketcloud","pull_request_reviews_response.json"))
627+
assert.NoError(t,err)
628+
629+
client,cleanUp:=createServerAndClient(t,vcsutils.BitbucketCloud,true,response,
630+
fmt.Sprintf("/repositories/%s/%s/pullrequests/%d/comments/",owner,repo1,1),createBitbucketCloudHandler)
631+
defercleanUp()
632+
633+
result,err:=client.ListPullRequestReviews(ctx,owner,repo1,1)
634+
assert.NoError(t,err)
635+
assert.Len(t,result,2)
636+
assert.Equal(t,PullRequestReviewDetails{
637+
ID:301545835,
638+
Reviewer:"user",
639+
Body:"I’m a comment",
640+
SubmittedAt:"2022-05-16T11:04:07Z",
641+
CommitID:"",
642+
},result[0])
643+
}
644+
645+
funcTestBitbucketCloud_ListPullRequestsAssociatedWithCommit(t*testing.T) {
646+
ctx:=context.Background()
647+
response,err:=os.ReadFile(filepath.Join("testdata","bitbucketcloud","pull_requests_associated_with_commit_response.json"))
648+
assert.NoError(t,err)
649+
650+
client,cleanUp:=createServerAndClient(t,vcsutils.BitbucketCloud,true,response,
651+
fmt.Sprintf("/repositories/%s/%s/commit/%s/pullrequests",owner,repo1,"commitSHA"),createBitbucketCloudHandler)
652+
defercleanUp()
653+
654+
_,err=client.ListPullRequestsAssociatedWithCommit(ctx,owner,repo1,"commitSHA")
655+
assert.ErrorIs(t,err,errBitbucketListPullRequestAssociatedCommitsNotSupported)
656+
}
657+
624658
funcTestSplitWorkSpaceAndOwner(t*testing.T) {
625659
valid:="work/repo"
626660
workspace,repo:=splitBitbucketCloudRepoName(valid)

‎vcsclient/bitbucketcommon.go‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ const (
1313
)
1414

1515
var (
16-
errLabelsNotSupported=fmt.Errorf("labels are %s",notSupportedOnBitbucket)
17-
errBitbucketCodeScanningNotSupported=fmt.Errorf("code scanning is %s",notSupportedOnBitbucket)
18-
errBitbucketDownloadFileFromRepoNotSupported=fmt.Errorf("download file from repo is %s",notSupportedOnBitbucket)
19-
errBitbucketGetCommitsNotSupported=fmt.Errorf("get commits is %s",notSupportedOnBitbucket)
20-
errBitbucketGetCommitsWithOptionsNotSupported=fmt.Errorf("get commits with options is %s",notSupportedOnBitbucket)
21-
errBitbucketGetRepoEnvironmentInfoNotSupported=fmt.Errorf("get repository environment info is %s",notSupportedOnBitbucket)
22-
errBitbucketListPullRequestReviewCommentsNotSupported=fmt.Errorf("list pull request review comments is %s",notSupportedOnBitbucket)
23-
errBitbucketAddPullRequestReviewCommentsNotSupported=fmt.Errorf("add pull request review comment is %s",notSupportedOnBitbucket)
24-
errBitbucketDeletePullRequestComment=fmt.Errorf("delete pull request comment is %s",notSupportedOnBitbucket)
16+
errLabelsNotSupported=fmt.Errorf("labels are %s",notSupportedOnBitbucket)
17+
errBitbucketCodeScanningNotSupported=fmt.Errorf("code scanning is %s",notSupportedOnBitbucket)
18+
errBitbucketDownloadFileFromRepoNotSupported=fmt.Errorf("download file from repo is %s",notSupportedOnBitbucket)
19+
errBitbucketGetCommitsNotSupported=fmt.Errorf("get commits is %s",notSupportedOnBitbucket)
20+
errBitbucketGetCommitsWithOptionsNotSupported=fmt.Errorf("get commits with options is %s",notSupportedOnBitbucket)
21+
errBitbucketGetRepoEnvironmentInfoNotSupported=fmt.Errorf("get repository environment info is %s",notSupportedOnBitbucket)
22+
errBitbucketListPullRequestReviewCommentsNotSupported=fmt.Errorf("list pull request review comments is %s",notSupportedOnBitbucket)
23+
errBitbucketAddPullRequestReviewCommentsNotSupported=fmt.Errorf("add pull request review comment is %s",notSupportedOnBitbucket)
24+
errBitbucketDeletePullRequestComment=fmt.Errorf("delete pull request comment is %s",notSupportedOnBitbucket)
25+
errBitbucketListPullRequestAssociatedCommitsNotSupported=fmt.Errorf("list pull requests associated commits is %s",notSupportedOnBitbucket)
26+
errBitbucketListListPullRequestReviewsNotSupported=fmt.Errorf("list pull request reviews is %s",notSupportedOnBitbucket)
2527
)
2628

2729
typeBitbucketCommitInfostruct {

‎vcsclient/bitbucketserver.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ func (client *BitbucketServerClient) DeletePullRequestReviewComments(ctx context
499499
returnnil
500500
}
501501

502+
func (client*BitbucketServerClient)ListPullRequestReviews(ctx context.Context,owner,repositorystring,pullRequestIDint) ([]PullRequestReviewDetails,error) {
503+
returnnil,errBitbucketListListPullRequestReviewsNotSupported
504+
}
505+
506+
func (client*BitbucketServerClient)ListPullRequestsAssociatedWithCommit(ctx context.Context,owner,repositorystring,commitSHAstring) ([]PullRequestInfo,error) {
507+
returnnil,errBitbucketListPullRequestAssociatedCommitsNotSupported
508+
}
509+
502510
// DeletePullRequestComment on Bitbucket Server
503511
func (client*BitbucketServerClient)DeletePullRequestComment(ctx context.Context,owner,repositorystring,pullRequestID,commentIDint)error {
504512
bitbucketClient:=client.buildBitbucketClient(ctx)

‎vcsclient/bitbucketserver_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ func TestBitbucketServer_DeleteWebhook(t *testing.T) {
133133
assert.Error(t,err)
134134
}
135135

136+
funcTestBitbucketServer_ListPullRequestReviews(t*testing.T) {
137+
ctx:=context.Background()
138+
client,cleanUp:=createServerAndClient(t,vcsutils.BitbucketServer,true,nil,
139+
fmt.Sprintf("/rest/api/1.0/projects/%s/repos/%s/pull-requests/%d/reviewers",owner,repo1,1),createBitbucketServerHandler)
140+
defercleanUp()
141+
_,err:=client.ListPullRequestReviews(ctx,owner,repo1,1)
142+
assert.ErrorIs(t,err,errBitbucketListListPullRequestReviewsNotSupported)
143+
}
144+
145+
funcTestBitbucketServer_ListPullRequestsAssociatedWithCommit(t*testing.T) {
146+
ctx:=context.Background()
147+
client,cleanUp:=createServerAndClient(t,vcsutils.BitbucketServer,true,nil,
148+
fmt.Sprintf("/rest/api/1.0/projects/%s/repos/%s/commits/%s/pull-requests",owner,repo1,"commitSHA"),createBitbucketServerHandler)
149+
defercleanUp()
150+
_,err:=client.ListPullRequestsAssociatedWithCommit(ctx,owner,repo1,"commitSHA")
151+
assert.ErrorIs(t,err,errBitbucketListPullRequestAssociatedCommitsNotSupported)
152+
}
153+
136154
funcTestBitbucketServer_SetCommitStatus(t*testing.T) {
137155
ctx:=context.Background()
138156
ref:="9caf1c431fb783b669f0f909bd018b40f2ea3808"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp