Skip to content

Commit c0563d4

Browse files
lgatellierJohnVillalovos
authored andcommitted
feat(api): Add support for new runner creation API
1 parent d054917 commit c0563d4

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

gitlab/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def __init__(
189189
"""See :class:`~gitlab.v4.objects.PagesDomainManager`"""
190190
self.user_activities = objects.UserActivitiesManager(self)
191191
"""See :class:`~gitlab.v4.objects.UserActivitiesManager`"""
192+
self.user_runners = objects.UserRunnerManager(self)
193+
"""See :class:`~gitlab.v4.objects.UserRunnerManager`"""
192194
self.applications = objects.ApplicationManager(self)
193195
"""See :class:`~gitlab.v4.objects.ApplicationManager`"""
194196
self.variables = objects.VariableManager(self)

gitlab/v4/objects/users.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"UserMembershipManager",
6464
"UserProject",
6565
"UserProjectManager",
66+
"UserRunner",
67+
"UserRunnerManager",
6668
]
6769

6870

@@ -678,3 +680,28 @@ class UserFollowingManager(ListMixin, RESTManager):
678680
_path = "/users/{user_id}/following"
679681
_obj_cls = User
680682
_from_parent_attrs = {"user_id": "id"}
683+
684+
685+
class UserRunner(RESTObject):
686+
pass
687+
688+
689+
class UserRunnerManager(CreateMixin, RESTManager):
690+
_path = "/user/runners"
691+
_obj_cls = UserRunner
692+
_types = {"tag_list": types.CommaSeparatedListAttribute}
693+
_create_attrs = RequiredOptional(
694+
required=("runner_type",),
695+
optional=(
696+
"group_id",
697+
"project_id",
698+
"description",
699+
"paused",
700+
"locked",
701+
"run_untagged",
702+
"tag_list",
703+
"access_level",
704+
"maximum_timeout",
705+
"maintenance_note",
706+
),
707+
)

tests/unit/objects/test_users.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import responses
88

9+
import gitlab
910
from gitlab.v4.objects import StarredProject, User, UserMembership, UserStatus
1011

1112
from .test_projects import project_content
@@ -241,6 +242,19 @@ def resp_starred_projects():
241242
yield rsps
242243

243244

245+
@pytest.fixture
246+
def resp_runner_create():
247+
with responses.RequestsMock() as rsps:
248+
rsps.add(
249+
method=responses.POST,
250+
url="http://localhost/api/v4/user/runners",
251+
json={"id": "6", "token": "6337ff461c94fd3fa32ba3b1ff4125"},
252+
content_type="application/json",
253+
status=200,
254+
)
255+
yield rsps
256+
257+
244258
def test_get_user(gl, resp_get_user):
245259
user = gl.users.get(1)
246260
assert isinstance(user, User)
@@ -304,3 +318,9 @@ def test_list_starred_projects(user, resp_starred_projects):
304318
projects = user.starred_projects.list()
305319
assert isinstance(projects[0], StarredProject)
306320
assert projects[0].id == project_content["id"]
321+
322+
323+
def test_create_user_runner(gl: gitlab.Gitlab, resp_runner_create):
324+
runner = gl.user_runners.create({"runner_type": "instance_type"})
325+
assert runner.id == "6"
326+
assert runner.token == "6337ff461c94fd3fa32ba3b1ff4125"

0 commit comments

Comments
 (0)