Skip to content

Commit

Permalink
Merge pull request #1 from DrFaust92/master
Browse files Browse the repository at this point in the history
Fetch Change
  • Loading branch information
abhinand-c authored Nov 14, 2022
2 parents 89e5506 + 0bc0f50 commit f4543bc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions bitbucket/resource_branch_restriction.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ func resourceBranchRestrictionsRead(ctx context.Context, d *schema.ResourceData,
brRes, res, err := brApi.RepositoriesWorkspaceRepoSlugBranchRestrictionsIdGet(c.AuthContext, url.PathEscape(d.Id()),
d.Get("repository").(string), d.Get("owner").(string))

if err != nil {
return diag.FromErr(err)
}

if res.StatusCode == http.StatusNotFound {
if res != nil && res.StatusCode == http.StatusNotFound {
log.Printf("[WARN] Branch Restrictions (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

if err != nil {
return diag.FromErr(err)
}

d.SetId(string(fmt.Sprintf("%v", brRes.Id)))
d.Set("kind", brRes.Kind)
d.Set("pattern", brRes.Pattern)
Expand Down Expand Up @@ -254,9 +254,14 @@ func resourceBranchRestrictionsDelete(ctx context.Context, d *schema.ResourceDat
c := m.(Clients).genClient
brApi := c.ApiClient.BranchRestrictionsApi

_, err := brApi.RepositoriesWorkspaceRepoSlugBranchRestrictionsIdDelete(c.AuthContext, url.PathEscape(d.Id()),
res, err := brApi.RepositoriesWorkspaceRepoSlugBranchRestrictionsIdDelete(c.AuthContext, url.PathEscape(d.Id()),
d.Get("repository").(string), d.Get("owner").(string))

if res != nil && res.StatusCode == http.StatusNotFound {
log.Printf("[WARN] Branch Restrictions (%s) not found, removing from state", d.Id())
return nil
}

if err != nil {
return diag.FromErr(err)
}
Expand Down

0 comments on commit f4543bc

Please sign in to comment.