Closed bartje321 closed 1 month ago
isnt the issue that it should be 2.0/workspaces/foo/projects/BAR/settings/branching-model instead of 2.0/workspaces/foo/projects/BAR/branching-model/settings
@DLangenberg Interesting thought.
I checked the API docs and the correct path seems to be:
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branching-model/settings
So I think the the endpoint is right overall, but Atlassian doesn't have a sample payload to show, only a response, so something must be sideways.
Here's the payload when setting it via the browser:
{
"branch_types": [
{
"enabled": true,
"kind": "bugfix",
"prefix": "bugfix/"
},
{
"enabled": true,
"kind": "feature",
"prefix": "feature/"
},
{
"enabled": false,
"kind": "hotfix",
"prefix": "hotfix/"
},
{
"enabled": false,
"kind": "release",
"prefix": "release/"
}
],
"development": {
"name": "dev",
"use_mainbranch": false,
"is_valid": true
},
"production": {
"name": "main",
"use_mainbranch": false,
"enabled": true,
"is_valid": true
}
}
I found the issue -- the Bitbucket API requires the use_mainbranch
field to be present in the request body, but the BranchModel
specifies omitempty
, which omits it from the JSON if it's empty (i.e. false
).
type BranchModel struct {
IsValid bool `json:"is_valid,omitempty"`
Name *string `json:"name"`
UseMainbranch bool `json:"use_mainbranch,omitempty"`
BranchDoesNotExist bool `json:"branch_does_not_exist,omitempty"`
Enabled bool `json:"enabled,omitempty"`
}
I fixed and tested this locally and confirmed that removing ,omitempty
from this field fixes the issue. I'll submit a PR.
Hi there,
Terraform Version
Terraform v1.4.6
Affected Resource(s)
Please list the resources as a list, for example:
Terraform Configuration Files
Panic Output
Expected Behavior
The project branching model should have "new" as the development branch
Actual Behavior
400 Bad request.
Important Factoids
The following scenarios all result in the 400 error:
use_mainbranch = false
creating the resource without a name and then setting the name
What does work is setting a name in Bitbucket and updating it using Terraform