-
Notifications
You must be signed in to change notification settings - Fork 671
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ | |||||||||||
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 @@ 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]: | ||||||||||||
"""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) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To force it to be a
Suggested change
|
||||||||||||
|
||||||||||||
@cli.register_custom_action("Project") | ||||||||||||
@exc.on_http_error(exc.GitlabDeleteError) | ||||||||||||
def delete_merged_branches(self, **kwargs: Any) -> None: | ||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 a
Dict
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 overloading
http_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 at https://medium.com/analytics-vidhya/making-sense-of-typing-overload-437e6deecade.