@@ -126,7 +126,7 @@ class UserKey(ObjectDeleteMixin, RESTObject):
126126
127127
128128class UserKeyManager (GetFromListMixin , CreateMixin , DeleteMixin , RESTManager ):
129- _path = '/users/%(user_id)s/emails '
129+ _path = '/users/%(user_id)s/keys '
130130 _obj_cls = UserKey
131131 _from_parent_attrs = {'user_id' : 'id' }
132132 _create_attrs = (('title' , 'key' ), tuple ())
@@ -842,8 +842,8 @@ def enable(self, key_id, **kwargs):
842842 GitlabAuthenticationError: If authentication is not correct
843843 GitlabProjectDeployKeyError: If the key could not be enabled
844844 """
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 )
847847
848848
849849class ProjectEvent (RESTObject ):
@@ -999,17 +999,19 @@ def set_release_description(self, description, **kwargs):
999999 data = {'description' : description }
10001000 if self .release is None :
10011001 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 )
10041005 except exc .GitlabHttpError as e :
10051006 raise exc .GitlabCreateError (e .response_code , e .error_message )
10061007 else :
10071008 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 )
10101012 except exc .GitlabHttpError as e :
10111013 raise exc .GitlabUpdateError (e .response_code , e .error_message )
1012- self .release = result . json ()
1014+ self .release = server_data
10131015
10141016
10151017class ProjectTagManager (GetFromListMixin , CreateMixin , DeleteMixin ,
@@ -1223,8 +1225,7 @@ def merge_requests(self, **kwargs):
12231225 return RESTObjectList (manager , ProjectMergeRequest , data_list )
12241226
12251227
1226- class ProjectMilestoneManager (RetrieveMixin , CreateMixin , DeleteMixin ,
1227- RESTManager ):
1228+ class ProjectMilestoneManager (CRUDMixin , RESTManager ):
12281229 _path = '/projects/%(project_id)s/milestones'
12291230 _obj_cls = ProjectMilestone
12301231 _from_parent_attrs = {'project_id' : 'id' }
@@ -1239,6 +1240,26 @@ class ProjectLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin,
12391240 RESTObject ):
12401241 _id_attr = 'name'
12411242
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+
12421263
12431264class ProjectLabelManager (GetFromListMixin , CreateMixin , UpdateMixin ,
12441265 DeleteMixin , RESTManager ):
@@ -1262,27 +1283,7 @@ def delete(self, name, **kwargs):
12621283 GitlabAuthenticationError: If authentication is not correct.
12631284 GitlabDeleteError: If the server cannot perform the request.
12641285 """
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 )
12861287
12871288
12881289class ProjectFile (SaveMixin , ObjectDeleteMixin , RESTObject ):
@@ -1297,6 +1298,38 @@ def decode(self):
12971298 """
12981299 return base64 .b64decode (self .content )
12991300
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+
13001333
13011334class ProjectFileManager (GetMixin , CreateMixin , UpdateMixin , DeleteMixin ,
13021335 RESTManager ):
@@ -1308,11 +1341,12 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin,
13081341 _update_attrs = (('file_path' , 'branch' , 'content' , 'commit_message' ),
13091342 ('encoding' , 'author_email' , 'author_name' ))
13101343
1311- def get (self , file_path , ** kwargs ):
1344+ def get (self , file_path , ref , ** kwargs ):
13121345 """Retrieve a single file.
13131346
13141347 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
13161350 **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
13171351
13181352 Raises:
@@ -1323,7 +1357,49 @@ def get(self, file_path, **kwargs):
13231357 object: The generated RESTObject
13241358 """
13251359 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 )
13271403
13281404 @exc .on_http_error (exc .GitlabGetError )
13291405 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,
13481424 Returns:
13491425 str: The file content
13501426 """
1351- file_path = file_path .replace ('/' , '%2F' )
1427+ file_path = file_path .replace ('/' , '%2F' ). replace ( '.' , '%2E' )
13521428 path = '%s/%s/raw' % (self .path , file_path )
13531429 query_data = {'ref' : ref }
13541430 result = self .gitlab .http_get (path , query_data = query_data ,
@@ -1489,8 +1565,8 @@ class ProjectVariableManager(CRUDMixin, RESTManager):
14891565 _path = '/projects/%(project_id)s/variables'
14901566 _obj_cls = ProjectVariable
14911567 _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 ())
14941570
14951571
14961572class ProjectService (GitlabObject ):
@@ -2016,7 +2092,8 @@ class ProjectManager(CRUDMixin, RESTManager):
20162092 'request_access_enabled' )
20172093 )
20182094 _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' )
20202097
20212098
20222099class GroupProject (Project ):
0 commit comments