Skip to content

feat(api): add project milestone promotion #1655

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 1 commit into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/gl_objects/milestones.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Change the state of a milestone (activate / close)::
milestone.state_event = 'activate'
milestone.save()

Promote a project milestone::

milestone.promote()

List the issues related to a milestone::

issues = milestone.issues()
Expand Down
5 changes: 3 additions & 2 deletions gitlab/v4/objects/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from gitlab import exceptions as exc
from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, PromoteMixin, SaveMixin

from .issues import GroupIssue, GroupIssueManager, ProjectIssue, ProjectIssueManager
from .merge_requests import (
Expand Down Expand Up @@ -90,8 +90,9 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
_types = {"iids": types.ListAttribute}


class ProjectMilestone(SaveMixin, ObjectDeleteMixin, RESTObject):
class ProjectMilestone(PromoteMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = "title"
_update_uses_post = True

@cli.register_custom_action("ProjectMilestone")
@exc.on_http_error(exc.GitlabListError)
Expand Down
21 changes: 21 additions & 0 deletions tests/functional/api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ def test_project_milestones(project):
assert len(milestone.merge_requests()) == 0


def test_project_milestone_promotion(gl, group):
"""
Milestone promotion requires the project to be a child of a group (not in a user namespace)
"""
_id = uuid.uuid4().hex
data = {
"name": f"test-project-{_id}",
"namespace_id": group.id,
}
project = gl.projects.create(data)

milestone_title = "promoteme"
promoted_milestone = project.milestones.create({"title": milestone_title})
promoted_milestone.promote()

assert any(
milestone.title == milestone_title for milestone in group.milestones.list()
)


def test_project_pages_domains(gl, project):
domain = project.pagesdomains.create({"domain": "foo.domain.com"})
assert len(project.pagesdomains.list()) == 1
Expand Down