Skip to content

Commit

Permalink
adding the approvalrule settings to the project
Browse files Browse the repository at this point in the history
Signed-off-by: Hossein Rouhani <[email protected]>
  • Loading branch information
HRouhani committed Jul 18, 2024
1 parent 99e085f commit b05fe0b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions providers/gitlab/resources/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,35 @@ func initGitlabProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (m
args = getGitlabProjectArgs(project)
return args, nil, nil
}

// New function to fetch project approval rules
func (p *mqlGitlabProject) approvalRules() ([]interface{}, error) {
conn := p.MqlRuntime.Connection.(*connection.GitLabConnection)

projectID := int(p.Id.Data)
approvals, _, err := conn.Client().Projects.GetProjectApprovalRules(projectID, nil, nil)
if err != nil {
return nil, err
}

var approvalRules []interface{}
for _, rule := range approvals {
approvalRule := map[string]*llx.RawData{
"id": llx.IntData(int64(rule.ID)),
"name": llx.StringData(rule.Name),
"approvalsRequired": llx.IntData(int64(rule.ApprovalsRequired)),
}
mqlApprovalRule, err := CreateResource(p.MqlRuntime, "gitlab.project.approvalRule", approvalRule)
if err != nil {
return nil, err
}
approvalRules = append(approvalRules, mqlApprovalRule)
}

return approvalRules, nil
}

// Initialize the gitlab project approval rule
func initGitlabProjectApprovalRule(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
return args, nil, nil
}
13 changes: 13 additions & 0 deletions providers/gitlab/resources/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ gitlab.project @defaults("fullName visibility webURL") {
autoDevopsEnabled bool
// Whether the requirements feature is enabled
requirementsEnabled bool
// Approval rules for the project
approvalRules() []gitlab.project.approvalRule
}


// GitLab project approval rule
gitlab.project.approvalRule @defaults("id name approvalsRequired") {
// Rule ID
id int
// Rule name
name string
// Number of approvals required
approvalsRequired int
}

0 comments on commit b05fe0b

Please sign in to comment.