@@ -41,6 +41,10 @@ class GitLabService(Service):
41
41
re .escape (urlparse (adapter .provider_base_url ).netloc ),
42
42
)
43
43
44
+ PERMISSION_NO_ACCESS = 0
45
+ PERMISSION_MAINTAINER = 40
46
+ PERMISSION_OWNER = 50
47
+
44
48
def _get_repo_id (self , project ):
45
49
# The ID or URL-encoded path of the project
46
50
# https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding
@@ -132,13 +136,20 @@ def sync_organizations(self):
132
136
133
137
return remote_organizations , remote_repositories
134
138
135
- def is_owned_by (self , owner_id ):
136
- return self .account .extra_data ['id' ] == owner_id
137
-
138
139
def create_repository (self , fields , privacy = None , organization = None ):
139
140
"""
140
141
Update or create a repository from GitLab API response.
141
142
143
+ ``admin`` field is computed using the ``permissions`` fields from the
144
+ repository response. The permission from GitLab is given by an integer:
145
+ * 0: No access
146
+ * (... others ...)
147
+ * 40: Maintainer
148
+ * 50: Owner
149
+
150
+ https://docs.gitlab.com/ee/api/access_requests.html
151
+ https://gitlab.com/help/user/permissions
152
+
142
153
:param fields: dictionary of response data from API
143
154
:param privacy: privacy level to support
144
155
:param organization: remote organization to associate with
@@ -179,9 +190,17 @@ def create_repository(self, fields, privacy=None, organization=None):
179
190
else :
180
191
repo .clone_url = fields ['http_url_to_repo' ]
181
192
182
- repo .admin = not repo_is_public
183
- if not repo .admin and 'owner' in fields :
184
- repo .admin = self .is_owned_by (fields ['owner' ]['id' ])
193
+ project_access_level = group_access_level = self .PERMISSION_NO_ACCESS
194
+ project_access = fields .get ('permissions' , {}).get ('project_access' , {})
195
+ if project_access :
196
+ project_access_level = project_access .get ('access_level' , self .PERMISSION_NO_ACCESS )
197
+ group_access = fields .get ('permissions' , {}).get ('group_access' , {})
198
+ if group_access :
199
+ group_access_level = group_access .get ('access_level' , self .PERMISSION_NO_ACCESS )
200
+ repo .admin = any ([
201
+ project_access_level in (self .PERMISSION_MAINTAINER , self .PERMISSION_OWNER ),
202
+ group_access_level in (self .PERMISSION_MAINTAINER , self .PERMISSION_OWNER ),
203
+ ])
185
204
186
205
repo .vcs = 'git'
187
206
repo .account = self .account
0 commit comments