From 2cadff320f1ddc74f464379430a50ac860ff71fd Mon Sep 17 00:00:00 2001 From: Sebastian Kratzert Date: Wed, 4 Sep 2019 13:07:35 +0200 Subject: [PATCH 1/3] feat: impement update_submodule --- gitlab/v4/objects.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index dd73be25b..f664ea39c 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3864,6 +3864,34 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ("wikis", "ProjectWikiManager"), ) + @cli.register_custom_action("Project", ("submodule", "branch", "commit_sha")) + @exc.on_http_error(exc.GitlabUpdateError) + def update_submodule(self, submodule, branch, commit_sha, **kwargs): + """Transfer a project to the given namespace ID + + Args: + submodule (str): Full path to the submodule + branch (str): Name of the branch to commit into + commit_sha (str): Full commit SHA to update the submodule to + commit_message (str): Commit message. If no message is provided, a default one will be set (optional) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabPutError: If the submodule could not be updated + """ + + submodule = submodule.replace('/', '%2F') # .replace('.', '%2E') + path = "/projects/%s/repository/submodules/%s" % (self.get_id(), submodule) + data = { + "branch": branch, + "commit_sha": commit_sha, + } + if 'commit_message' in kwargs: + data['commit_message'] = kwargs['commit_message'] + return self.manager.gitlab.http_put( + path, post_data=data + ) + @cli.register_custom_action("Project", tuple(), ("path", "ref", "recursive")) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path="", ref="", recursive=False, **kwargs): From 716d8c1569a4ab800c27848c08f70045ee2df650 Mon Sep 17 00:00:00 2001 From: Sebastian Kratzert Date: Fri, 6 Sep 2019 08:53:50 +0200 Subject: [PATCH 2/3] style: Formatted with black --- gitlab/v4/objects.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index f664ea39c..bbcb48e8f 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3880,17 +3880,12 @@ def update_submodule(self, submodule, branch, commit_sha, **kwargs): GitlabPutError: If the submodule could not be updated """ - submodule = submodule.replace('/', '%2F') # .replace('.', '%2E') + submodule = submodule.replace("/", "%2F") # .replace('.', '%2E') path = "/projects/%s/repository/submodules/%s" % (self.get_id(), submodule) - data = { - "branch": branch, - "commit_sha": commit_sha, - } - if 'commit_message' in kwargs: - data['commit_message'] = kwargs['commit_message'] - return self.manager.gitlab.http_put( - path, post_data=data - ) + data = {"branch": branch, "commit_sha": commit_sha} + if "commit_message" in kwargs: + data["commit_message"] = kwargs["commit_message"] + return self.manager.gitlab.http_put(path, post_data=data) @cli.register_custom_action("Project", tuple(), ("path", "ref", "recursive")) @exc.on_http_error(exc.GitlabGetError) From 185f064dbf30795e66caf613548a47ccaec66641 Mon Sep 17 00:00:00 2001 From: Sebastian Kratzert Date: Fri, 6 Sep 2019 08:55:31 +0200 Subject: [PATCH 3/3] test: Implemented test for Project.update_submodule I did not manage to run the tests on windows, so i am not sure if the tests is running fine --- gitlab/tests/test_gitlab.py | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index ee1daa323..da78e3bfd 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -637,6 +637,56 @@ def resp_get_user(url, request): self.assertEqual(user.name, "name") self.assertEqual(user.id, 1) + def test_update_submodule(self): + @urlmatch( + scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" + ) + def resp_get_project(url, request): + headers = {"content-type": "application/json"} + content = '{"name": "name", "id": 1}'.encode("utf-8") + return response(200, content, headers, None, 5, request) + + @urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/$1/repository/submodules/foo%2Fbar", + method="post", + ) + def resp_update_submodule(url, request): + headers = {"content-type": "application/json"} + content = """{ + "id": "ed899a2f4b50b4370feeea94676502b42383c746", + "short_id": "ed899a2f4b5", + "title": "Message", + "author_name": "Author", + "author_email": "author@example.com", + "committer_name": "Author", + "committer_email": "author@example.com", + "created_at": "2018-09-20T09:26:24.000-07:00", + "message": "Message", + "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], + "committed_date": "2018-09-20T09:26:24.000-07:00", + "authored_date": "2018-09-20T09:26:24.000-07:00", + "status": null}""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + with HTTMock(resp_update_submodule): + project = self.gl.projects.get(1) + self.assertIsInstance(project, Project) + self.assertEqual(project.name, "name") + self.assertEqual(project.id, 1) + + ret = project.update_submodule( + submodule="foo/bar", + branch="master", + commit_sha="4c3674f66071e30b3311dac9b9ccc90502a72664", + commit_message="Message", + ) + self.assertIsInstance(ret, dict) + self.assertEqual(ret["message"], "Message") + self.assertEqual(ret["id"], "ed899a2f4b50b4370feeea94676502b42383c746") + def _default_config(self): fd, temp_path = tempfile.mkstemp() os.write(fd, valid_config) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy