Hi,
I've been looking at the REST API to try and find a way to enable some merge checks on projects and repos but have found a few that require configuration as well as being enabled. So far I've been able to enable some hooks without configurations using:
curl -u <username> -X PUT -H "Accept: application/json" -H "Content-Type: application/json" https://<BitBucket URL>/rest/api/1.0/projects/<project key>/repos/<repo slug>/settings/hooks/<hook key>/enabled -d "{\"enabled\":\"true\"}"
Is there a way through the API to enable and configure a merge check?
I managed to resolve this problem by pushing the configurations for the hooks to the "/enabled" URL. For example with the Minimum Successful Builds merge check, used the following:
curl -u <username> -X PUT -H "Accept: application/json" -H "Content-Type: application/json" https://<BitBucketURL>/rest/api/1.0/projects/<ProjectKey>/repos/<RepoSlug>/settings/hooks/<MinimumSuccessfulBuildsHookKey>/enabled -d "{\"requiredCount\":\"2\"}"
This enabled and configured the merge check.
Nice work!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The key for minimum builds is "com.atlassian.bitbucket.server.bitbucket-build:requiredBuildsMergeCheck", and instead of hitting "/enabled" you can PUT against "/settings" for hooks that take config.
Try this (GET and PUT):
/bitbucket/rest/api/1.0/projects/PROJECT_1/repos/rep_1/settings/hooks/com.atlassian.bitbucket.server.bitbucket-build:requiredBuildsMergeCheck/settings
Here's the docs for it: docs.atlassian.com/bitbucket-server/rest/5.14.0
Out of curiosity, why do you want to set these via REST API ? We maintain some Bitbucket add-ons, and we're always on the lookout for possible new features we might implement.
In particular we maintain PR-Booster, which contains logic to prevent "Minimum Successful Builds" from causing rebase fights.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I try to PUT "enabled:true" against "/settings" I get an error back saying:
{"errors":[{"context":"requiredCount","message":"The number of required builds must be provided.","exceptionName":null}]}
This made me think I'd have to push the settings as well so I tried "enabled:true, requiredCount:2" but it still didn't populate the configuration correctly.
I'm still fairly new to the REST API so I'm wondering if there's something I'm missing in the call or if this is even possible.
We're wanting to use the REST API to enable/modify different merge checks across numerous repos as a way of managing them in an automated way.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.