How to maintain and set the configuration externally?
In general the process can be done via the standard REST-API of Bitbucket. The REST-API offers an interface which enables you to set the settings of hooks via JSON. This JSON representation of the settings you can get and put to/from the hook (see Bitbucket REST Resources )
Since version 3.0.x
The settings
This example shows and describes the possibilities via JSON
{
//enable the Jira transition action
"jira.transitions.action.enabled": true,
//enable the Jira comments action
"jira.comments.action.enabled": true,
//enable the Jira worklog action
"jira.worklog.action.enabled": true,
//enable printing of the remaining time
"jira.worklog.action.remain.enabled": true,
//enable the possibility to set the remaining effort
"jira.remain.action.enabled": true,
//enable the possibility to set the assignee
"jira.assignee.action.enabled": true,
//enable the possibility to set/add the component
"jira.component.action.enabled": true,
//enable the possibility to set/add labels
"jira.label.action.enabled": true,
//enable the possibility to set priority
"jira.prio.action.enabled": true,
//enable the possibility to set fixed version
"jira.fixversion.action.enabled": true,
//enable the possibility to set the affected
"jira.affectedversion.action.enabled": true,
//set the regular expression to detect issue keys
"jira.issue.regex": "([A-Z][A-Z\\d_]*)-(\\d+)",
//enable the possibility to add a heater to Jira comments
"jira.comments.header.enabled": true,
//Create jira comment with the following header
"jira.comments.header": "my new header",
//enable the possibility to create a pull request
"bb.pull.action.enabled": true,
//enable the possibility to add a comment to existing pull request
"bb.comment.action.enabled": true,
//enable the possibility to add a reviewer to existing pull request
"bb.reviewer.action.enabled": true,
//enable the possibility to add tasks to existing pull request
"bb.task.action.enabled": true,
//enable the approval strategy
"bb.approve.action.enabled": true,
//enable Set the approval strategy: KEEP: keep approvals UNAPPROVE: discard existing approvals
"bb.approve": "KEEP",
//the response level (ERROR,WARNING,INFO,DISABLED)
"bb.response.level": "info",
//in ms -> how long does the hook wait for a response
"bb.action.timeout": "500"
}
Please remove the comments in the json file, because JSON is data only and do not support comments
How to put the JSON Settings to the hook
As you can see in the REST Resources of Bitbucket, you need to configure the REST call with the following:
Endpoints for project and repository
repository: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/settings
project: /rest/api/1.0/projects/{projectKey}/settings/hooks/{hookKey}/settings
To automatically enable the addon in addition use the endpoints
Enable endpoints for project and repository
repository: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/enabled
project: /rest/api/1.0/projects/{projectKey}/settings/hooks/{hookKey}/enabled
Endpoint variables, URL, user and password:
- hookKey: com.lb.software.stash.smart.commit.lb-software-stash-smart-commit:smart-post-hook - The unique hook ID
- projectKey: PROJECT_1 - The slug of the project in this example
- repositorySlug: rep_1 - The slug of the test repository in this example just if you would like to define a repository specific confirguration
- Username and password: admin:admin - username and password to access the settings via REST-API ( has the user the permission to access the configuration page?)
- Bitbucket-URL: http://bitbucket:7990/bitbucket
Resulting absolute endpoint
http://admin:admin@bitbucket:7990/bitbucket/rest/api/1.0/projects/PROJECT_1/repos/rep_1/settings/hooks/com.lb.software.stash.smart.commit.lb-software-stash-smart-commit:smart-post-hook/settings
Based on this configuration, we can put the above settings to the repository "rep_1" in the project "PROJECT_1" via the tool curl.
curl -H 'Content-Type: application/json' -X PUT -d '{ "jira.transitions.action.enabled": true, "jira.comments.action.enabled": true, "jira.worklog.action.enabled": true, "jira.worklog.action.remain.enabled": true, "jira.remain.action.enabled": true, "jira.assignee.action.enabled": true, "jira.component.action.enabled": true, "jira.label.action.enabled": true, "jira.prio.action.enabled": true, "jira.fixversion.action.enabled": true, "jira.affectedversion.action.enabled": true, "jira.issue.regex": "([A-Z][A-Z\\d_]*)-(\\d+)", "jira.comments.header.enabled": true, "jira.comments.header": "my new header", "bb.pull.action.enabled": true, "bb.comment.action.enabled": true, "bb.reviewer.action.enabled": true, "bb.task.action.enabled": true, "bb.approve.action.enabled": true, "bb.approve": "KEEP", "bb.response.level": "info", "bb.action.timeout": "500" }' http://admin:admin@bitbucket:7990/bitbucket/rest/api/1.0/projects/PROJECT_1/repos/rep_1/settings/hooks/com.lb.software.stash.smart.commit.lb-software-stash-smart-commit:smart-post-hook/settings