Add repo runner registration token
Some checks failed
Security Scan / security (push) Successful in 12s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:40:45 +00:00
parent 4a7743a8ac
commit bb5c3c0e5b
2 changed files with 35 additions and 0 deletions

View file

@ -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))

View file

@ -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 {