MergeCheck plugin - obtaining Minimum Approvals config value

Hi

How do I determine what the current value of “Minimum Approvals” merge check from the code inside a merge check plugin?

I tried this:

public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context,
                                      @Nonnull PullRequestMergeHookRequest request) {

            int requiredApprovals = context.getSettings().getInt("approvals", 0);

            log.info("settings: " + context.getSettings().asMap() );

The ‘Settings’ map is always empty.

Thanks

You have to hit the REST endpoint that provides this data:

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests

Documentation here:

https://docs.atlassian.com/bitbucket-server/rest/6.4.1/bitbucket-rest.html#idp307

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests => endpoint for a specific repository.

But if I have to change the number of the PROJECT minimum approvals ?
I got the endpoint to enable it (/rest/api/1.0/projects/{projectKey}/settings/hooks), but the API don’t have the option to set the number (count) of approvers.

Anyone knows how to do it ?

PUT against this endpoint (and GET to see the current value):

/rest/api/1.0/projects/{projectKey}/settings/hooks/com.atlassian.bitbucket.server.bitbucket-bundled-hooks:requiredApproversMergeHook/settings

Docs for this specific endpoint are here (“/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}”):

https://docs.atlassian.com/bitbucket-server/rest/6.4.1/bitbucket-rest.html#idp312

1 Like