Skip to content

Commit 58e11f2

Browse files
authored
Merge pull request #229 from DrFaust92/default_branch_deletion
Default_branch_deletion
2 parents 49ac45e + e665d3d commit 58e11f2

21 files changed

+106
-66
lines changed

.github/workflows/lint.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
name: Run linter
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/setup-go@v3
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-go@v5
1112
with:
12-
go-version: '1.19'
13-
- uses: actions/checkout@v3
13+
go-version-file: "go.mod"
1414
- name: golangci-lint
15-
uses: golangci/golangci-lint-action@v3
15+
uses: golangci/golangci-lint-action@v8
1616
with:
17-
version: v1.50.1
18-
only-new-issues: true
17+
version: v2.1
18+
only-new-issues: true

.golangci.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1-
linters-settings:
2-
errcheck:
3-
ignore: Set
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
- durationcheck
6+
- govet
7+
- ineffassign
8+
- makezero
9+
- misspell
10+
- nilerr
11+
- staticcheck
12+
- unconvert
13+
- unused
14+
exclusions:
15+
generated: lax
16+
presets:
17+
- comments
18+
- common-false-positives
19+
- legacy
20+
- std-error-handling
21+
paths:
22+
- third_party$
23+
- builtin$
24+
- examples$
25+
formatters:
26+
enable:
27+
- gofmt
28+
exclusions:
29+
generated: lax
30+
paths:
31+
- third_party$
32+
- builtin$
33+
- examples$

bitbucket/provider_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ func TestProvider(t *testing.T) {
2424
}
2525

2626
func TestProvider_impl(t *testing.T) {
27-
var _ *schema.Provider = Provider()
27+
var _ = Provider()
2828
}
2929

3030
func testAccPreCheck(t *testing.T) {
3131
if v := os.Getenv("BITBUCKET_USERNAME"); v == "" {
32-
t.Fatal("BITBUCKET_USERNAME must be set for acceptence tests")
32+
t.Fatal("BITBUCKET_USERNAME must be set for acceptance tests")
3333
}
3434

3535
if v := os.Getenv("BITBUCKET_PASSWORD"); v == "" {
36-
t.Fatal("BITBUCKET_PASSWORD must be set for acceptence tests")
36+
t.Fatal("BITBUCKET_PASSWORD must be set for acceptance tests")
3737
}
3838

3939
if v := os.Getenv("BITBUCKET_TEAM"); v == "" {
40-
t.Fatal("BITBUCKET_TEAM must be set for acceptence tests")
40+
t.Fatal("BITBUCKET_TEAM must be set for acceptance tests")
4141
}
4242
}
4343

4444
func testAccPreCheckPipeSchedule(t *testing.T) {
4545
if v := os.Getenv("BITBUCKET_PIPELINED_REPO"); v == "" {
46-
t.Fatal("BITBUCKET_PIPELINED_REPO must be set for acceptence tests")
46+
t.Fatal("BITBUCKET_PIPELINED_REPO must be set for acceptance tests")
4747
}
4848
}

bitbucket/resource_branch_restriction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func resourceBranchRestrictionsCreate(ctx context.Context, d *schema.ResourceDat
199199
return diag.FromErr(err)
200200
}
201201

202-
d.SetId(string(fmt.Sprintf("%v", branchRestrictionReq.Id)))
202+
d.SetId(fmt.Sprintf("%v", branchRestrictionReq.Id))
203203

204204
return resourceBranchRestrictionsRead(ctx, d, m)
205205
}
@@ -221,7 +221,7 @@ func resourceBranchRestrictionsRead(ctx context.Context, d *schema.ResourceData,
221221
return diag.FromErr(err)
222222
}
223223

224-
d.SetId(string(fmt.Sprintf("%v", brRes.Id)))
224+
d.SetId(fmt.Sprintf("%v", brRes.Id))
225225
d.Set("kind", brRes.Kind)
226226
d.Set("pattern", brRes.Pattern)
227227
d.Set("value", brRes.Value)

bitbucket/resource_branching_model.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import (
1717

1818
// BranchingModel is the data we need to send to create a new branching model for the repository
1919
type BranchingModel struct {
20-
Development *BranchModel `json:"development,omitempty"`
21-
Production *BranchModel `json:"production,omitempty"`
22-
BranchTypes []*BranchType `json:"branch_types"`
20+
Development *BranchModel `json:"development,omitempty"`
21+
Production *BranchModel `json:"production,omitempty"`
22+
BranchTypes []*BranchType `json:"branch_types"`
23+
DefaultBranchDeletion *bool `json:"default_branch_deletion,omitempty"`
2324
}
2425

2526
type BranchModel struct {
@@ -138,6 +139,10 @@ func resourceBranchingModel() *schema.Resource {
138139
},
139140
},
140141
},
142+
"default_branch_deletion": {
143+
Type: schema.TypeBool,
144+
Optional: true,
145+
},
141146
},
142147
}
143148
}
@@ -172,7 +177,7 @@ func resourceBranchingModelsPut(ctx context.Context, d *schema.ResourceData, m i
172177
return diag.FromErr(decodeerr)
173178
}
174179

175-
d.SetId(string(fmt.Sprintf("%s/%s", d.Get("owner").(string), d.Get("repository").(string))))
180+
d.SetId(fmt.Sprintf("%s/%s", d.Get("owner").(string), d.Get("repository").(string)))
176181

177182
return resourceBranchingModelsRead(ctx, d, m)
178183
}
@@ -221,6 +226,7 @@ func resourceBranchingModelsRead(ctx context.Context, d *schema.ResourceData, m
221226

222227
d.Set("owner", owner)
223228
d.Set("repository", repo)
229+
d.Set("default_branch_deletion", branchingModel.DefaultBranchDeletion)
224230
d.Set("development", flattenBranchModel(branchingModel.Development, "development"))
225231
d.Set("branch_type", flattenBranchTypes(branchingModel.BranchTypes))
226232
d.Set("production", flattenBranchModel(branchingModel.Production, "production"))
@@ -262,6 +268,11 @@ func expandBranchingModel(d *schema.ResourceData) *BranchingModel {
262268
model.BranchTypes = make([]*BranchType, 0)
263269
}
264270

271+
//nolint:staticcheck
272+
if v, ok := d.GetOkExists("default_branch_deletion"); ok {
273+
model.DefaultBranchDeletion = v.(*bool)
274+
}
275+
265276
return model
266277
}
267278

@@ -383,7 +394,7 @@ func branchingModelId(id string) (string, string, error) {
383394
parts := strings.Split(id, "/")
384395

385396
if len(parts) != 2 {
386-
return "", "", fmt.Errorf("Unexpected format of ID (%q), expected OWNER/REPOSITORY", id)
397+
return "", "", fmt.Errorf("unexpected format of ID (%q), expected OWNER/REPOSITORY", id)
387398
}
388399

389400
return parts[0], parts[1], nil

bitbucket/resource_commit_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func resourceCommitFilePut(ctx context.Context, d *schema.ResourceData, m interf
128128
return diag.FromErr(fmt.Errorf(""))
129129
}
130130

131-
d.SetId(string(fmt.Sprintf("%s/%s/%s/%s", workspace, repoSlug, branch, filename)))
131+
d.SetId(fmt.Sprintf("%s/%s/%s/%s", workspace, repoSlug, branch, filename))
132132

133133
location, _ := res.Location()
134134
splitPath := strings.Split(location.Path, "/")

bitbucket/resource_deploy_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func resourceDeployKeysCreate(ctx context.Context, d *schema.ResourceData, m int
9191

9292
log.Printf("[DEBUG] Deploy Keys Create Response Decoded: %#v", deployKeyRes)
9393

94-
d.SetId(string(fmt.Sprintf("%s/%s/%d", workspace, repo, deployKeyRes.ID)))
94+
d.SetId(fmt.Sprintf("%s/%s/%d", workspace, repo, deployKeyRes.ID))
9595

9696
return resourceDeployKeysRead(ctx, d, m)
9797
}

bitbucket/resource_forked_repository.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ func resourceForkedRepository() *schema.Resource {
136136
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
137137
v := val.(map[string]interface{})
138138
if _, ok := v["slug"]; !ok {
139-
errs = append(errs, fmt.Errorf("A repository 'slug' is required when specifying a parent to fork from."))
139+
errs = append(errs, fmt.Errorf("a repository 'slug' is required when specifying a parent to fork from"))
140140
}
141141
if _, ok := v["owner"]; !ok {
142-
errs = append(errs, fmt.Errorf("A repository 'owner' is required when specifying a parent to fork from."))
142+
errs = append(errs, fmt.Errorf("a repository 'owner' is required when specifying a parent to fork from"))
143143
}
144144
return warns, errs
145145
},
@@ -215,16 +215,17 @@ func resourceForkedRepositoryCreate(ctx context.Context, d *schema.ResourceData,
215215
return diag.FromErr(err)
216216
}
217217

218-
d.SetId(string(fmt.Sprintf("%s/%s", d.Get("owner").(string), repoSlug)))
218+
d.SetId(fmt.Sprintf("%s/%s", d.Get("owner").(string), repoSlug))
219219

220220
pipelinesEnabled := d.Get("pipelines_enabled").(bool)
221221
pipelinesConfig := &bitbucket.PipelinesConfig{Enabled: pipelinesEnabled}
222222

223+
//nolint:all
223224
retryErr := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
224225
_, pipelineResponse, err := pipeApi.UpdateRepositoryPipelineConfig(c.AuthContext, *pipelinesConfig, workspace, repoSlug)
225226
if pipelineResponse.StatusCode == 403 || pipelineResponse.StatusCode == 404 {
226227
return resource.RetryableError(
227-
fmt.Errorf("Permissions error setting Pipelines config, retrying..."),
228+
fmt.Errorf("permissions error setting Pipelines config, retrying"),
228229
)
229230
}
230231

@@ -315,9 +316,10 @@ func resourceForkedRepositoryRead(ctx context.Context, d *schema.ResourceData, m
315316
return diag.FromErr(err)
316317
}
317318

318-
if res.StatusCode == 200 {
319+
switch res.StatusCode {
320+
case http.StatusOK:
319321
d.Set("pipelines_enabled", pipelinesConfigReq.Enabled)
320-
} else if res.StatusCode == http.StatusNotFound {
322+
case http.StatusNotFound:
321323
d.Set("pipelines_enabled", false)
322324
}
323325

bitbucket/resource_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func resourceGroupsCreate(ctx context.Context, d *schema.ResourceData, m interfa
9191

9292
log.Printf("[DEBUG] Group Req Response Decoded: %#v", group)
9393

94-
d.SetId(string(fmt.Sprintf("%s/%s", workspace, group.Slug)))
94+
d.SetId(fmt.Sprintf("%s/%s", workspace, group.Slug))
9595

9696
return resourceGroupsRead(ctx, d, m)
9797
}

bitbucket/resource_group_membership.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func resourceGroupMembershipsPut(ctx context.Context, d *schema.ResourceData, m
6363
return diag.FromErr(err)
6464
}
6565

66-
d.SetId(string(fmt.Sprintf("%s/%s/%s", workspace, groupSlug, uuid)))
66+
d.SetId(fmt.Sprintf("%s/%s/%s", workspace, groupSlug, uuid))
6767

6868
return resourceGroupMembershipsRead(ctx, d, m)
6969
}

0 commit comments

Comments
 (0)