Skip to content
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
9 changes: 9 additions & 0 deletions src/poly/cli_commands/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ def delete_gists(cls, gist_id: Optional[str] = None, output_json: bool = False)
choices = [format_gist_choice(g) for g in gists]
description_to_id = {format_gist_choice(g): g["id"] for g in gists}

if output_json:
json_print(
{
"success": False,
"error": "Please provide a gist ID to delete when using JSON output.",
}
)
return

selected = questionary.checkbox("Select gists to delete", choices=choices).ask()
if not selected:
warning("No gists selected. Exiting.")
Expand Down
6 changes: 4 additions & 2 deletions src/poly/resources/handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ def from_projection(cls, projection: dict) -> dict[str, "Handoff"]:
return handoffs

def to_yaml_dict(self) -> dict:
return {
result = {
"name": self.name,
"description": self.description,
"is_default": self.is_default,
"sip_config": self.sip_config.to_yaml_dict(),
"sip_headers": self.sip_headers,
}
if self.sip_headers:
result["sip_headers"] = self.sip_headers
return result

@property
def file_path(self) -> str:
Expand Down
18 changes: 13 additions & 5 deletions src/poly/tests/github_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,23 @@ def test_direct_gist_id_with_json_output(self, mock_json_print, mock_delete, moc
@patch("poly.cli_commands.review.GitHubAPIHandler.delete_gist")
@patch("questionary.checkbox")
@patch("poly.cli_commands.review.json_print")
def test_json_output_prints_success(self, mock_json_print, mock_checkbox, mock_delete, mock_list):
"""With output_json=True, a success JSON object is printed after deletion."""
def test_json_output_without_gist_id_errors_without_prompting(
self, mock_json_print, mock_checkbox, mock_delete, mock_list
):
"""With output_json=True and no gist_id, a JSON error is printed and the
interactive checkbox prompt is never shown."""
mock_list.return_value = self.SAMPLE_GISTS
first_choice = format_gist_choice(self.SAMPLE_GISTS[0])
mock_checkbox.return_value.ask.return_value = [first_choice]

ReviewCommand.delete_gists(output_json=True)

mock_json_print.assert_called_once_with({"success": True})
mock_checkbox.assert_not_called()
mock_delete.assert_not_called()
mock_json_print.assert_called_once_with(
{
"success": False,
"error": "Please provide a gist ID to delete when using JSON output.",
}
)


class ListGistsTest(unittest.TestCase):
Expand Down
Loading