Mam oryginalną treść, że potrzebuję oczekiwanego wyjścia jak poniżej.

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 }'

Poniżej znajduje się kod, który próbowałem.

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

Ale daje wyjście jak poniżej

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 }'

Czy ktoś może zasugerować mi lepszy sposób na uzyskanie oczekiwanej mocy.

0
moong 27 luty 2019, 10:10

1 odpowiedź

Najlepsza odpowiedź

Możesz spróbować tego:

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 }'
0
mee 27 luty 2019, 07:47