@@ -122,11 +122,40 @@ def sync_organizations(self):
122
122
remote_organizations .append (remote_organization )
123
123
124
124
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
+
130
159
except (TypeError , ValueError ):
131
160
log .warning ('Error syncing GitLab organizations' )
132
161
raise SyncServiceError (
0 commit comments