Skip to content

Commit bb6a929

Browse files
authored
Merge pull request #785 from timofurrer/bugfix/pr-551
Fix bugs introduced with PR #551
2 parents febe745 + 4a349ab commit bb6a929

7 files changed

+38
-40
lines changed

docs/data-sources/project_protected_branch.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ The following arguments are supported:
3030

3131
The following attributes are exported:
3232

33-
* `push_access_levels`, `merge_access_levels`, `unprotect_access_levels` - Each block contains a list of which access levels, users or groups are allowed to perform the respective actions (documented below).
33+
* `push_access_levels`, `merge_access_levels` - Each block contains a list of which access levels, users or groups are allowed to perform the respective actions (documented below).
3434

35+
* `allow_force_push` - Whether force push is allowed.
3536
* `code_owner_approval_required` - Reject code pushes that change files listed in the CODEOWNERS file.
3637

3738
## Nested Blocks
3839

39-
### `push_access_levels`, `merge_access_levels`, `unprotect_access_levels`
40+
### `push_access_levels`, `merge_access_levels`
4041

4142
#### Attributes
4243

docs/data-sources/project_protected_branches.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ The following attributes are exported:
3636

3737
* `name` - The name of the protected branch.
3838

39-
* `push_access_levels`, `merge_access_levels`, `unprotect_access_levels` - Each block contains a list of which access levels, users or groups are allowed to perform the respective actions (documented below).
39+
* `push_access_levels`, `merge_access_levels` - Each block contains a list of which access levels, users or groups are allowed to perform the respective actions (documented below).
40+
41+
* `allow_force_push` - Whether force push is allowed.
4042

4143
* `code_owner_approval_required` - Reject code pushes that change files listed in the CODEOWNERS file.
4244

43-
### `push_access_levels`, `merge_access_levels`, `unprotect_access_levels`
45+
### `push_access_levels`, `merge_access_levels`
4446

4547
#### Attributes
4648

gitlab/data_source_gitlab_project_protected_branch.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ func dataSourceGitlabProjectProtectedBranch() *schema.Resource {
2929
Type: schema.TypeInt,
3030
Computed: true,
3131
},
32-
"push_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
33-
"merge_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
34-
"unprotect_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
32+
"push_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
33+
"merge_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
34+
"allow_force_push": {
35+
Type: schema.TypeBool,
36+
Computed: true,
37+
},
3538
"code_owner_approval_required": {
3639
Type: schema.TypeBool,
3740
Computed: true,
@@ -81,13 +84,15 @@ func dataSourceGitlabProjectProtectedBranchRead(d *schema.ResourceData, meta int
8184
return fmt.Errorf("error getting protected branch (Project: %v / Name %v): %v", project, name, err)
8285
}
8386

87+
// lintignore:R004 // TODO: Resolve this tfproviderlint issue
8488
if err := d.Set("push_access_levels", convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.PushAccessLevels)); err != nil {
8589
return err
8690
}
91+
// lintignore:R004 // TODO: Resolve this tfproviderlint issue
8792
if err := d.Set("merge_access_levels", convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.MergeAccessLevels)); err != nil {
8893
return err
8994
}
90-
if err := d.Set("unprotect_access_levels", convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.UnprotectAccessLevels)); err != nil {
95+
if err := d.Set("allow_force_push", pb.AllowForcePush); err != nil {
9196
return err
9297
}
9398
if err := d.Set("code_owner_approval_required", pb.CodeOwnerApprovalRequired); err != nil {
@@ -102,8 +107,8 @@ func dataSourceGitlabProjectProtectedBranchRead(d *schema.ResourceData, meta int
102107
type stateBranchAccessDescription struct {
103108
AccessLevel string `json:"access_level" mapstructure:"access_level"`
104109
AccessLevelDescription string `json:"access_level_description" mapstructure:"access_level_description"`
105-
GroupID *int `json:"group_id,omitempty" mapstructure:"group_id,omitempty"`
106-
UserID *int `json:"user_id,omitempty" mapstructure:"user_id,omitempty"`
110+
GroupID int `json:"group_id,omitempty" mapstructure:"group_id,omitempty"`
111+
UserID int `json:"user_id,omitempty" mapstructure:"user_id,omitempty"`
107112
}
108113

109114
func convertBranchAccessDescriptionsToStateBranchAccessDescriptions(descriptions []*gitlab.BranchAccessDescription) []stateBranchAccessDescription {
@@ -122,10 +127,10 @@ func convertBranchAccessDescriptionToStateBranchAccessDescription(description *g
122127
AccessLevelDescription: description.AccessLevelDescription,
123128
}
124129
if description.UserID != 0 {
125-
stateDescription.UserID = &description.UserID
130+
stateDescription.UserID = description.UserID
126131
}
127132
if description.GroupID != 0 {
128-
stateDescription.GroupID = &description.GroupID
133+
stateDescription.GroupID = description.GroupID
129134
}
130135
return stateDescription
131136
}

gitlab/data_source_gitlab_project_protected_branch_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
99
)
1010

11-
func TestAccDataGitlabProjectProtectedBranchSearch(t *testing.T) {
11+
func TestAccDataGitlabProjectProtectedBranch_search(t *testing.T) {
1212
projectName := fmt.Sprintf("tf-%s", acctest.RandString(5))
1313

1414
resource.Test(t, resource.TestCase{
@@ -21,7 +21,7 @@ func TestAccDataGitlabProjectProtectedBranchSearch(t *testing.T) {
2121
resource.TestCheckResourceAttr(
2222
"data.gitlab_project_protected_branch.test",
2323
"name",
24-
"master",
24+
"main",
2525
),
2626
resource.TestCheckResourceAttr(
2727
"data.gitlab_project_protected_branch.test",
@@ -39,26 +39,19 @@ func testAccDataGitlabProjectProtectedBranchConfigGetProjectSearch(projectName s
3939
resource "gitlab_project" "test" {
4040
name = "%s"
4141
path = "%s"
42-
default_branch = "master"
43-
}
44-
45-
resource "gitlab_branch_protection" "master" {
46-
project = gitlab_project.test.id
47-
branch = "master"
48-
push_access_level = "maintainer"
49-
merge_access_level = "developer"
42+
default_branch = "main"
5043
}
5144
5245
resource "gitlab_branch_protection" "test" {
5346
project = gitlab_project.test.id
54-
branch = "master"
47+
branch = "main"
5548
push_access_level = "maintainer"
5649
merge_access_level = "developer"
5750
}
5851
5952
data "gitlab_project_protected_branch" "test" {
6053
project_id = gitlab_project.test.id
61-
name = gitlab_branch_protection.master.branch
54+
name = gitlab_branch_protection.test.branch
6255
}
6356
`, projectName, projectName)
6457
}

gitlab/data_source_gitlab_project_protected_branches.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ func dataSourceGitlabProjectProtectedBranches() *schema.Resource {
3232
Type: schema.TypeInt,
3333
Computed: true,
3434
},
35-
"push_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
36-
"merge_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
37-
"unprotect_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
35+
"push_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
36+
"merge_access_levels": dataSourceGitlabProjectProtectedBranchSchemaAccessLevels(),
37+
"allow_force_push": {
38+
Type: schema.TypeBool,
39+
Computed: true,
40+
},
3841
"code_owner_approval_required": {
3942
Type: schema.TypeBool,
4043
Computed: true,
@@ -51,7 +54,7 @@ type stateProtectedBranch struct {
5154
Name string `json:"name,omitempty" mapstructure:"name,omitempty"`
5255
PushAccessLevels []stateBranchAccessDescription `json:"push_access_levels,omitempty" mapstructure:"push_access_levels,omitempty"`
5356
MergeAccessLevels []stateBranchAccessDescription `json:"merge_access_levels,omitempty" mapstructure:"merge_access_levels,omitempty"`
54-
UnprotectAccessLevels []stateBranchAccessDescription `json:"unprotect_access_levels,omitempty" mapstructure:"unprotect_access_levels,omitempty"`
57+
AllowForcePush bool `json:"allow_force_push,omitempty" mapstructure:"allow_force_push,omitempty"`
5558
CodeOwnerApprovalRequired bool `json:"code_owner_approval_required,omitempty" mapstructure:"code_owner_approval_required,omitempty"`
5659
}
5760

@@ -83,12 +86,13 @@ func dataSourceGitlabProjectProtectedBranchesRead(d *schema.ResourceData, meta i
8386
Name: pb.Name,
8487
PushAccessLevels: convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.PushAccessLevels),
8588
MergeAccessLevels: convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.MergeAccessLevels),
86-
UnprotectAccessLevels: convertBranchAccessDescriptionsToStateBranchAccessDescriptions(pb.UnprotectAccessLevels),
89+
AllowForcePush: pb.AllowForcePush,
8790
CodeOwnerApprovalRequired: pb.CodeOwnerApprovalRequired,
8891
})
8992
}
9093
}
9194

95+
// lintignore:R004 // TODO: Resolve this tfproviderlint issue
9296
if err := d.Set("protected_branches", allProtectedBranches); err != nil {
9397
return err
9498
}

gitlab/data_source_gitlab_project_protected_branches_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
99
)
1010

11-
func TestAccDataGitlabProjectProtectedBranchesSearch(t *testing.T) {
11+
func TestAccDataGitlabProjectProtectedBranches_search(t *testing.T) {
1212
projectName := fmt.Sprintf("tf-%s", acctest.RandString(5))
1313

1414
resource.Test(t, resource.TestCase{
@@ -21,7 +21,7 @@ func TestAccDataGitlabProjectProtectedBranchesSearch(t *testing.T) {
2121
resource.TestCheckResourceAttr(
2222
"data.gitlab_project_protected_branches.test",
2323
"protected_branches.0.name",
24-
"master",
24+
"main",
2525
),
2626
resource.TestCheckResourceAttr(
2727
"data.gitlab_project_protected_branches.test",
@@ -39,12 +39,12 @@ func testAccDataGitlabProjectProtectedBranchesConfigGetProjectSearch(projectName
3939
resource "gitlab_project" "test" {
4040
name = "%s"
4141
path = "%s"
42-
default_branch = "master"
42+
default_branch = "main"
4343
}
4444
4545
resource "gitlab_branch_protection" "test" {
4646
project = gitlab_project.test.id
47-
branch = "master"
47+
branch = "main"
4848
push_access_level = "maintainer"
4949
merge_access_level = "developer"
5050
}

gitlab/resource_gitlab_branch_protection.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ func schemaAllowedTo() *schema.Schema {
255255
}
256256
}
257257

258-
type stateBranchAccessDescription struct {
259-
AccessLevel string `mapstructure:"access_level"`
260-
AccessLevelDescription string `mapstructure:"access_level_description"`
261-
GroupID int `mapstructure:"group_id,omitempty"`
262-
UserID int `mapstructure:"user_id,omitempty"`
263-
}
264-
265258
func convertAllowedAccessLevelsToBranchAccessDescriptions(descriptions []*gitlab.BranchAccessDescription) []stateBranchAccessDescription {
266259
result := make([]stateBranchAccessDescription, 0)
267260

0 commit comments

Comments
 (0)