Skip to content

Commit

Permalink
✨ get closed or all PRs from github (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskimmina authored Dec 11, 2023
1 parent b074bb0 commit 2da6549
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
6 changes: 5 additions & 1 deletion providers/github/resources/github.lr
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,12 @@ private github.repository @defaults("fullName") {
hasDiscussions bool
// Whether the repository is an organization repository template
isTemplate bool
// Whether the repository has open merge requests
// List of open merge requests for the repository
openMergeRequests() []github.mergeRequest
// List of closed merge requests for the repository
closedMergeRequests() []github.mergeRequest
// List of all merge requests for the repository
allMergeRequests() []github.mergeRequest
// List of branches for the repository
branches() []github.branch
// Default branch name for the repository
Expand Down
48 changes: 48 additions & 0 deletions providers/github/resources/github.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions providers/github/resources/github.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ resources:
fields:
MergeRequests:
min_mondoo_version: latest
allMergeRequests:
min_mondoo_version: latest
allowAutoMerge:
min_mondoo_version: 6.4.0
allowForking:
Expand All @@ -311,6 +313,8 @@ resources:
min_mondoo_version: 7.14.0
closedIssues:
min_mondoo_version: 7.14.0
closedMergeRequests:
min_mondoo_version: latest
collaborators:
min_mondoo_version: 6.11.0
commits:
Expand Down
32 changes: 28 additions & 4 deletions providers/github/resources/github_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (g *mqlGithubRepository) id() (string, error) {
}

func initGithubMergeRequest(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
if len(args) > 1 {
if len(args) > 2 {
return args, nil, nil
}

Expand Down Expand Up @@ -164,7 +164,7 @@ func initGithubMergeRequest(runtime *plugin.Runtime, args map[string]*llx.RawDat
owner = user.GetLogin()
}
reponame := ""
if x, ok := args["name"]; ok {
if x, ok := args["repoName"]; ok {
reponame = x.Value.(string)
} else {
repo, err := conn.Repository()
Expand Down Expand Up @@ -354,7 +354,7 @@ func (g *mqlGithubRepository) license() (*mqlGithubLicense, error) {
return res.(*mqlGithubLicense), nil
}

func (g *mqlGithubRepository) openMergeRequests() ([]interface{}, error) {
func (g *mqlGithubRepository) getMergeRequests(state string) ([]interface{}, error) {
conn := g.MqlRuntime.Connection.(*connection.GithubConnection)
if g.Name.Error != nil {
return nil, g.Name.Error
Expand All @@ -371,7 +371,7 @@ func (g *mqlGithubRepository) openMergeRequests() ([]interface{}, error) {

listOpts := &github.PullRequestListOptions{
ListOptions: github.ListOptions{PerPage: paginationPerPage},
State: "open",
State: state,
}
var allPulls []*github.PullRequest
for {
Expand Down Expand Up @@ -437,6 +437,30 @@ func (g *mqlGithubRepository) openMergeRequests() ([]interface{}, error) {
return res, nil
}

func (g *mqlGithubRepository) allMergeRequests() ([]interface{}, error) {
res, err := g.getMergeRequests("all")
if err != nil {
return nil, err
}
return res, err
}

func (g *mqlGithubRepository) closedMergeRequests() ([]interface{}, error) {
res, err := g.getMergeRequests("closed")
if err != nil {
return nil, err
}
return res, err
}

func (g *mqlGithubRepository) openMergeRequests() ([]interface{}, error) {
res, err := g.getMergeRequests("open")
if err != nil {
return nil, err
}
return res, err
}

func (g *mqlGithubMergeRequest) id() (string, error) {
if g.Id.Error != nil {
return "", g.Id.Error
Expand Down

0 comments on commit 2da6549

Please sign in to comment.