Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


updated to work with github api v3 #3

merged 1 commit into from

2 participants


hi, i've just updated your script so that it works with github api v3 (as v2 is not supported anymore). because new api uses PATCH request method, i switched to requests python library. also, in some cases, github api responses with error 500 so i added condition that just prints out info that import of an issue failed and continues with import of following issues.

i do not code in python so maybe my patch could be written better, but at least it works for me.

thank you for the great script.

@ttencate ttencate merged commit ba821d2 into from

Thanks! The entire script is a "this just might work" thing, so don't worry about code quality. If it worked for you, it will probably work for other people. Otherwise, well, the old version didn't work for sure anyway :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 3, 2012
  1. @fordfrog
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 25 deletions.
  1. +25 −25
@@ -25,33 +25,31 @@
trackers = soup.document.find('trackers', recursive=False).findAll('tracker', recursive=False)
from urllib import urlencode
-from urllib2 import Request, urlopen, HTTPError
+from urllib2 import HTTPError
from base64 import b64encode
from time import sleep
from getpass import getpass
+import requests
+from requests.auth import HTTPBasicAuth
+import json
import re
-def __rest_call_unchecked(before, after, data_dict=None):
+def __rest_call_unchecked(method, request, data=None):
global github_repo, github_user, github_password
- url = '' % (before, github_repo, after)
- if data_dict is None:
- data = None
+ url = '' % (github_repo, request)
+ if method == 'PATCH':
+ response = requests.patch(url, data=json.dumps(data), auth=HTTPBasicAuth(github_user, github_password))
- data = urlencode([(unicode(key).encode('utf-8'), unicode(value).encode('utf-8')) for key, value in data_dict.iteritems()])
- headers = {
- 'Authorization': 'Basic %s' % b64encode('%s:%s' % (github_user, github_password)),
- }
- request = Request(url, data, headers)
- response = urlopen(request)
+ response =, data=json.dumps(data), auth=HTTPBasicAuth(github_user, github_password))
# GitHub limits API calls to 60 per minute
return response
-def rest_call(before, after, data_dict=None):
+def rest_call(method, request, data=None):
count500err = 0
while True:
- return __rest_call_unchecked(before, after, data_dict)
+ return __rest_call_unchecked(method, request, data)
except HTTPError, e:
print "Got HTTPError:", e
l = data_dict and max(map(len, data_dict.itervalues())) or 0
@@ -121,18 +119,20 @@ def handle_tracker_item(item, issue_title_prefix):
print 'Creating: %s [%s] (%d comments)%s for SF #%s' % (title, ','.join(labels), len(comments), ' (closed)' if closed else '',
- response = rest_call('issues/open', '', {'title': title, 'body': body})
- issue = BeautifulStoneSoup(response, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)
- number = issue.number.string
- for label in labels:
- print 'Attaching label: %s' % label
- rest_call('issues/label/add', '%s/%s' % (label, number))
- for comment in comments:
- print 'Creating comment: %s' % comment[:50].replace('\n', ' ').replace(chr(13), '')
- rest_call('issues/comment', number, {'comment': comment})
- if closed:
- print 'Closing...'
- rest_call('issues/close', number)
+ response = rest_call('POST', 'issues', {'title': title, 'body': body})
+ if response.status_code == 500:
+ print "ISSUE CAUSED SERVER SIDE ERROR AND WAS NOT SAVED!!! Import will continue."
+ else:
+ issue = response.json
+ number = issue['number']
+ print 'Attaching labels: %s' % labels
+ rest_call('POST', 'issues/%s/labels' % (number), labels)
+ for comment in comments:
+ print 'Creating comment: %s' % comment[:50].replace('\n', ' ').replace(chr(13), '')
+ rest_call('POST', 'issues/%s/comments' % (number), {'body': comment})
+ if closed:
+ print 'Closing...'
+ rest_call('PATCH', 'issues/%s' % (number), {'state': 'closed'})
import signal
Something went wrong with that request. Please try again.