Skip to content

Commit b5e03f2

Browse files
authored
Set The Right Permissions on GitLab OAuth RemoteRepository (#7753)
Set the right permissions on GitLab OAuth RemoteRepository
1 parent cf38ce2 commit b5e03f2

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

readthedocs/oauth/services/gitlab.py

+34-5
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,40 @@ def sync_organizations(self):
122122
remote_organizations.append(remote_organization)
123123

124124
for repo in org_repos:
125-
remote_repository = self.create_repository(
126-
repo,
127-
organization=remote_organization,
128-
)
129-
remote_repositories.append(remote_repository)
125+
# TODO: Optimize this so that we don't re-fetch project data
126+
# Details: https://github.com/readthedocs/readthedocs.org/issues/7743
127+
try:
128+
# The response from /groups/{id}/projects API does not contain
129+
# admin permission fields for GitLab projects.
130+
# So, fetch every single project data from the API
131+
# which contains the admin permission fields.
132+
resp = self.get_session().get(
133+
'{url}/api/v4/projects/{id}'.format(
134+
url=self.adapter.provider_base_url,
135+
id=repo['id']
136+
)
137+
)
138+
139+
if resp.status_code == 200:
140+
repo_details = resp.json()
141+
remote_repository = self.create_repository(
142+
repo_details,
143+
organization=remote_organization
144+
)
145+
remote_repositories.append(remote_repository)
146+
else:
147+
log.warning(
148+
'GitLab project does not exist or user does not have '
149+
'permissions: project=%s',
150+
repo['name_with_namespace'],
151+
)
152+
153+
except Exception:
154+
log.exception(
155+
'Error creating GitLab repository=%s',
156+
repo['name_with_namespace'],
157+
)
158+
130159
except (TypeError, ValueError):
131160
log.warning('Error syncing GitLab organizations')
132161
raise SyncServiceError(

0 commit comments

Comments
 (0)