Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListPullRequestReviews & ListPullRequestsAssociatedWithCommit #145

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions vcsclient/azurerepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ type AzureReposClient struct {
logger vcsutils.Log
}

func (client *AzureReposClient) ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error) {
// TODO implement me
panic("implement me")
}

func (client *AzureReposClient) ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error) {
// TODO implement me
panic("implement me")
}

// NewAzureReposClient create a new AzureReposClient
func NewAzureReposClient(vcsInfo VcsInfo, logger vcsutils.Log) (*AzureReposClient, error) {
client := &AzureReposClient{vcsInfo: vcsInfo, logger: logger}
Expand Down
10 changes: 10 additions & 0 deletions vcsclient/bitbucketcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ type BitbucketCloudClient struct {
logger vcsutils.Log
}

func (client *BitbucketCloudClient) ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error) {
// TODO implement me
panic("implement me")
}

func (client *BitbucketCloudClient) ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error) {
// TODO implement me
panic("implement me")
}

// NewBitbucketCloudClient create a new BitbucketCloudClient
func NewBitbucketCloudClient(vcsInfo VcsInfo, logger vcsutils.Log) (*BitbucketCloudClient, error) {
bitbucketClient := &BitbucketCloudClient{
Expand Down
10 changes: 10 additions & 0 deletions vcsclient/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ type BitbucketServerClient struct {
logger vcsutils.Log
}

func (client *BitbucketServerClient) ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error) {
// TODO implement me
panic("implement me")
}

func (client *BitbucketServerClient) ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error) {
// TODO implement me
panic("implement me")
}

// NewBitbucketServerClient create a new BitbucketServerClient
func NewBitbucketServerClient(vcsInfo VcsInfo, logger vcsutils.Log) (*BitbucketServerClient, error) {
bitbucketServerClient := &BitbucketServerClient{
Expand Down
45 changes: 45 additions & 0 deletions vcsclient/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,38 @@ func (client *GitHubClient) ListPullRequestReviewComments(ctx context.Context, o
return commentsInfoList, err
}

// ListPullRequestReviews on GitHub
func (client *GitHubClient) ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error) {
err := validateParametersNotBlank(map[string]string{"owner": owner, "repository": repository})
if err != nil {
return nil, err
}

var reviews []*github.PullRequestReview
err = client.runWithRateLimitRetries(func() (*github.Response, error) {
var ghResponse *github.Response
reviews, ghResponse, err = client.ghClient.PullRequests.ListReviews(ctx, owner, repository, pullRequestID, nil)
return ghResponse, err
})
if err != nil {
return nil, err
}

var reviewInfos []PullRequestReviewDetails
for _, review := range reviews {
reviewInfos = append(reviewInfos, PullRequestReviewDetails{
ID: review.GetID(),
Reviewer: review.GetUser().GetLogin(),
Body: review.GetBody(),
State: review.GetState(),
SubmittedAt: review.GetSubmittedAt().String(),
CommitID: review.GetCommitID(),
})
}

return reviewInfos, nil
}

func (client *GitHubClient) executeListPullRequestReviewComments(ctx context.Context, owner, repository string, pullRequestID int) ([]CommentInfo, *github.Response, error) {
commentsList, ghResponse, err := client.ghClient.PullRequests.ListComments(ctx, owner, repository, pullRequestID, nil)
if err != nil {
Expand Down Expand Up @@ -871,6 +903,19 @@ func (client *GitHubClient) ListPullRequestLabels(ctx context.Context, owner, re
return results, nil
}

func (client *GitHubClient) ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error) {
err := validateParametersNotBlank(map[string]string{"owner": owner, "repository": repository})
if err != nil {
return nil, err
}

pulls, _, err := client.ghClient.PullRequests.ListPullRequestsWithCommit(ctx, owner, repository, commitSHA, nil)
if err != nil {
return nil, err
}
return mapGitHubPullRequestToPullRequestInfoList(pulls, false)
}

// UnlabelPullRequest on GitHub
func (client *GitHubClient) UnlabelPullRequest(ctx context.Context, owner, repository, name string, pullRequestID int) error {
err := validateParametersNotBlank(map[string]string{"owner": owner, "repository": repository})
Expand Down
10 changes: 10 additions & 0 deletions vcsclient/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ type GitLabClient struct {
logger vcsutils.Log
}

func (client *GitLabClient) ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error) {
// TODO implement me
panic("implement me")
}

func (client *GitLabClient) ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error) {
// TODO implement me
panic("implement me")
}

// NewGitLabClient create a new GitLabClient
func NewGitLabClient(vcsInfo VcsInfo, logger vcsutils.Log) (*GitLabClient, error) {
var client *gitlab.Client
Expand Down
22 changes: 22 additions & 0 deletions vcsclient/vcsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ type VcsClient interface {
// comment - The new comment details defined in PullRequestComment
AddPullRequestReviewComments(ctx context.Context, owner, repository string, pullRequestID int, comments ...PullRequestComment) error

// ListPullRequestReviews List all reviews assigned to a pull request.
// owner - User or organization
// repository - VCS repository name
// pullRequestID - Pull request ID
// comment - The new comment details defined in PullRequestComment
ListPullRequestReviews(ctx context.Context, owner, repository string, pullRequestID int) ([]PullRequestReviewDetails, error)

// ListPullRequestReviewComments Gets all pull request review comments
// owner - User or organization
// repository - VCS repository name
Expand Down Expand Up @@ -231,6 +238,12 @@ type VcsClient interface {
// listOptions - Optional parameters for the 'ListCommits' method
GetCommitsWithQueryOptions(ctx context.Context, owner, repository string, options GitCommitsQueryOptions) ([]CommitInfo, error)

// ListPullRequestsAssociatedWithCommit Lists pull requests associated with the commit.
// owner - User or organization
// repository - VCS repository name
// commitSHA - commit sha
ListPullRequestsAssociatedWithCommit(ctx context.Context, owner, repository string, commitSHA string) ([]PullRequestInfo, error)

// AddSshKeyToRepository Adds a public ssh key to a repository
// owner - User or organization
// repository - VCS repository name
Expand Down Expand Up @@ -345,6 +358,15 @@ type PullRequestInfo struct {
Target BranchInfo
}

type PullRequestReviewDetails struct {
ID int64
Reviewer string
Body string
SubmittedAt string
CommitID string
State string
}

type BranchInfo struct {
Name string
Repository string
Expand Down
Loading