Create a gist now

Instantly share code, notes, and snippets.

Bitbucket issue migration between repos
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 = '{0}/{1}/issues/?limit=50'.format(account_name, old_repo)
new_url = '{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:
r = requests.get(old_url+'&start={0}'.format(start), auth=auth)
content = json.loads(r.content)
count = content['count']
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():, data=data, auth=auth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment