Public Access
DEVX-1: Extract reusable dev/CI tools from GRM into devx package #1
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user