Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to capture pull request creation event in bitbucket using python script

Jayadev Pentapati
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2020

‘’’’
Need to know if there is any possible way to capture the event of pull request creation in bitbucket to write a custom script using this event.

Dont want PR to trigger any automatic build instead just need capture the pr creation event to write a custom python script to trigger certain activities through script run.

One option is to read/continuous poll the bit bucket PR creation page to identify the activity/event but it sounds to be a bad scripting standard and not a good practice.

Is there any git command to identify PR creation at feature branch and to merge into parent(say its DEV) and also git command to capture PR default reviewer names???

So that, these git commandS can be used in script To track if any PR is raised?

Verified many websites and read many articals and unfortunately no where found the possibility to capture the PR creation event in but bucket?

Great if anyone can post the possibility to capture the event to write our own custom logic with the PR event capture
‘’’’

1 answer

0 votes
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 16, 2020

Hello Jayadev, welcome to the Community!

Sounds like you're trying to trigger action in an external system (possibly a python script of your own making) when a pull request is created in Bitbucket, yes?

Fortunately there's a mechanism for triggering API calls on PR creation and many other events: webhooks

Without webhooks, if you want to detect when events occur in Bitbucket Cloud, you need to poll the API. However, polling the API is inconvenient, inefficient, and error-prone. Consider how SMS messages work on mobile phones. You don't have to check your messages every 5 minutes to see if you have a text because your phone sends you a notification. In the same way, webhooks work like the notification so that the API does not have to check for the same activity every minute.

In Bitbucket's repository settings, you create the webhook and its trigger events. You'll need to provide the URL of a service listening for events; this can be a bit tricky if you're considering a python script. There are a few routes you could go down:

  1. Use a python library that creates a listening server. With Javascript, this would be something like node.js. In python, you have options like socket from the standard library
  2. You could put your script into a serverless service like AWS Lambda that runs a small docker container and executes your script when it receives a trigger
  3. Depending on complexity, you could use a service like Zapier or IFTTT to receive the webhook from Bitbucket and trigger additional API calls in your destination applications.

More information about configuring webhooks and what triggers you can use are available in our documentation: Manage webhooks in Bitbucket 

I hope this helps and happy to clarify any points you're unsure about!

Cheers,
Daniel

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events