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

Change merge_strategies via API

Julien Dephix September 29, 2024

Hi!

I'm working on a small Bitbucket App which would ensure PRs targeting `master` have a `merge --no-ff` strategy.

My app listens to `avi:bitbucket:created:pullrequest` events and updates the pull request if target = `master`.

It seems to work as I do not get any errors (I also update the title to make sure my PUT request is fine).

However when I click on `Merge` I still have the complete list of merge strategies and not the one I set earlier.

Any pointers as to why I can't have just one merge strategy in the Merge modal?

Here's the code which updates `title` but not `merge_strategies`.

const updatePr = async (workspaceId, repoId, prId) => {
    const requestUrl = route`/2.0/repositories/${workspaceId}/${repoId}/pullrequests/${prId}`;

    let response = await api.asApp().requestBitbucket(requestUrl, {
        method: "PUT",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            title: 'This is an updated title.',
            destination: {
                branch: {
                    merge_strategies: [
                        'merge_commit'
                    ]
                }
            }
        }),
    });

    return response.json();
};

Thanks!

3 answers

1 vote
Julien Dephix September 30, 2024

comment removed since I posted code in my original post.

0 votes
Saxea _Flowie_
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 1, 2024

Hi @Julien Dephix

I don't think this is supported. Did you base this on any documentation? I know you can set the default merge strategy at a repository level, ut not restrict the merge strategies, let alone for the PR.

We actually support this specifically in our app. Using Flowie you can set the merge strategy based on multiple conditions, including the target, like in your example. You can set the other options too, like the to close or not close. You can define them as default or lock them.

Regards,
Renato

Julien Dephix October 1, 2024

Hi @Saxea _Flowie_ 

I read the Rest API documentation (PUT to update a PR) and this is what can be sent in the body:bb-pr-put-rest-api.jpg

 

 Is that what you guys use?

Saxea _Flowie_
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 1, 2024

Is that what you guys use? 

 No, Flowie has its own implementation to support it.

I believe this is just a description of pull request properties, not necessarily what can be changed. For instance, you can't update id or links even though they are listed above as well.

Like # people like this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2024

Hi Jools,

I didn't see your code yesterday (perhaps you edited the post after I read it?).

Saxea _Flowie_ is actually right, you cannot change the available merge strategies with this API endpoint.

Kind regards,
Theodora

Julien Dephix October 2, 2024

Hi @Theodora Boudale .

Thank you for confirming. Is there an API endpoint which would let me do what I want? Or at least a way to limit via coe the entries in the merge strategies drop down?

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2024

Hi Jools,

I haven't been involved with app development so I don't know the reason why. However, I suggest posting your question either to the developer community:

Or, if this is a Forge app, in the 'Forge for Bitbucket Cloud' group here:

Kind regards,
Theodora

Julien Dephix October 1, 2024

Thanks @Theodora Boudale 

I'll wait a couple of days to see if anyone chimes in with a solution or pointers and then I'll post in the Forge section. Maybe @Edmund Munday knows as he's active in the forums you mentioned?

Thanks.

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events