From c7809c0dc708db071798cc97fedc9486310f9a4f Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 01:43:11 +0000 Subject: [PATCH] feat(actions): add repo variable update Co-Authored-By: Virgil --- actions.go | 6 ++++++ actions_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/actions.go b/actions.go index a980bab..559fb28 100644 --- a/actions.go +++ b/actions.go @@ -71,6 +71,12 @@ func (s *ActionsService) CreateRepoVariable(ctx context.Context, owner, repo, na return s.client.Post(ctx, path, body, nil) } +// UpdateRepoVariable updates an existing action variable in a repository. +func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo, name string, opts *types.UpdateVariableOption) error { + path := ResolvePath("/api/v1/repos/{owner}/{repo}/actions/variables/{name}", pathParams("owner", owner, "repo", repo, "name", name)) + return s.client.Put(ctx, path, opts, nil) +} + // DeleteRepoVariable removes an action variable from a repository. func (s *ActionsService) DeleteRepoVariable(ctx context.Context, owner, repo, name string) error { path := ResolvePath("/api/v1/repos/{owner}/{repo}/actions/variables/{name}", pathParams("owner", owner, "repo", repo, "name", name)) diff --git a/actions_test.go b/actions_test.go index 8b4112a..82a4d09 100644 --- a/actions_test.go +++ b/actions_test.go @@ -141,6 +141,38 @@ func TestActionsService_CreateRepoVariable_Good(t *testing.T) { } } +func TestActionsService_UpdateRepoVariable_Good(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPut { + t.Errorf("expected PUT, got %s", r.Method) + } + if r.URL.Path != "/api/v1/repos/core/go-forge/actions/variables/CI_ENV" { + t.Errorf("wrong path: %s", r.URL.Path) + } + var body types.UpdateVariableOption + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + t.Fatal(err) + } + if body.Name != "CI_ENV_NEW" { + t.Errorf("got name=%q, want %q", body.Name, "CI_ENV_NEW") + } + if body.Value != "production" { + t.Errorf("got value=%q, want %q", body.Value, "production") + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + err := f.Actions.UpdateRepoVariable(context.Background(), "core", "go-forge", "CI_ENV", &types.UpdateVariableOption{ + Name: "CI_ENV_NEW", + Value: "production", + }) + if err != nil { + t.Fatal(err) + } +} + func TestActionsService_DeleteRepoVariable_Good(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodDelete {