Skip to content

Bitbucket: update to match latest API changes #8801

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

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions readthedocs/oauth/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ def sync_repositories(self):
return remote_repositories

def sync_organizations(self):
"""Sync Bitbucket teams (our RemoteOrganization) and team repositories."""
"""Sync Bitbucket workspaces(our RemoteOrganization) and workspace repositories."""
remote_organizations = []
remote_repositories = []

try:
teams = self.paginate(
'https://api.bitbucket.org/2.0/teams/?role=member',
workspaces = self.paginate(
'https://api.bitbucket.org/2.0/workspaces/?role=member',
)
for team in teams:
remote_organization = self.create_organization(team)
repos = self.paginate(team['links']['repositories']['href'])
for workspace in workspaces:
remote_organization = self.create_organization(workspace)
repos = self.paginate(workspace['links']['repositories']['href'])

remote_organizations.append(remote_organization)

Expand All @@ -106,7 +106,7 @@ def sync_organizations(self):
except ValueError:
log.warning('Error syncing Bitbucket organizations')
raise SyncServiceError(
'Could not sync your Bitbucket team repositories, '
'Could not sync your Bitbucket workspace repositories, '
'try reconnecting your account',
)

Expand Down Expand Up @@ -200,16 +200,13 @@ def create_organization(self, fields):
self.user, self.account
)

organization.slug = fields.get('username')
organization.name = fields.get('display_name')
organization.email = fields.get('email')
organization.slug = fields.get('slug')
organization.name = fields.get('name')
organization.url = fields['links']['html']['href']
organization.avatar_url = fields['links']['avatar']['href']

if not organization.avatar_url:
organization.avatar_url = self.default_org_avatar_url

organization.url = fields['links']['html']['href']

organization.save()

return organization
Expand Down
29 changes: 17 additions & 12 deletions readthedocs/rtd_tests/tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,34 +567,39 @@ def setUp(self):
}

self.team_response_data = {
'username': 'teamsinspace',
'website': None,
'display_name': 'Teams In Space',
'slug': 'teamsinspace',
'name': 'Teams In Space',
'uuid': '{61fc5cf6-d054-47d2-b4a9-061ccf858379}',
'links': {
'self': {
'href': 'https://api.bitbucket.org/2.0/teams/teamsinspace',
'href': 'https://api.bitbucket.org/2.0/workspaces/teamsinspace',
},
'repositories': {
'href': 'https://api.bitbucket.org/2.0/repositories/teamsinspace',
},
'html': {'href': 'https://bitbucket.org/teamsinspace'},
'followers': {
'href': 'https://api.bitbucket.org/2.0/teams/teamsinspace/followers',
},
'avatar': {
'href': 'https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2014/Sep/24/teamsinspace-avatar-3731530358-7_avatar.png',
},
'members': {
'href': 'https://api.bitbucket.org/2.0/teams/teamsinspace/members',
'href': 'https://api.bitbucket.org/2.0/workspaces/teamsinspace/members',
},
'owners': {
'href': 'https://api.bitbucket.org/2.0/workspaces/teamsinspace/members?q=permission%3D%22owner%22',
},
'hooks': {
'href': 'https://api.bitbucket.org/2.0/workspaces/teamsinspace/hooks',
},
'snippets': {
'href': 'https://api.bitbucket.org/2.0/snippets/teamsinspace/',
},
'following': {
'href': 'https://api.bitbucket.org/2.0/teams/teamsinspace/following',
'projects': {
'href': 'https://api.bitbucket.org/2.0/workspaces/teamsinspace/projects',
},
},
'created_on': '2014-04-08T00:00:14.070969+00:00',
'location': None,
'type': 'team',
'type': 'workspace',
'is_private': True,
}

def test_make_project_pass(self):
Expand Down