0

I have the original content, that I need the expected output like below.

curl -X POST -H "Content-Type: application/json" https://bitbucket.org/api/2.0/repositories/username/BB_Access/pullrequests -d '{ "title": "Merge dev branch to Master", "source": { "branch": { "name": "Dev" }, "repository": { "full_name": "username/BB_Access" } }, "destination": { "branch": { "name": "master" } }, "close_source_branch": false }'

Below is the code that I have tried.

import subprocess
BBrepo = "BB_Access"
BBuser = "username"
src_branch = "Dev"
Dest_branch = "master"
pull_command = "curl -X POST -H "'"Content-Type: application/json"'" https://bitbucket.org/api/2.0/repositories/"+BBuser+"/"+BBrepo+"/pullrequests -d '"'{ "title": "python_pull_request", "source": { "branch": { "name": '"' "+src_branch+" }, '"'repository": { "full_name": '"'"+BBuser+"/"+BBrepo+" } }, '"'destination": { "branch": { "name": '"'"+Dest_branch+'"'" } }, '"'close_source_branch": false }'"'"

print pull_command

but it is giving the output as below

curl -X POST -H "Content-Type: application/json" https://bitbucket.org/api/2.0/repositories/username/BB_Access/pullrequests -d '{ "title": "python_pull_request", "source": { "branch": { "name": ' Dev }, 'repository": { "full_name": 'username/BB_Access } }, 'destination": { "branch": { "name": 'master" } }, 'close_source_branch": false }'

can any one suggest me the better way to get the expected output.

2 Answers 2

1

I see two ways:

  • use " inside '' (or the opposite)
  • escape, as "\"" or '\''
Sign up to request clarification or add additional context in comments.

Comments

0

You can try this:

import subprocess
BBrepo = "BB_Access"
BBuser = "username"
src_branch = "Dev"
Dest_branch = "master"
pull_command = 'curl -X POST -H "Content-Type: application/json" https://bitbucket.org/api/2.0/repositories/'+BBuser+'/'+BBrepo+'/pullrequests -d \'{ "title": "python_pull_request", "source": { "branch": { "name": '+'"'+src_branch+'"'+' }, "repository": { "full_name": '+'"'+BBuser+'/'+BBrepo+'"'+' } }, "destination": { "branch": { "name": '+'"'+Dest_branch+'"'+' } }, "close_source_branch": false }\''

print(pull_command)

Ang get :

curl -X POST -H "Content-Type: application/json" https://bitbucket.org/api/2.0/repositories/username/BB_Access/pullrequests -d '{ "title": "python_pull_request", "source": { "branch": { "name": "Dev" }, "repository": { "full_name": "username/BB_Access" } }, "destination": { "branch": { "name": "master" } }, "close_source_branch": false }'

1 Comment

Worked perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.