Skip to content

Commit

Permalink
support for default branch
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 1e801bd commit 556d76d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion providers/gitlab/resources/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (p *mqlGitlabProject) approvalSettings() (*mqlGitlabProjectApprovalSettings
return mqlApprovalSettings.(*mqlGitlabProjectApprovalSettings), nil
}

// Define the id function for unique identifier for a resource instance
// Define the id function for a unique identifier for a resource instance
func (g *mqlGitlabProjectRepositoryProtectedBranch) id() (string, error) {
return g.Name.Data, nil
}
Expand All @@ -159,16 +159,27 @@ func (p *mqlGitlabProject) protectedBranches() ([]interface{}, error) {
conn := p.MqlRuntime.Connection.(*connection.GitLabConnection)

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

defaultBranch := project.DefaultBranch

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

var mqlProtectedBranches []interface{}
for _, branch := range protectedBranches {
// Declare and initialize isDefaultBranch variable
isDefaultBranch := branch.Name == defaultBranch

branchSettings := map[string]*llx.RawData{
"name": llx.StringData(branch.Name),
"allowForcePush": llx.BoolData(branch.AllowForcePush),
"defaultBranch": llx.BoolData(isDefaultBranch),
}

mqlProtectedBranch, err := CreateResource(p.MqlRuntime, "gitlab.project.repository.protectedBranch", branchSettings)
Expand Down
2 changes: 2 additions & 0 deletions providers/gitlab/resources/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ gitlab.project.repository.protectedBranch @defaults("name allowForcePush") {
name string
// Whether force push is allowed
allowForcePush bool
// Whether this is the default branch
defaultBranch bool
}

0 comments on commit 556d76d

Please sign in to comment.