DEVX-136: feat: add fix_pr_title module and update_pr API method
Post-merge / detect-and-configure (push) Successful in 12s
Post-merge / release-and-maintain (push) Successful in 1m0s

This commit was merged in pull request #203.
This commit is contained in:
2026-07-13 23:55:11 +00:00
parent 68f0872134
commit ddfbdec956
32 changed files with 2761 additions and 322 deletions
+22 -8
View File
@@ -9,9 +9,10 @@ from devx.gitea_cli import TeaCLIError, configure_tea_login
class TestNotifyFailure:
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.ci.notify_failure.TeaCLI")
def test_creates_issue_with_tea(self, mock_tea_cls: MagicMock) -> None:
def test_creates_issue_with_tea(self, mock_tea_cls: MagicMock, mock_login: MagicMock) -> None:
mock_tea = MagicMock()
mock_tea.list_labels.return_value = [{"id": 5, "name": "bug"}]
mock_tea.create_issue.return_value = {"index": 42, "title": "test"}
@@ -36,9 +37,10 @@ class TestNotifyFailure:
mock_tea.create_issue.assert_called_once()
mock_tea.add_label.assert_called_once_with("owner/repo", 42, ["bug"])
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.ci.notify_failure.TeaCLI")
def test_tea_creates_issue_without_bug_label(self, mock_tea_cls: MagicMock) -> None:
def test_tea_creates_issue_without_bug_label(self, mock_tea_cls: MagicMock, mock_login: MagicMock) -> None:
mock_tea = MagicMock()
mock_tea.list_labels.return_value = [{"id": 1, "name": "enhancement"}]
mock_tea.create_issue.return_value = {"index": 43, "title": "test"}
@@ -53,9 +55,10 @@ class TestNotifyFailure:
assert "issue #43" in result.output
mock_tea.add_label.assert_not_called()
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.ci.notify_failure.TeaCLI")
def test_tea_error_raises(self, mock_tea_cls: MagicMock) -> None:
def test_tea_error_raises(self, mock_tea_cls: MagicMock, mock_login: MagicMock) -> None:
"""When tea fails, the workflow fails — no fallback."""
mock_tea = MagicMock()
mock_tea.list_labels.side_effect = TeaCLIError("network error")
@@ -70,9 +73,12 @@ class TestNotifyFailure:
assert result.exit_code != 0
assert "tea" in result.output.lower()
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.ci.notify_failure.TeaCLI")
def test_tea_list_labels_error_continues_without_labels(self, mock_tea_cls: MagicMock) -> None:
def test_tea_list_labels_error_continues_without_labels(
self, mock_tea_cls: MagicMock, mock_login: MagicMock
) -> None:
"""If listing labels fails via tea, issue is still created without labels."""
mock_tea = MagicMock()
mock_tea.list_labels.side_effect = TeaCLIError("network error")
@@ -87,9 +93,10 @@ class TestNotifyFailure:
assert result.exit_code == 0
assert "issue #50" in result.output
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.ci.notify_failure.TeaCLI")
def test_tea_add_label_error_is_ignored(self, mock_tea_cls: MagicMock) -> None:
def test_tea_add_label_error_is_ignored(self, mock_tea_cls: MagicMock, mock_login: MagicMock) -> None:
"""If adding label fails via tea, issue is still reported as created."""
mock_tea = MagicMock()
mock_tea.list_labels.return_value = [{"id": 5, "name": "bug"}]
@@ -105,8 +112,9 @@ class TestNotifyFailure:
assert result.exit_code == 0
assert "issue #51" in result.output
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": ""}, clear=True)
def test_missing_token_exits(self) -> None:
def test_missing_token_exits(self, mock_login: MagicMock) -> None:
runner = CliRunner()
result = runner.invoke(
main,
@@ -115,10 +123,13 @@ class TestNotifyFailure:
assert result.exit_code != 0
assert "CI_GITEA_TOKEN" in result.output
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": "tok"})
@patch("devx.gitea_cli.shutil.which", return_value=None)
@patch("devx.ci.notify_failure.TeaCLI")
def test_auto_login_no_tea_skips(self, mock_tea_cls: MagicMock, mock_which: MagicMock) -> None:
def test_auto_login_no_tea_skips(
self, mock_tea_cls: MagicMock, mock_which: MagicMock, mock_login: MagicMock
) -> None:
"""--auto-login with tea not installed skips login and still creates issue."""
mock_tea = MagicMock()
mock_tea.list_labels.return_value = []
@@ -133,10 +144,13 @@ class TestNotifyFailure:
assert result.exit_code == 0
assert "issue #60" in result.output
@patch("devx.gitea_cli.configure_tea_login")
@patch.dict("os.environ", {"CI_GITEA_TOKEN": ""}, clear=True)
@patch("devx.gitea_cli.shutil.which", return_value="/usr/bin/tea")
@patch("devx.ci.notify_failure.TeaCLI")
def test_auto_login_no_token_skips_login(self, mock_tea_cls: MagicMock, mock_which: MagicMock) -> None:
def test_auto_login_no_token_skips_login(
self, mock_tea_cls: MagicMock, mock_which: MagicMock, mock_login: MagicMock
) -> None:
"""--auto-login with no CI_GITEA_TOKEN skips login but raises before creating issue."""
mock_tea = MagicMock()
mock_tea_cls.return_value = mock_tea