Skip to content

Commit 8899eff

Browse files
committed
Simplify code based on non-nullability
1 parent 88bd3f1 commit 8899eff

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

gitlab/resource_gitlab_branch_protection.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func resourceGitlabBranchProtectionCreate(d *schema.ResourceData, meta interface
5656
branch := gitlab.String(d.Get("branch").(string))
5757
mergeAccessLevel := accessLevelID[d.Get("merge_access_level").(string)]
5858
pushAccessLevel := accessLevelID[d.Get("push_access_level").(string)]
59-
codeOwnerApprovalRequired := getOptionalBool(d, "code_owner_approval_required")
59+
codeOwnerApprovalRequired := d.Get("code_owner_approval_required").(bool)
6060

6161
options := &gitlab.ProtectRepositoryBranchesOptions{
6262
Name: branch,
6363
MergeAccessLevel: &mergeAccessLevel,
6464
PushAccessLevel: &pushAccessLevel,
65-
CodeOwnerApprovalRequired: codeOwnerApprovalRequired,
65+
CodeOwnerApprovalRequired: &codeOwnerApprovalRequired,
6666
}
6767

6868
log.Printf("[DEBUG] create gitlab branch protection on %v for project %s", options.Name, project)
@@ -120,12 +120,12 @@ func resourceGitlabBranchProtectionUpdate(d *schema.ResourceData, meta interface
120120
client := meta.(*gitlab.Client)
121121
project := d.Get("project").(string)
122122
branch := d.Get("branch").(string)
123-
codeOwnerApprovalRequired := getOptionalBool(d, "code_owner_approval_required")
123+
codeOwnerApprovalRequired := d.Get("code_owner_approval_required").(bool)
124124

125125
log.Printf("[DEBUG] update gitlab branch protection for project %s, branch %s", project, branch)
126126

127127
options := &gitlab.RequireCodeOwnerApprovalsOptions{
128-
CodeOwnerApprovalRequired: codeOwnerApprovalRequired,
128+
CodeOwnerApprovalRequired: &codeOwnerApprovalRequired,
129129
}
130130

131131
if _, err := client.ProtectedBranches.RequireCodeOwnerApprovals(project, branch, options); err != nil {

gitlab/util.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,3 @@ func stringSetToStringSlice(stringSet *schema.Set) *[]string {
190190
}
191191
return &ret
192192
}
193-
194-
func getOptionalBool(d *schema.ResourceData, key string) *bool {
195-
var result *bool
196-
if value, isSet := d.GetOk(key); isSet {
197-
valueBool := value.(bool)
198-
result = &valueBool
199-
}
200-
return result
201-
}

0 commit comments

Comments
 (0)