From bb5c3c0e5be0dc41cc14be39eb91b398bce4760f Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 02:40:45 +0000 Subject: [PATCH] Add repo runner registration token Co-Authored-By: Virgil --- repos.go | 10 ++++++++++ repos_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/repos.go b/repos.go index 6379524..a72132a 100644 --- a/repos.go +++ b/repos.go @@ -727,6 +727,16 @@ func (s *RepoService) MirrorSync(ctx context.Context, owner, repo string) error return s.client.Post(ctx, path, nil, nil) } +// GetRunnerRegistrationToken returns a repository actions runner registration token. +func (s *RepoService) GetRunnerRegistrationToken(ctx context.Context, owner, repo string) (string, error) { + path := ResolvePath("/api/v1/repos/{owner}/{repo}/actions/runners/registration-token", pathParams("owner", owner, "repo", repo)) + resp, err := s.client.doJSON(ctx, http.MethodGet, path, nil, nil) + if err != nil { + return "", err + } + return resp.Header.Get("token"), nil +} + // SyncPushMirrors triggers a sync across all push mirrors configured for a repository. func (s *RepoService) SyncPushMirrors(ctx context.Context, owner, repo string) error { path := ResolvePath("/api/v1/repos/{owner}/{repo}/push_mirrors-sync", pathParams("owner", owner, "repo", repo)) diff --git a/repos_test.go b/repos_test.go index b9121cb..234c647 100644 --- a/repos_test.go +++ b/repos_test.go @@ -74,6 +74,31 @@ func TestRepoService_GetByID_Good(t *testing.T) { } } +func TestRepoService_GetRunnerRegistrationToken_Good(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + t.Errorf("expected GET, got %s", r.Method) + } + if r.URL.Path != "/api/v1/repos/core/go-forge/actions/runners/registration-token" { + t.Errorf("wrong path: %s", r.URL.Path) + http.NotFound(w, r) + return + } + w.Header().Set("token", "runner-token") + w.WriteHeader(http.StatusOK) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + token, err := f.Repos.GetRunnerRegistrationToken(context.Background(), "core", "go-forge") + if err != nil { + t.Fatal(err) + } + if token != "runner-token" { + t.Fatalf("got token=%q, want %q", token, "runner-token") + } +} + func TestRepoService_ListTopics_Good(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet {