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

fix(epics): use actual group_id for save/delete operations on nested epics#3279

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

Draft
JohnVillalovos wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromjlvillal/3261_epic_group
Draft
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

Some comments aren't visible on the classic Files Changed page.

2 changes: 2 additions & 0 deletionsgitlab/mixins.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -314,6 +314,8 @@ def update(
path=self.path
else:
path=f"{self.path}/{utils.EncodedId(id)}"
if"_pg_custom_path"inkwargs:
path=kwargs.pop("_pg_custom_path")

excludes= []
ifself._obj_clsisnotNoneandself._obj_cls._id_attrisnotNone:
Expand Down
58 changes: 58 additions & 0 deletionsgitlab/v4/objects/epics.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@

fromtypingimportAny,TYPE_CHECKING

importgitlab.utils
fromgitlabimportexceptionsasexc
fromgitlabimporttypes
fromgitlab.baseimportRESTObject
Expand DownExpand Up@@ -29,6 +30,63 @@ class GroupEpic(ObjectDeleteMixin, SaveMixin, RESTObject):
resourcelabelevents:GroupEpicResourceLabelEventManager
notes:GroupEpicNoteManager

def_epic_path(self)->str:
"""Return the API path for this epic using its real group."""
ifnothasattr(self,"group_id")orself.group_idisNone:
raiseAttributeError(
"Cannot compute epic path: attribute 'group_id' is missing."
)
encoded_group_id=gitlab.utils.EncodedId(self.group_id)
returnf"/groups/{encoded_group_id}/epics/{self.encoded_id}"

@exc.on_http_error(exc.GitlabUpdateError)
defsave(self,**kwargs:Any)->dict[str,Any]|None:
"""Save the changes made to the object to the server.
The object is updated to match what the server returns.
This method uses the epic's group_id attribute to construct the correct
API path. This is important when the epic was retrieved from a parent
group but actually belongs to a sub-group.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Returns:
The new object data (*not* a RESTObject)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request
"""
# Use the epic's actual group_id to construct the correct path.
path=self._epic_path()

# Call SaveMixin.save() method
returnsuper().save(_pg_custom_path=path,**kwargs)

@exc.on_http_error(exc.GitlabDeleteError)
defdelete(self,**kwargs:Any)->None:
"""Delete the object from the server.
This method uses the epic's group_id attribute to construct the correct
API path. This is important when the epic was retrieved from a parent
group but actually belongs to a sub-group.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabDeleteError: If the server cannot perform the request
"""
ifTYPE_CHECKING:
assertself.encoded_idisnotNone

# Use the epic's actual group_id to construct the correct path.
path=self._epic_path()
self.manager.gitlab.http_delete(path,**kwargs)


classGroupEpicManager(CRUDMixin[GroupEpic]):
_path="/groups/{group_id}/epics"
Expand Down
44 changes: 44 additions & 0 deletionstests/functional/api/test_epics.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
import uuid

import pytest

import gitlab.exceptions
from tests.functional import helpers

pytestmark = pytest.mark.gitlab_premium


Expand DownExpand Up@@ -30,3 +35,42 @@ def test_epic_notes(epic):

epic.notes.create({"body": "Test note"})
assert epic.notes.list()


def test_epic_save_from_parent_group_updates_subgroup_epic(gl, group):
subgroup_id = uuid.uuid4().hex
subgroup = gl.groups.create(
{
"name": f"subgroup-{subgroup_id}",
"path": f"sg-{subgroup_id}",
"parent_id": group.id,
}
)

nested_epic = subgroup.epics.create(
{"title": f"Nested epic {subgroup_id}", "description": "Nested epic"}
)

try:
fetched_epics = group.epics.list(search=nested_epic.title)
assert fetched_epics, "Expected to discover nested epic via parent group list"
subgroup.epics.get(nested_epic.iid)

fetched_epic = next(
(epic for epic in fetched_epics if epic.id == nested_epic.id), None
)
assert (
fetched_epic is not None
), "Parent group listing did not include nested epic"

new_label = f"nested-{subgroup_id}"
fetched_epic.labels = [new_label]
fetched_epic.save()

refreshed_epic = subgroup.epics.get(nested_epic.iid)
assert new_label in refreshed_epic.labels
finally:
helpers.safe_delete(nested_epic)
with pytest.raises(gitlab.exceptions.GitlabGetError):
subgroup.epics.get(nested_epic.iid)
helpers.safe_delete(subgroup)
52 changes: 52 additions & 0 deletionstests/unit/objects/test_epics.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
import pytest
import responses

from gitlab.v4.objects.epics import GroupEpic


def _build_epic(manager, iid=3, group_id=2, title="Epic"):
data = {"iid": iid, "group_id": group_id, "title": title}
return GroupEpic(manager, data)


def test_group_epic_save_uses_actual_group_path(group):
epic_manager = group.epics
epic = _build_epic(epic_manager, title="Original")
epic.title = "Updated"

with responses.RequestsMock() as rsps:
rsps.add(
method=responses.PUT,
url="http://localhost/api/v4/groups/2/epics/3",
json={"iid": 3, "group_id": 2, "title": "Updated"},
content_type="application/json",
status=200,
match=[responses.matchers.json_params_matcher({"title": "Updated"})],
)

epic.save()

assert epic.title == "Updated"


def test_group_epic_delete_uses_actual_group_path(group):
epic_manager = group.epics
epic = _build_epic(epic_manager)

with responses.RequestsMock() as rsps:
rsps.add(
method=responses.DELETE,
url="http://localhost/api/v4/groups/2/epics/3",
status=204,
)

epic.delete()

assert len(epic._updated_attrs) == 0


def test_group_epic_path_requires_group_id(fake_manager):
epic = GroupEpic(manager=fake_manager, attrs={"iid": 5})

with pytest.raises(AttributeError):
epic._epic_path()

[8]ページ先頭

©2009-2025 Movatter.jp