Skip to content

Instantly share code, notes, and snippets.

@onyxfish
Forked from anonymous/migrate_github_issues.py
Created December 12, 2012 14:44
Show Gist options
  • Save onyxfish/4268283 to your computer and use it in GitHub Desktop.
Save onyxfish/4268283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import getpass
import json
import requests
from requests.auth import HTTPBasicAuth
# CHANGE THESE CONSTANTS
USERNAME = 'onyxfish'
PASSWORD = getpass.getpass("Password:")
OLD_OWNER = 'npr'
NEW_OWNER = 'nprapps'
OLD_REPO = 'us-wildfires'
NEW_REPO = 'us-wildfires'
old_url = "https://api.github.com/repos/%s/%s/issues" % (OLD_OWNER, OLD_REPO)
new_url = "https://api.github.com/repos/%s/%s/issues" % (NEW_OWNER, NEW_REPO)
response = requests.get(old_url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
tickets = json.loads(response.content)
print 'Migrating %i tickets' % len(tickets)
for ticket in tickets:
print 'Migrating ticket %s' % ticket['title']
new_ticket = {
'title': ticket['title'],
'body': ticket['body'],
'assignee': ticket['assignee']['login'] if ticket['assignee'] else None,
# Milestones and labels need to be configured in the new project first
#'milestone': ticket['milestone']['number'],
#'labels': [l['name'] for l in ticket['labels']]
}
response = requests.post(new_url, data=json.dumps(new_ticket), auth=HTTPBasicAuth(USERNAME, PASSWORD))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment