Skip to content
Closed
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
7 changes: 7 additions & 0 deletions gitlab/v4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def do_custom(self) -> Any:
method_name = self.resource_action.replace("-", "_")
return getattr(class_instance, method_name)(**self.args)

def do_project_commit_status_create(self) -> gitlab.base.RESTObject:
# Status creation has a different URL from the interpolated list path.
project = self.gl.projects.get(self.parent_args["project_id"], lazy=True)
commit = project.commits.get(self.parent_args["commit_id"], lazy=True)
self.mgr = commit.statuses
return self.do_create()

def do_project_export_download(self) -> None:
try:
project = self.gl.projects.get(self.parent_args["project_id"], lazy=True)
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest import mock

import pytest
import responses

import gitlab.base
from gitlab import cli
Expand Down Expand Up @@ -231,3 +232,32 @@ def test_legacy_display_with_long_repr_truncates(fake_object_long_repr):
printer.display(fake_object_long_repr, obj=fake_object_long_repr)

assert len(mocked.call_args.args[0]) < 80


@pytest.mark.parametrize(
"project_id,encoded_project_id",
[("42", "42"), ("group/sub project", "group%2Fsub%20project")],
)
def test_cli_create_commit_status(gl, monkeypatch, project_id, encoded_project_id):
manager = gitlab.v4.objects.ProjectCommitStatusManager
# CLI initialization interpolates the class path; restore it after this test.
monkeypatch.setattr(manager, "_path", manager._path)
data = {"state": "pending", "context": "sample"}
url = f"http://localhost/api/v4/projects/{encoded_project_id}/statuses/abcdef"
with responses.RequestsMock() as rsps:
rsps.post(
url,
json={"id": 1, "status": "pending", "name": "sample"},
status=201,
match=[responses.matchers.json_params_matcher(data)],
)
command = v4_cli.GitlabCLI(
gl,
"project-commit-status",
"create",
{"project_id": project_id, "commit_id": "abcdef", **data},
)
result = command.run()

assert result.status == "pending"
assert result.name == "sample"
Loading