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

automate file content update and commit the change using python

Rijin Raju
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!
May 30, 2024

i am trying to automate some task ,where i need to connect a bitbucket project and need to visit every repos and  branches in each repos delete some content on the file present in every branches and commit the changes remotly using python script.

2 answers

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

Hi Rijin and welcome to the community!

We have an API endpoint that can be used to create a commit in a remote repo by uploading a file (a file that exists on the computer where you run this API call):

If the file exists in the remote repo, its content will be replaced with the content of the file you are uploading. The branch can be specified the same way as the file, e.g. with curl you add -F branch=branch-name in the request.

The following API endpoints can be used for retrieving all repos in a workspace (that you have access to) and all open branches in a certain repo respectively:

Kind regards,
Theodora

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2024

If I were you I would do this Git:

  • for each repo
    • git clone it 
      • for each branch
        • git pull it
        • update the file
        • git commit it
    • git push all branches

You can do this using by running the Git commandline client from Python. The nicety is that you don't even need to tie yourself to Bitbucket, which means flexibility (you can migrate to any Git hosting platform in the future).

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events