Skip to content

Commit

Permalink
GH-71 Address bug with importing repositories (#85)
Browse files Browse the repository at this point in the history
Specifically ones that never had their pipeline feature enabled.
  • Loading branch information
zahiar authored Apr 2, 2022
1 parent 7e07f59 commit 7486bb1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bitbucket/resource_bitbucket_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,18 @@ func resourceBitbucketRepositoryRead(ctx context.Context, resourceData *schema.R
},
)
if err != nil {
return diag.FromErr(fmt.Errorf("unable to get pipeline configuration for repository with error: %s", err))
// Underlying go-bitbucket library only returns an error object, so this is our best way to check for a 404.
// This specifically addresses an issue whereby if you import a Bitbucket repository that has never had its
// pipelines enabled, Bitbucket's API returns a 404.
if err.Error() != "unable to get pipeline config: 404 Not Found" {
return diag.FromErr(fmt.Errorf("unable to get pipeline configuration for repository with error: %s", err))
}

_ = resourceData.Set("enable_pipelines", false)
} else {
_ = resourceData.Set("enable_pipelines", repositoryPipelineConfig.Enabled)
}

_ = resourceData.Set("enable_pipelines", repositoryPipelineConfig.Enabled)

return nil
}

Expand Down

0 comments on commit 7486bb1

Please sign in to comment.