Skip to content

Commit

Permalink
removed extra parts and rebased
Browse files Browse the repository at this point in the history
Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>
  • Loading branch information
HRouhani committed Jul 19, 2024
1 parent 11708bf commit a3a325d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
24 changes: 1 addition & 23 deletions providers/gitlab/resources/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,7 @@ func (p *mqlGitlabProject) approvalSettings() (*mqlGitlabProjectApprovalSettings
return mqlApprovalSettings.(*mqlGitlabProjectApprovalSettings), nil
}

// New function to fetch force push settings
func (p *mqlGitlabProject) forcePushDenied() (bool, error) {
conn := p.MqlRuntime.Connection.(*connection.GitLabConnection)

projectID := int(p.Id.Data)
protectedBranches, _, err := conn.Client().ProtectedBranches.ListProtectedBranches(projectID, nil)
if err != nil {
return false, err
}

for _, branch := range protectedBranches {
if branch.Name == p.DefaultBranch.Data {
for _, pushAccessLevel := range branch.PushAccessLevels {
if pushAccessLevel.AccessLevelDescription == "No one" {
return true, nil
}
}
}
}

return false, nil
}

// To fetch protected branch settings
func (p *mqlGitlabProject) protectedBranches() ([]interface{}, error) {
conn := p.MqlRuntime.Connection.(*connection.GitLabConnection)

Expand Down
10 changes: 10 additions & 0 deletions providers/gitlab/resources/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ gitlab.project @defaults("fullName visibility webURL") {
requirementsEnabled bool
// Approval settings for the project
approvalSettings() gitlab.project.approvalSettings
// Protected branches settings for the project
protectedBranches() []gitlab.project.repository.protectedBranch
}

// GitLab project approval settings
Expand All @@ -100,4 +102,12 @@ gitlab.project.approvalSettings @defaults("approvalsBeforeMerge requirePasswordT
mergeRequestsDisableCommittersApproval bool
// Require password to approve
requirePasswordToApprove bool
}

// GitLab protected branch
gitlab.project.repository.protectedBranch @defaults("name allowForcePush") {
// Branch name
name string
// Whether force push is allowed
allowForcePush bool
}

0 comments on commit a3a325d

Please sign in to comment.