-
Notifications
You must be signed in to change notification settings - Fork 670
Feat/merge trains additional #2547 #3149
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
base: main
Are you sure you want to change the base?
Changes from all commits
761ff67
e10ba0c
cb4e015
775cd78
d444f04
60b0ec0
3ac6561
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,43 @@ | ||
from gitlab.base import RESTObject | ||
from gitlab.mixins import ListMixin | ||
from gitlab.base import RESTManager, RESTObject | ||
from gitlab.mixins import GetMixin, ListMixin, UpdateMethod, UpdateMixin | ||
from gitlab.types import RequiredOptional | ||
|
||
__all__ = ["ProjectMergeTrain", "ProjectMergeTrainManager"] | ||
__all__ = [ | ||
"ProjectMergeTrain", | ||
"ProjectMergeTrainManager", | ||
"ProjectMergeTrainMergeRequest", | ||
"ProjectMergeTrainMergeRequestManager", | ||
] | ||
|
||
|
||
class ProjectMergeTrain(RESTObject): | ||
class ProjectMergeTrainMergeRequest(RESTObject): | ||
pass | ||
|
||
|
||
class ProjectMergeTrainManager(ListMixin[ProjectMergeTrain]): | ||
class ProjectMergeTrainMergeRequestManager( | ||
GetMixin[ProjectMergeTrainMergeRequest], | ||
UpdateMixin[ProjectMergeTrainMergeRequest], | ||
RESTManager[ProjectMergeTrainMergeRequest], | ||
): | ||
_path = "/projects/{project_id}/merge_trains/merge_requests" | ||
_obj_cls = ProjectMergeTrainMergeRequest | ||
_from_parent_attrs = {"project_id": "project_id"} | ||
_update_method: UpdateMethod = UpdateMethod.POST | ||
|
||
_update_attrs = RequiredOptional( | ||
optional=("sha", "squash", "when_pipeline_succeeds") | ||
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. Should https://docs.gitlab.com/api/merge_trains/#add-a-merge-request-to-a-merge-train |
||
) | ||
|
||
|
||
class ProjectMergeTrain(RESTObject): | ||
merge_requests: ProjectMergeTrainMergeRequestManager | ||
|
||
|
||
class ProjectMergeTrainManager( | ||
GetMixin[ProjectMergeTrain], | ||
ListMixin[ProjectMergeTrain], | ||
RESTManager[ProjectMergeTrain], | ||
): | ||
_path = "/projects/{project_id}/merge_trains" | ||
_obj_cls = ProjectMergeTrain | ||
_from_parent_attrs = {"project_id": "id"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
import pytest | ||
import responses | ||
|
||
from gitlab.v4.objects import ProjectMergeTrain | ||
from gitlab.v4.objects import ProjectMergeTrain, ProjectMergeTrainMergeRequest | ||
|
||
mr_content = { | ||
"id": 110, | ||
"merge_request": { | ||
"id": 1, | ||
"id": 273, | ||
"iid": 1, | ||
"project_id": 3, | ||
"title": "Test merge train", | ||
|
@@ -46,6 +46,10 @@ | |
"duration": 70, | ||
} | ||
|
||
merge_train_update = mr_content.copy() | ||
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. Using dict.copy() here performs a shallow copy, so nested structures (like the 'pipeline' dict) remain shared with mr_content and may be mutated unexpectedly. Consider using copy.deepcopy() to isolate test data changes. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. Probably a good idea. Since line 51 would modify the underlying dict. |
||
merge_train_update["iid"] = 4 | ||
merge_train_update["pipeline"]["sha"] = "ef33a3zxc3" | ||
|
||
|
||
@pytest.fixture | ||
def resp_list_merge_trains(): | ||
|
@@ -60,7 +64,61 @@ def resp_list_merge_trains(): | |
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_merge_trains_merge_request_get(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/projects/1/merge_trains/merge_requests/1", | ||
json=mr_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_merge_trains_merge_request_post(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/projects/1/merge_trains/merge_requests/4", | ||
json=[merge_train_update], | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_list_project_merge_requests(project, resp_list_merge_trains): | ||
merge_trains = project.merge_trains.list() | ||
assert isinstance(merge_trains[0], ProjectMergeTrain) | ||
assert merge_trains[0].id == mr_content["id"] | ||
|
||
|
||
def test_merge_trains_status_merge_request( | ||
project, resp_merge_trains_merge_request_get | ||
): | ||
merge_train_mr: ProjectMergeTrainMergeRequest = project.merge_trains.get( | ||
1, lazy=True | ||
).merge_requests.get(1) | ||
assert isinstance(merge_train_mr, ProjectMergeTrainMergeRequest) | ||
assert merge_train_mr.get_id() == 110 | ||
assert merge_train_mr.merge_request["iid"] == mr_content["merge_request"]["iid"] | ||
assert merge_train_mr.pipeline.get("status") == mr_content["pipeline"]["status"] | ||
|
||
|
||
def test_merge_train_add_merge_request(project, resp_merge_trains_merge_request_post): | ||
merge_train: ProjectMergeTrain = project.merge_trains.get(1, lazy=True) | ||
merge_requests_update = merge_train.merge_requests.update( | ||
4, new_data={"sha": "ef33a3zxc3"} | ||
) | ||
assert isinstance(merge_train, ProjectMergeTrain) | ||
assert ( | ||
merge_requests_update[0]["pipeline"]["sha"] | ||
== merge_train_update["pipeline"]["sha"] | ||
) | ||
assert ( | ||
merge_requests_update[0]["merge_request"]["iid"] | ||
== merge_train_update["merge_request"]["iid"] | ||
) |
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.
Typo in the module path: 'gilab' should be spelled 'gitlab'.
Copilot uses AI. Check for mistakes.