FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(cli): handle list response for json/yaml output by JohnVillalovos · Pull Request #2290 · python-gitlab/python-gitlab · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 4 additions & 4 deletions gitlab/v4/cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:


def get_dict(
obj: Union[str, gitlab.base.RESTObject], fields: List[str]
obj: Union[str, Dict[str, Any], gitlab.base.RESTObject], fields: List[str]
) -> Union[str, Dict[str, Any]]:
if isinstance(obj, str):
if not isinstance(obj, gitlab.base.RESTObject):
return obj

if fields:
Expand All @@ -406,7 +406,7 @@ def display(d: Union[str, Dict[str, Any]], **_kwargs: Any) -> None:

@staticmethod
def display_list(
data: List[Union[str, gitlab.base.RESTObject]],
data: List[Union[str, Dict[str, Any], gitlab.base.RESTObject]],
fields: List[str],
**_kwargs: Any,
) -> None:
Expand All @@ -431,7 +431,7 @@ def display(d: Union[str, Dict[str, Any]], **_kwargs: Any) -> None:

@staticmethod
def display_list(
data: List[Union[str, gitlab.base.RESTObject]],
data: List[Union[str, Dict[str, Any], gitlab.base.RESTObject]],
fields: List[str],
**_kwargs: Any,
) -> None:
Expand Down
44 changes: 44 additions & 0 deletions tests/functional/cli/test_cli_repository.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import json
import time


def test_project_create_file(gitlab_cli, project):
file_path = "README"
branch = "main"
Expand Down Expand Up @@ -45,6 +49,46 @@ def test_list_all_commits(gitlab_cli, project):
assert len(ret_all.stdout) > len(ret.stdout)


def test_commit_merge_requests(gitlab_cli, project, merge_request, wait_for_sidekiq):
"""This tests the `project-commit merge-requests` command and also tests
that we can print the result using the `json` formatter"""
Comment thread
nejch marked this conversation as resolved.
# create and then merge a merge-request
mr = merge_request(source_branch="test_commit_merge_requests")
merge_result = mr.merge(should_remove_source_branch=True)
wait_for_sidekiq(timeout=60)
# Wait until it is merged
mr_iid = mr.iid
for _ in range(60):
mr = project.mergerequests.get(mr_iid)
if mr.merged_at is not None:
break
time.sleep(0.5)
assert mr.merged_at is not None
time.sleep(0.5)
wait_for_sidekiq(timeout=60)

commit_sha = merge_result["sha"]
cmd = [
"-o",
"json",
"project-commit",
"merge-requests",
"--project-id",
project.id,
"--id",
commit_sha,
]
ret = gitlab_cli(cmd)
assert ret.success

json_list = json.loads(ret.stdout)
assert isinstance(json_list, list)
assert len(json_list) == 1
mr_dict = json_list[0]
assert mr_dict["id"] == mr.id
assert mr_dict["iid"] == mr.iid


def test_revert_commit(gitlab_cli, project):
commit = project.commits.list()[0]

Expand Down

Back | FazBrowse Home | New Git URL