Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add support for merge_base API#2236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JohnVillalovos merged 1 commit intomainfromfeat/merge-base
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionsdocs/cli-examples.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -302,6 +302,12 @@ Define the status of a commit (as would be done from a CI tool for example):
--target-url http://server/build/123 \
--description "Jenkins build succeeded"

Get the merge base for two or more branches, tags or commits:

.. code-block:: console

gitlab project repository-merge-base --id 1 --refs bd1324e2f,main,v1.0.0

Artifacts
---------

Expand Down
4 changes: 4 additions & 0 deletionsdocs/gl_objects/projects.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -231,6 +231,10 @@ Compare two branches, tags or commits::
for file_diff in result['diffs']:
print(file_diff)

Get the merge base for two or more branches, tags or commits::

commit = project.repository_merge_base(['main', 'v1.2.3', 'bd1324e2f'])

Get a list of contributors for the repository::

contributors = project.repository_contributors()
Expand Down
28 changes: 27 additions & 1 deletiongitlab/v4/objects/repositories.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@
import gitlab
from gitlab import cli
from gitlab import exceptions as exc
from gitlab import utils
from gitlab importtypes,utils

if TYPE_CHECKING:
# When running mypy we use these as the base classes
Expand DownExpand Up@@ -246,6 +246,32 @@ def repository_archive(
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]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This made me think if we should start forcing these to just be aDict?

Copy link
MemberAuthor

@nejchnejchAug 16, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks@JohnVillalovos! Makes sense to me! I was looking at doing this via overloadinghttp_get/http_request to narrow the types there already, depending on the streamed/raw arguments but it got a bit out of hand. Then I think we wouldn't need to do it in "downstream" methods, IIUC. I will look into it again :)

But it requires quite a few overloads for all the possible signatures. This is what I was looking athttps://medium.com/analytics-vidhya/making-sense-of-typing-overload-437e6deecade.

"""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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To force it to be aDict I think could do this:

Suggested change
returnself.manager.gitlab.http_get(path,query_data=query_data,**kwargs)
result=self.manager.gitlab.http_get(path,query_data=query_data,raw=False,streamed=False,**kwargs)
ifTYPE_CHECKING:
assertisinstance(result,dict)
returnresult


@cli.register_custom_action("Project")
@exc.on_http_error(exc.GitlabDeleteError)
def delete_merged_branches(self, **kwargs: Any) -> None:
Expand Down
10 changes: 10 additions & 0 deletionstests/functional/api/test_repository.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,3 +174,13 @@ def test_revert_commit(project):
with pytest.raises(gitlab.GitlabRevertError):
# Two revert attempts should raise GitlabRevertError
commit.revert(branch="main")


def test_repository_merge_base(project):
refs = [commit.id for commit in project.commits.list(all=True)]

commit = project.repository_merge_base(refs)
assert commit["id"] in refs

with pytest.raises(gitlab.GitlabGetError, match="Provide at least 2 refs"):
commit = project.repository_merge_base(refs[0])

[8]ページ先頭

©2009-2025 Movatter.jp