From 6a463a93d2de1dbf454f500bdd0f0f57811e6115 Mon Sep 17 00:00:00 2001 From: emil Date: Tue, 7 Jul 2026 15:51:45 +0000 Subject: [PATCH] DEVX-121: fix: GiteaClient.set_repo_variable uses PUT instead of PATCH --- src/devx/api_clients.py | 9 +++++---- tests/unit/test_api_clients.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/devx/api_clients.py b/src/devx/api_clients.py index 3d2e690..301bc72 100644 --- a/src/devx/api_clients.py +++ b/src/devx/api_clients.py @@ -391,15 +391,16 @@ class GiteaClient: def set_repo_variable(self, name: str, value: str) -> None: """Create or update a Gitea Actions repository variable (idempotent). - Tries PATCH first; if the variable doesn't exist (404), creates it - via POST. + Tries PUT first (update); if the variable doesn't exist (404), + creates it via POST. Gitea 1.26.x does not support PATCH for + action variables. """ try: - self._request("PATCH", f"/actions/variables/{name}", json={"value": value}) + self._request("PUT", f"/actions/variables/{name}", json={"value": value}) except APIError as e: if e.status != 404: raise - self._request("POST", "/actions/variables", json={"name": name, "value": value}) + self._request("POST", f"/actions/variables/{name}", json={"value": value}) class VikunjaClient: diff --git a/tests/unit/test_api_clients.py b/tests/unit/test_api_clients.py index d104d37..6738ee8 100644 --- a/tests/unit/test_api_clients.py +++ b/tests/unit/test_api_clients.py @@ -944,7 +944,7 @@ class TestGiteaClientActions: client._session.request = MagicMock(return_value=_mock_response({})) client.set_repo_variable("PRODUCTION_DEPLOY_TAG", "v0.28.2") client._session.request.assert_called_once_with( - "PATCH", + "PUT", "https://git.example.com/repos/owner/repo/actions/variables/PRODUCTION_DEPLOY_TAG", timeout=DEFAULT_TIMEOUT, json={"value": "v0.28.2"}, @@ -960,8 +960,8 @@ class TestGiteaClientActions: assert client._session.request.call_count == 2 second_call = client._session.request.call_args_list[1] assert second_call.args[0] == "POST" - assert second_call.args[1] == "https://git.example.com/repos/owner/repo/actions/variables" - assert second_call.kwargs["json"] == {"name": "NEW_VAR", "value": "v0.29.0"} + assert second_call.args[1] == "https://git.example.com/repos/owner/repo/actions/variables/NEW_VAR" + assert second_call.kwargs["json"] == {"value": "v0.29.0"} def test_set_repo_variable_reraises_non_404(self) -> None: client = GiteaClient("https://git.example.com", "tok", "owner", "repo")