Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Enabling Minimum successful builds merge check through REST API

ejobson October 11, 2018

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? 

2 answers

2 votes
ejobson October 12, 2018

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. 

Julius Davies [bit-booster.com]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2018

 

Nice work!

0 votes
Julius Davies [bit-booster.com]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2018

 

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.

 

 

ejobson October 12, 2018

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.  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events