public
Created

Bitbucket issue migration between repos

  • Download Gist
bitbucket-issue-migration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import requests
import json
from requests.auth import HTTPBasicAuth
 
account_name = 'MY_NICKNAME'
password = 'PASSWORD'
old_repo = 'OLD_REPO'
new_repo = 'NEW_REPO'
old_url = 'https://api.bitbucket.org/1.0/repositories/{0}/{1}/issues/?limit=50'.format(account_name, old_repo)
new_url = 'https://api.bitbucket.org/1.0/repositories/{0}/{1}/issues/'.format(account_name, new_repo)
auth = HTTPBasicAuth(account_name, password)
 
# Getting old issues
result = []
start = 0
count = 1
while True:
if start > count:
break
r = requests.get(old_url+'&start={0}'.format(start), auth=auth)
content = json.loads(r.content)
count = content['count']
result.extend(content['issues'])
start += 50
 
# converting to payload
new_res = dict([(x['local_id'], {'title':x['title'],'content':x['content'],'status':x['status'],'priority':x['priority'],'kind':x['metadata']['kind']}) for x in result])
for data in new_res.values():
requests.post(new_url, data=data, auth=auth)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.