github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/pkg/apis/github/pull_request.go (about) 1 package github 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/google/go-github/v44/github" 9 ) 10 11 func (g *Github) ListPullRequests(repository string) ([]*github.PullRequest, error) { 12 prs, _, err := g.client.PullRequests.List(context.Background(), g.organization, repository, &github.PullRequestListOptions{}) 13 if err != nil { 14 return nil, fmt.Errorf("error when listing pull requests for the repo %s: %v", repository, err) 15 } 16 17 return prs, nil 18 } 19 20 func (g *Github) ListPullRequestCommentsSince(repository string, prNumber int, since time.Time) ([]*github.IssueComment, error) { 21 comments, _, err := g.client.Issues.ListComments(context.Background(), g.organization, repository, prNumber, &github.IssueListCommentsOptions{ 22 Since: &since, 23 Sort: github.String("created"), 24 Direction: github.String("asc"), 25 }) 26 if err != nil { 27 return nil, fmt.Errorf("error when listing pull requests comments for the repo %s: %v", repository, err) 28 } 29 30 return comments, nil 31 } 32 33 func (g *Github) MergePullRequest(repository string, prNumber int) (*github.PullRequestMergeResult, error) { 34 mergeResult, _, err := g.client.PullRequests.Merge(context.Background(), g.organization, repository, prNumber, "", &github.PullRequestOptions{}) 35 if err != nil { 36 return nil, fmt.Errorf("error when merging pull request number %d for the repo %s: %v", prNumber, repository, err) 37 } 38 39 return mergeResult, nil 40 }