Skip to content

Set The Right Permissions on GitLab OAuth RemoteRepository #7753

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 3 commits into from
Dec 16, 2020
Merged
Changes from 1 commit
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
34 changes: 29 additions & 5 deletions readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,35 @@ def sync_organizations(self):
remote_organizations.append(remote_organization)

for repo in org_repos:
remote_repository = self.create_repository(
repo,
organization=remote_organization,
)
remote_repositories.append(remote_repository)
try:
# Get response for a single repository with permission data
resp = self.get_session().get(
'{url}/api/v4/projects/{id}'.format(
url=self.adapter.provider_base_url,
id=repo['id']
)
)

if resp.status_code == 200:
repo_details = resp.json()
remote_repository = self.create_repository(
repo_details,
organization=remote_organization
)
remote_repositories.append(remote_repository)
else:
log.warning(
'GitLab project does not exist or user does not have '
'permissions: project=%s',
repo['name_with_namespace'],
)

except Exception:
log.exception(
'Error creating GitLab repository=%s',
repo['name_with_namespace'],
)

except (TypeError, ValueError):
log.warning('Error syncing GitLab organizations')
raise SyncServiceError(
Expand Down