jeffwidman / bitbucket-issue-migration

A small script for migrating repo issues from Bitbucket to GitHub
GNU General Public License v3.0
313 stars 97 forks source link

username -> nickname (change of bitbucket API?) #119

Closed bjornbm closed 4 years ago

bjornbm commented 5 years ago

I had to make this change for the migration to work. It seemed like the right thing to do and the results of a migration look fine to me.

jeffwidman commented 5 years ago

Hmm... is the nickname vs username difference documented anywhere on bitbucket? I'd like to understand the difference better before pulling this in

bjornbm commented 5 years ago

The problem I was having was that I got an error message regarding the username not being a field of the user object. Inspecting the user object it seemed nickname was the closest thing available.

See https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr. In particular

The short summary is that username endpoints and username fields will stop being available on 29 April 2019, and we're introducing some new data points that are available immediately to replace them.

and

In all cases where Bitbucket APIs return user details, we are introducing two new fields to the object body, Atlassian account ID account_id and nickname.

jeffwidman commented 5 years ago

Thanks for digging that up.

Reading through the linked doc, I noticed that:

Given the above, would display_name be more appropriate than nickname? I have not played with the API so I don't know if it actually returns this... sometimes docs do not match reality.

bjornbm commented 5 years ago

Here is a user as passed to format_user of migrate.py:

{
'display_name': 'Björn Buckwalter',
'uuid': '{647e413e-1269-4aec-912f-9e214acb1df7}', 
'links': {
    'self': {'href': 'https://api.bitbucket.org/2.0/users/%7B647e413e-1269-4aec-912f-9e214acb1df7%7D'},
    'html': {'href': 'https://bitbucket.org/%7B647e413e-1269-4aec-912f-9e214acb1df7%7D/'},
    'avatar': {'href': 'https://avatar-cdn.atlassian.com/557058%3A4d58b2d4-edfd-4232-9dc6-8cf28044ca15?by=id&sg=RyTjFmqMnVDGE99Y8FOwSaiPt24%3D&d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBB-0.png'}
},
'nickname': 'bjornbm',
'type': 'user',
'account_id': '557058:4d58b2d4-edfd-4232-9dc6-8cf28044ca15'
}

Here are lines 658–661 of migrate.py:

    bb_user = "Bitbucket: [{0}](https://bitbucket.org/{0})".format(user['nickname'])
    gh_username = _gh_username(user['nickname'], options.users, options.gh_auth)
    if gh_username is not None:
        gh_user = "GitHub: [{0}](https://github.com/{0})".format(gh_username)

Observations:

  1. These work as-is when using nickname (assuming the user reused their Bitbucket username on GitHub as per README.md).
  2. If using display_name both Bitbucket and Github URLs are broken.
  3. The uuid can be used to construct a Bitbucket URL (https://bitbucket.org/%7B647e413e-1269-4aec-912f-9e214acb1df7%7D/ in this case) but clearly is not useful for constucting a Github URL.
jeffwidman commented 4 years ago

Thanks! And sorry about this--I totally forgot about it