From fe5805f3b60fc97c107e1c9b0a4ff299459ca800 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 21 Oct 2017 09:21:11 +0200 Subject: ProjectFileManager: custom update() method Closes #340 --- gitlab/v4/objects.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gitlab') diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 0fe2ea5..80c4286 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1420,6 +1420,30 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, server_data = self.gitlab.http_post(path, post_data=data, **kwargs) return self._obj_cls(self, server_data) + @exc.on_http_error(exc.GitlabUpdateError) + def update(self, file_path, new_data={}, **kwargs): + """Update an object on the server. + + Args: + id: ID of the object to update (can be None if not required) + new_data: the update data for the object + **kwargs: Extra options to send to the Gitlab server (e.g. sudo) + + Returns: + dict: The new object data (*not* a RESTObject) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUpdateError: If the server cannot perform the request + """ + + data = new_data.copy() + file_path = file_path.replace('/', '%2F') + data['file_path'] = file_path + path = '%s/%s' % (self.path, file_path) + self._check_missing_update_attrs(data) + return self.gitlab.http_put(path, post_data=data, **kwargs) + @cli.register_custom_action('ProjectFileManager', ('file_path', 'branch', 'commit_message')) @exc.on_http_error(exc.GitlabDeleteError) -- cgit v1.2.1