Skip to content

Commit 194ee01

Browse files
nejchJohnVillalovos
authored andcommitted
feat: add support for iterations API
1 parent 66461ba commit 194ee01

File tree

7 files changed

+112
-0
lines changed

7 files changed

+112
-0
lines changed

docs/api-objects.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ API examples
2828
gl_objects/group_access_tokens
2929
gl_objects/invitations
3030
gl_objects/issues
31+
gl_objects/iterations
3132
gl_objects/keys
3233
gl_objects/boards
3334
gl_objects/labels

docs/gl_objects/iterations.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
##########
2+
Iterations
3+
##########
4+
5+
6+
Reference
7+
---------
8+
9+
* v4 API:
10+
11+
+ :class:`gitlab.v4.objects.GroupIteration`
12+
+ :class:`gitlab.v4.objects.GroupIterationManager`
13+
+ :attr:`gitlab.v4.objects.Group.iterations`
14+
+ :class:`gitlab.v4.objects.ProjectIterationManager`
15+
+ :attr:`gitlab.v4.objects.Project.iterations`
16+
17+
* GitLab API: https://docs.gitlab.com/ee/api/iterations.html
18+
19+
Examples
20+
--------
21+
22+
.. note::
23+
24+
GitLab no longer has project iterations. Using a project endpoint returns
25+
the ancestor groups' iterations.
26+
27+
List iterations for a project's ancestor groups::
28+
29+
iterations = project.iterations.list()
30+
31+
List iterations for a group::
32+
33+
iterations = group.iterations.list()

gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from .integrations import *
4848
from .invitations import *
4949
from .issues import *
50+
from .iterations import *
5051
from .jobs import *
5152
from .keys import *
5253
from .labels import *

gitlab/v4/objects/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .hooks import GroupHookManager # noqa: F401
2525
from .invitations import GroupInvitationManager # noqa: F401
2626
from .issues import GroupIssueManager # noqa: F401
27+
from .iterations import GroupIterationManager # noqa: F401
2728
from .labels import GroupLabelManager # noqa: F401
2829
from .members import ( # noqa: F401
2930
GroupBillableMemberManager,
@@ -71,6 +72,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
7172
invitations: GroupInvitationManager
7273
issues: GroupIssueManager
7374
issues_statistics: GroupIssuesStatisticsManager
75+
iterations: GroupIterationManager
7476
labels: GroupLabelManager
7577
members: GroupMemberManager
7678
members_all: GroupMemberAllManager

gitlab/v4/objects/iterations.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from gitlab.base import RESTManager, RESTObject
2+
from gitlab.mixins import ListMixin
3+
4+
__all__ = [
5+
"ProjectIterationManager",
6+
"GroupIteration",
7+
"GroupIterationManager",
8+
]
9+
10+
11+
class GroupIteration(RESTObject):
12+
_repr_attr = "title"
13+
14+
15+
class GroupIterationManager(ListMixin, RESTManager):
16+
_path = "/groups/{group_id}/iterations"
17+
_obj_cls = GroupIteration
18+
_from_parent_attrs = {"group_id": "id"}
19+
_list_filters = ("state", "search", "include_ancestors")
20+
21+
22+
class ProjectIterationManager(ListMixin, RESTManager):
23+
_path = "/projects/{project_id}/iterations"
24+
_obj_cls = GroupIteration
25+
_from_parent_attrs = {"project_id": "id"}
26+
_list_filters = ("state", "search", "include_ancestors")

gitlab/v4/objects/projects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from .integrations import ProjectIntegrationManager, ProjectServiceManager # noqa: F401
5858
from .invitations import ProjectInvitationManager # noqa: F401
5959
from .issues import ProjectIssueManager # noqa: F401
60+
from .iterations import GroupIterationManager # noqa: F401
6061
from .jobs import ProjectJobManager # noqa: F401
6162
from .labels import ProjectLabelManager # noqa: F401
6263
from .members import ProjectMemberAllManager, ProjectMemberManager # noqa: F401
@@ -185,6 +186,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
185186
invitations: ProjectInvitationManager
186187
issues: ProjectIssueManager
187188
issues_statistics: ProjectIssuesStatisticsManager
189+
iterations: GroupIterationManager
188190
jobs: ProjectJobManager
189191
keys: ProjectKeyManager
190192
labels: ProjectLabelManager

tests/unit/objects/test_iterations.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/iterations.html
3+
"""
4+
5+
import re
6+
7+
import pytest
8+
import responses
9+
10+
iterations_content = [
11+
{
12+
"id": 53,
13+
"iid": 13,
14+
"group_id": 5,
15+
"title": "Iteration II",
16+
"description": "Ipsum Lorem ipsum",
17+
"state": 2,
18+
"created_at": "2020-01-27T05:07:12.573Z",
19+
"updated_at": "2020-01-27T05:07:12.573Z",
20+
"due_date": "2020-02-01",
21+
"start_date": "2020-02-14",
22+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13",
23+
}
24+
]
25+
26+
27+
@pytest.fixture
28+
def resp_iterations_list():
29+
with responses.RequestsMock() as rsps:
30+
rsps.add(
31+
method=responses.GET,
32+
url=re.compile(r"http://localhost/api/v4/(groups|projects)/1/iterations"),
33+
json=iterations_content,
34+
content_type="application/json",
35+
status=200,
36+
)
37+
yield rsps
38+
39+
40+
def test_list_group_iterations(group, resp_iterations_list):
41+
iterations = group.iterations.list()
42+
assert iterations[0].group_id == 5
43+
44+
45+
def test_list_project_iterations(project, resp_iterations_list):
46+
iterations = project.iterations.list()
47+
assert iterations[0].group_id == 5

0 commit comments

Comments
 (0)