Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only works on public issues/repositories on bitbucket #8

Closed
rafiyagi opened this issue Apr 14, 2014 · 4 comments
Closed

Only works on public issues/repositories on bitbucket #8

rafiyagi opened this issue Apr 14, 2014 · 4 comments

Comments

@rafiyagi
Copy link

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.

@rafiyagi rafiyagi reopened this Apr 14, 2014
@dwstevens
Copy link

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} '

pomu0325 added a commit to pomu0325/bitbucket_issue_migration that referenced this issue Nov 23, 2014
@jeffwidman
Copy link
Owner

#22 tackles this. Waiting for it to be rebased before merging.

@jeffwidman
Copy link
Owner

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:

  • regardless of whether the user provided BB creds, we should try the BB repo without auth
  • only if we get back a 401 do we check for BB auth creds--if the user didn't include them, then complain
  • if the user included BB auth creds, and we already know it's not a public repo, then we try again to access it
    • if we still get a 404 or 401, complain appropriately to the user

@jeffwidman
Copy link
Owner

Fixed in #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants