Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trying to automate the creation of a pull request and a merge

Our branching approach is to have a master and production branch. Changes committed to our production branch are pushed to our repository nightly, via a 'git push' on our production server. Upon completion of the push, we would like an automated process that would:

1. Create a pull request to merge changes from production branch to the master branch

2. Auto approve the pull request

3. Auto-merge the pull request from production branch to master branch

4. Send email to predefined BitBucket Admin user, if any of the previous steps failed.

I reviewed the tutorials and examples from ScriptRunner, but it does not appear to offer this type of 'post-hook' process. Is this type of automation possible? How would we accomplish this?

Thank you!

1 answer

1 accepted

Hi @rdennisj,

Thank you for your question.

I am the Product Manager for ScriptRunner for Bitbucket.

I would look at the following in order to answer your requirements using ScriptRunner for Bitbucket.

1. Create a pull request to merge changes from production branch to the master branch

For this you could use a Custom Post Hook (https://scriptrunner.adaptavist.com/latest/bitbucket/PostReceiveHooks.html#_custom_post_receive_hooks), where the custom code for the Post Hook programatically creates the Pull Request using the Bitbucket API.

However, as an alternative, I believe you could also use the same Custom Post Hook to programatically run a merge commit onto the master branch without the need for a Pull Request. Thus removing requirements 2 and 3 altogether.

2. Auto approve the pull request

Given that you also want to auto-merge a Pull Request, I don't believe this is actually required, as the Pull Request could be created with no approvers on it.

 3. Auto-merge the pull request from production branch to master branch

We do have a built-in Event Handler that allows for auto-merging of Pull Requests (https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_auto_merge_pull_request).

However, I would recommend a Custom Event Handler that responded to a Pull Request Created Event, because of requirement number 4. Again, the Custom Event Handler could auto-merge the Pull Request using the Bitbucket API.

Here is an example Custom Event Handler (albeit that updates JIRA issues upon Pull Request creation): https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_update_all_related_jira_issues_when_pull_request_opened

4. Send email to predefined BitBucket Admin user, if any of the previous steps failed.

We do again have built-in Post Hook's and Event Handlers that can send emails:

https://scriptrunner.adaptavist.com/latest/bitbucket/PostReceiveHooks.html#_send_mail

https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_send_mail

However, if you are using the Custom Post Hook and Custom Event Handler suggests listed in sections 1 and 3 above, then you can include error handling in your custom scripts.

Here is an example Custom Event Handler, which posts custom Slack messages, when a Repo is forked for example: https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_post_to_em_slack_em_when_a_repository_is_forked

Finally, this looks like an interesting use case of ScriptRunner for Bitbucket and I will look to see if we could include this functionality as a Built-in Script inside the product, in the future.

Please let me know if you require any additional help?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Robert, Thank you for the detailed reply!  We will definitely pursue your suggestion in step 1 to run a merge commit, instead of creating a pull request. Our Production branch is the ONLY branch in our implementation that will apply updates to the Master branch, and will be done ONLY via nightly merges, so there is no change there will be any code conflicts, and no reason to go thru any code reviews or approvals. 

I will update this reply after we have completed/tested the Custom Post Hook.

Thank you again!

I would like this thread to be re-initiated, we are a corporate user of Atlassian products, we are looking for a way to 'lint' the PRs and auto-approve & merge based on the kind of changes done.

We dont have hooks enabled by our admin team, what options do i have to make this happen?

 

Appreciate your time and guidance.

Hi @suryachandra27 ,

Are you a ScriptRunner for Bitbucket customer?

As the ScriptRunner for Bitbucket team might be able to help you.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

84 views 2 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you