summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2020-03-22 11:52:59 -0400
committerNejc Habjan <hab.nejc@gmail.com>2020-03-22 11:52:59 -0400
commitda7a809772233be27fa8e563925dd2e44e1ce058 (patch)
treeb9956d3ad1caa4ba8d13a1279701647dbf60171a /gitlab
parent8c037712a53c1c54e46298fbb93441d9b7a7144a (diff)
downloadgitlab-da7a809772233be27fa8e563925dd2e44e1ce058.tar.gz
feat: add support for commit GPG signature API
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/tests/objects/test_commits.py27
-rw-r--r--gitlab/v4/objects.py18
2 files changed, 45 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_commits.py b/gitlab/tests/objects/test_commits.py
index 3247d60..23a4285 100644
--- a/gitlab/tests/objects/test_commits.py
+++ b/gitlab/tests/objects/test_commits.py
@@ -48,6 +48,26 @@ def resp_revert_commit(url, request):
return response(200, content, headers, None, 5, request)
+@urlmatch(
+ scheme="http",
+ netloc="localhost",
+ path="/api/v4/projects/1/repository/commits/6b2257ea/signature",
+ method="get",
+)
+def resp_get_commit_gpg_signature(url, request):
+ """Mock for commit GPG signature GET response."""
+ content = """{
+ "gpg_key_id": 1,
+ "gpg_key_primary_keyid": "8254AAB3FBD54AC9",
+ "gpg_key_user_name": "John Doe",
+ "gpg_key_user_email": "johndoe@example.com",
+ "verification_status": "verified",
+ "gpg_key_subkey_id": null
+ }"""
+ content = content.encode("utf-8")
+ return response(200, content, headers, None, 5, request)
+
+
class TestCommit(TestProject):
"""
Base class for commit tests. Inherits from TestProject,
@@ -77,3 +97,10 @@ class TestCommit(TestProject):
revert_commit = commit.revert(branch="master")
self.assertEqual(revert_commit["short_id"], "8b090c1b")
self.assertEqual(revert_commit["title"], 'Revert "Initial commit"')
+
+ @with_httmock(resp_get_commit_gpg_signature)
+ def test_get_commit_gpg_signature(self):
+ commit = self.project.commits.get("6b2257ea", lazy=True)
+ signature = commit.signature()
+ self.assertEqual(signature["gpg_key_primary_keyid"], "8254AAB3FBD54AC9")
+ self.assertEqual(signature["verification_status"], "verified")
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 9da9adf..96327b2 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -2172,6 +2172,24 @@ class ProjectCommit(RESTObject):
post_data = {"branch": branch}
return self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
+ @cli.register_custom_action("ProjectCommit")
+ @exc.on_http_error(exc.GitlabGetError)
+ def signature(self, **kwargs):
+ """Get the GPG signature of the commit.
+
+ Args:
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabGetError: If the signature could not be retrieved
+
+ Returns:
+ dict: The commit's GPG signature data
+ """
+ path = "%s/%s/signature" % (self.manager.path, self.get_id())
+ return self.manager.gitlab.http_get(path, **kwargs)
+
class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits"