summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-08-14 18:59:54 +0200
committerJohn Villalovos <john@sodarock.com>2022-08-19 16:24:31 -0700
commitdd4fbd5e43adbbc502624a8de0d30925d798dec0 (patch)
tree2014cb8ae4b3bbf41abcd2fb36711a5e12b61187 /gitlab
parent13d49279d28c55239f8c3e22b056d76df0f1ef7f (diff)
downloadgitlab-dd4fbd5e43adbbc502624a8de0d30925d798dec0.tar.gz
feat: add support for merge_base API
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/v4/objects/repositories.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py
index b340e80..9c0cd9a 100644
--- a/gitlab/v4/objects/repositories.py
+++ b/gitlab/v4/objects/repositories.py
@@ -10,7 +10,7 @@ import requests
import gitlab
from gitlab import cli
from gitlab import exceptions as exc
-from gitlab import utils
+from gitlab import types, utils
if TYPE_CHECKING:
# When running mypy we use these as the base classes
@@ -246,6 +246,32 @@ class RepositoryMixin(_RestObjectBase):
result, streamed, action, chunk_size, iterator=iterator
)
+ @cli.register_custom_action("Project", ("refs",))
+ @exc.on_http_error(exc.GitlabGetError)
+ def repository_merge_base(
+ self, refs: List[str], **kwargs: Any
+ ) -> Union[Dict[str, Any], requests.Response]:
+ """Return a diff between two branches/commits.
+
+ Args:
+ refs: The refs to find the common ancestor of. Multiple refs can be passed.
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabGetError: If the server failed to perform the request
+
+ Returns:
+ The common ancestor commit (*not* a RESTObject)
+ """
+ path = f"/projects/{self.encoded_id}/repository/merge_base"
+ query_data, _ = utils._transform_types(
+ data={"refs": refs},
+ custom_types={"refs": types.ArrayAttribute},
+ transform_data=True,
+ )
+ return self.manager.gitlab.http_get(path, query_data=query_data, **kwargs)
+
@cli.register_custom_action("Project")
@exc.on_http_error(exc.GitlabDeleteError)
def delete_merged_branches(self, **kwargs: Any) -> None: