Closed rafiyagi closed 8 years ago
I added authentication to my local copy based on this: http://stackoverflow.com/questions/635113/python-urllib2-basic-http-authentication-and-tr-im
bitbucket username and password were hardcoded in the base64string lines... obviously not ideal.
Here's the diff:
diff --git a/migrate.py b/migrate.py
old mode 100644
new mode 100755
index 95e1dda..ef5d5bc
--- a/migrate.py
+++ b/migrate.py
@@ -19,7 +19,7 @@ from datetime import datetime, timedelta
import urllib2
import time
import getpass
-
+import base64
import sys
try:
@@ -121,7 +121,10 @@ def get_comments(issue):
Fetch the comments for an issue
'''
url = "https://api.bitbucket.org/1.0/repositories/%s/%s/issues/%s/comments/" % (options.bitbucket_username, options.bitbucket_repo, issu
- result = json.loads(urllib2.urlopen(url).read())
+ request = urllib2.Request(url)
+ base64string = base64.encodestring('%s:%s' % ('', '')).replace('\n','')
+ request.add_header("Authorization", "Basic %s" % base64string)
+ result = json.loads(urllib2.urlopen(request).read())
comments = []
for comment in result:
@@ -143,7 +146,10 @@ issues = []
while True:
url = "https://api.bitbucket.org/1.0/repositories/%s/%s/issues/?start=%d" % (options.bitbucket_username, options.bitbucket_repo, options
try:
- response = urllib2.urlopen(url)
+ request = urllib2.Request(url)
+ base64string = base64.encodestring('%s:%s' % ('','')).replace('\n','')
+ request.add_header("Authorization", "Basic %s" % base64string)
+ response = urllib2.urlopen(request)
except urllib2.HTTPError as ex:
raise ValueError(
'Problem trying to connect to bitbucket ({url}): {ex} '
If a user submits BB creds, but the BB repo is public, then we shouldn't worry about whether the user's BB creds are authentic, we should just use the public API to grab the issues without authenticating.
So probably the workflow is:
Fixed in #59
Just a comment, not really an issue - this only works on issue trackers that are public in bitbucket, otherwise you'll get an HTTP error and the migration will fail.