@@ -126,7 +126,7 @@ class UserKey(ObjectDeleteMixin, RESTObject):
126
126
127
127
128
128
class UserKeyManager (GetFromListMixin , CreateMixin , DeleteMixin , RESTManager ):
129
- _path = '/users/%(user_id)s/emails '
129
+ _path = '/users/%(user_id)s/keys '
130
130
_obj_cls = UserKey
131
131
_from_parent_attrs = {'user_id' : 'id' }
132
132
_create_attrs = (('title' , 'key' ), tuple ())
@@ -842,8 +842,8 @@ def enable(self, key_id, **kwargs):
842
842
GitlabAuthenticationError: If authentication is not correct
843
843
GitlabProjectDeployKeyError: If the key could not be enabled
844
844
"""
845
- path = '%s/%s/enable' % (self .manager . path , key_id )
846
- self .manager . gitlab .http_post (path , ** kwargs )
845
+ path = '%s/%s/enable' % (self .path , key_id )
846
+ self .gitlab .http_post (path , ** kwargs )
847
847
848
848
849
849
class ProjectEvent (RESTObject ):
@@ -999,17 +999,19 @@ def set_release_description(self, description, **kwargs):
999
999
data = {'description' : description }
1000
1000
if self .release is None :
1001
1001
try :
1002
- result = self .manager .gitlab .http_post (path , post_data = data ,
1003
- ** kwargs )
1002
+ server_data = self .manager .gitlab .http_post (path ,
1003
+ post_data = data ,
1004
+ ** kwargs )
1004
1005
except exc .GitlabHttpError as e :
1005
1006
raise exc .GitlabCreateError (e .response_code , e .error_message )
1006
1007
else :
1007
1008
try :
1008
- result = self .manager .gitlab .http_put (path , post_data = data ,
1009
- ** kwargs )
1009
+ server_data = self .manager .gitlab .http_put (path ,
1010
+ post_data = data ,
1011
+ ** kwargs )
1010
1012
except exc .GitlabHttpError as e :
1011
1013
raise exc .GitlabUpdateError (e .response_code , e .error_message )
1012
- self .release = result . json ()
1014
+ self .release = server_data
1013
1015
1014
1016
1015
1017
class ProjectTagManager (GetFromListMixin , CreateMixin , DeleteMixin ,
@@ -1223,8 +1225,7 @@ def merge_requests(self, **kwargs):
1223
1225
return RESTObjectList (manager , ProjectMergeRequest , data_list )
1224
1226
1225
1227
1226
- class ProjectMilestoneManager (RetrieveMixin , CreateMixin , DeleteMixin ,
1227
- RESTManager ):
1228
+ class ProjectMilestoneManager (CRUDMixin , RESTManager ):
1228
1229
_path = '/projects/%(project_id)s/milestones'
1229
1230
_obj_cls = ProjectMilestone
1230
1231
_from_parent_attrs = {'project_id' : 'id' }
@@ -1239,6 +1240,26 @@ class ProjectLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin,
1239
1240
RESTObject ):
1240
1241
_id_attr = 'name'
1241
1242
1243
+ # Update without ID, but we need an ID to get from list.
1244
+ @exc .on_http_error (exc .GitlabUpdateError )
1245
+ def save (self , ** kwargs ):
1246
+ """Saves the changes made to the object to the server.
1247
+
1248
+ The object is updated to match what the server returns.
1249
+
1250
+ Args:
1251
+ **kwargs: Extra options to send to the server (e.g. sudo)
1252
+
1253
+ Raises:
1254
+ GitlabAuthenticationError: If authentication is not correct.
1255
+ GitlabUpdateError: If the server cannot perform the request.
1256
+ """
1257
+ updated_data = self ._get_updated_data ()
1258
+
1259
+ # call the manager
1260
+ server_data = self .manager .update (None , updated_data , ** kwargs )
1261
+ self ._update_attrs (server_data )
1262
+
1242
1263
1243
1264
class ProjectLabelManager (GetFromListMixin , CreateMixin , UpdateMixin ,
1244
1265
DeleteMixin , RESTManager ):
@@ -1262,27 +1283,7 @@ def delete(self, name, **kwargs):
1262
1283
GitlabAuthenticationError: If authentication is not correct.
1263
1284
GitlabDeleteError: If the server cannot perform the request.
1264
1285
"""
1265
- self .gitlab .http_delete (path , query_data = {'name' : self .name }, ** kwargs )
1266
-
1267
- # Update without ID, but we need an ID to get from list.
1268
- @exc .on_http_error (exc .GitlabUpdateError )
1269
- def save (self , ** kwargs ):
1270
- """Saves the changes made to the object to the server.
1271
-
1272
- The object is updated to match what the server returns.
1273
-
1274
- Args:
1275
- **kwargs: Extra options to send to the server (e.g. sudo)
1276
-
1277
- Raises:
1278
- GitlabAuthenticationError: If authentication is not correct.
1279
- GitlabUpdateError: If the server cannot perform the request.
1280
- """
1281
- updated_data = self ._get_updated_data ()
1282
-
1283
- # call the manager
1284
- server_data = self .manager .update (None , updated_data , ** kwargs )
1285
- self ._update_attrs (server_data )
1286
+ self .gitlab .http_delete (self .path , query_data = {'name' : name }, ** kwargs )
1286
1287
1287
1288
1288
1289
class ProjectFile (SaveMixin , ObjectDeleteMixin , RESTObject ):
@@ -1297,6 +1298,38 @@ def decode(self):
1297
1298
"""
1298
1299
return base64 .b64decode (self .content )
1299
1300
1301
+ def save (self , branch , commit_message , ** kwargs ):
1302
+ """Save the changes made to the file to the server.
1303
+
1304
+ The object is updated to match what the server returns.
1305
+
1306
+ Args:
1307
+ branch (str): Branch in which the file will be updated
1308
+ commit_message (str): Message to send with the commit
1309
+ **kwargs: Extra options to send to the server (e.g. sudo)
1310
+
1311
+ Raise:
1312
+ GitlabAuthenticationError: If authentication is not correct
1313
+ GitlabUpdateError: If the server cannot perform the request
1314
+ """
1315
+ self .branch = branch
1316
+ self .commit_message = commit_message
1317
+ super (ProjectFile , self ).save (** kwargs )
1318
+
1319
+ def delete (self , branch , commit_message , ** kwargs ):
1320
+ """Delete the file from the server.
1321
+
1322
+ Args:
1323
+ branch (str): Branch from which the file will be removed
1324
+ commit_message (str): Commit message for the deletion
1325
+ **kwargs: Extra options to send to the server (e.g. sudo)
1326
+
1327
+ Raises:
1328
+ GitlabAuthenticationError: If authentication is not correct
1329
+ GitlabDeleteError: If the server cannot perform the request
1330
+ """
1331
+ self .manager .delete (self .get_id (), branch , commit_message , ** kwargs )
1332
+
1300
1333
1301
1334
class ProjectFileManager (GetMixin , CreateMixin , UpdateMixin , DeleteMixin ,
1302
1335
RESTManager ):
@@ -1308,11 +1341,12 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin,
1308
1341
_update_attrs = (('file_path' , 'branch' , 'content' , 'commit_message' ),
1309
1342
('encoding' , 'author_email' , 'author_name' ))
1310
1343
1311
- def get (self , file_path , ** kwargs ):
1344
+ def get (self , file_path , ref , ** kwargs ):
1312
1345
"""Retrieve a single file.
1313
1346
1314
1347
Args:
1315
- id (int or str): ID of the object to retrieve
1348
+ file_path (str): Path of the file to retrieve
1349
+ ref (str): Name of the branch, tag or commit
1316
1350
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
1317
1351
1318
1352
Raises:
@@ -1323,7 +1357,49 @@ def get(self, file_path, **kwargs):
1323
1357
object: The generated RESTObject
1324
1358
"""
1325
1359
file_path = file_path .replace ('/' , '%2F' )
1326
- return GetMixin .get (self , file_path , ** kwargs )
1360
+ return GetMixin .get (self , file_path , ref = ref , ** kwargs )
1361
+
1362
+ @exc .on_http_error (exc .GitlabCreateError )
1363
+ def create (self , data , ** kwargs ):
1364
+ """Create a new object.
1365
+
1366
+ Args:
1367
+ data (dict): parameters to send to the server to create the
1368
+ resource
1369
+ **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
1370
+
1371
+ Returns:
1372
+ RESTObject: a new instance of the managed object class built with
1373
+ the data sent by the server
1374
+
1375
+ Raises:
1376
+ GitlabAuthenticationError: If authentication is not correct
1377
+ GitlabCreateError: If the server cannot perform the request
1378
+ """
1379
+
1380
+ self ._check_missing_create_attrs (data )
1381
+ file_path = data .pop ('file_path' )
1382
+ path = '%s/%s' % (self .path , file_path )
1383
+ server_data = self .gitlab .http_post (path , post_data = data , ** kwargs )
1384
+ return self ._obj_cls (self , server_data )
1385
+
1386
+ @exc .on_http_error (exc .GitlabDeleteError )
1387
+ def delete (self , file_path , branch , commit_message , ** kwargs ):
1388
+ """Delete a file on the server.
1389
+
1390
+ Args:
1391
+ file_path (str): Path of the file to remove
1392
+ branch (str): Branch from which the file will be removed
1393
+ commit_message (str): Commit message for the deletion
1394
+ **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
1395
+
1396
+ Raises:
1397
+ GitlabAuthenticationError: If authentication is not correct
1398
+ GitlabDeleteError: If the server cannot perform the request
1399
+ """
1400
+ path = '%s/%s' % (self .path , file_path .replace ('/' , '%2F' ))
1401
+ data = {'branch' : branch , 'commit_message' : commit_message }
1402
+ self .gitlab .http_delete (path , query_data = data , ** kwargs )
1327
1403
1328
1404
@exc .on_http_error (exc .GitlabGetError )
1329
1405
def raw (self , file_path , ref , streamed = False , action = None , chunk_size = 1024 ,
@@ -1348,7 +1424,7 @@ def raw(self, file_path, ref, streamed=False, action=None, chunk_size=1024,
1348
1424
Returns:
1349
1425
str: The file content
1350
1426
"""
1351
- file_path = file_path .replace ('/' , '%2F' )
1427
+ file_path = file_path .replace ('/' , '%2F' ). replace ( '.' , '%2E' )
1352
1428
path = '%s/%s/raw' % (self .path , file_path )
1353
1429
query_data = {'ref' : ref }
1354
1430
result = self .gitlab .http_get (path , query_data = query_data ,
@@ -1489,8 +1565,8 @@ class ProjectVariableManager(CRUDMixin, RESTManager):
1489
1565
_path = '/projects/%(project_id)s/variables'
1490
1566
_obj_cls = ProjectVariable
1491
1567
_from_parent_attrs = {'project_id' : 'id' }
1492
- _create_attrs = (('key' , 'vaule ' ), tuple ())
1493
- _update_attrs = (('key' , 'vaule ' ), tuple ())
1568
+ _create_attrs = (('key' , 'value ' ), tuple ())
1569
+ _update_attrs = (('key' , 'value ' ), tuple ())
1494
1570
1495
1571
1496
1572
class ProjectService (GitlabObject ):
@@ -2016,7 +2092,8 @@ class ProjectManager(CRUDMixin, RESTManager):
2016
2092
'request_access_enabled' )
2017
2093
)
2018
2094
_list_filters = ('search' , 'owned' , 'starred' , 'archived' , 'visibility' ,
2019
- 'order_by' , 'sort' , 'simple' , 'membership' , 'statistics' )
2095
+ 'order_by' , 'sort' , 'simple' , 'membership' , 'statistics' ,
2096
+ 'with_issues_enabled' , 'with_merge_requests_enabled' )
2020
2097
2021
2098
2022
2099
class GroupProject (Project ):
0 commit comments