Add three new services for the Forgejo API client: - ActionsService: repo/org secrets, variables, workflow dispatch - NotificationService: list, mark read, thread operations - PackageService: list, get, delete packages and files Wire up real constructors in forge.go and remove stubs from services_stub.go. All 21 new tests pass. Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
3.3 KiB
Go
77 lines
3.3 KiB
Go
package forge
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"forge.lthn.ai/core/go-forge/types"
|
|
)
|
|
|
|
// ActionsService handles CI/CD actions operations across repositories and
|
|
// organisations — secrets, variables, and workflow dispatches.
|
|
// No Resource embedding — heterogeneous endpoints across repo and org levels.
|
|
type ActionsService struct {
|
|
client *Client
|
|
}
|
|
|
|
func newActionsService(c *Client) *ActionsService {
|
|
return &ActionsService{client: c}
|
|
}
|
|
|
|
// ListRepoSecrets returns all secrets for a repository.
|
|
func (s *ActionsService) ListRepoSecrets(ctx context.Context, owner, repo string) ([]types.Secret, error) {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/secrets", owner, repo)
|
|
return ListAll[types.Secret](ctx, s.client, path, nil)
|
|
}
|
|
|
|
// CreateRepoSecret creates or updates a secret in a repository.
|
|
// Forgejo expects a PUT with {"data": "secret-value"} body.
|
|
func (s *ActionsService) CreateRepoSecret(ctx context.Context, owner, repo, name string, data string) error {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/secrets/%s", owner, repo, name)
|
|
body := map[string]string{"data": data}
|
|
return s.client.Put(ctx, path, body, nil)
|
|
}
|
|
|
|
// DeleteRepoSecret removes a secret from a repository.
|
|
func (s *ActionsService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) error {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/secrets/%s", owner, repo, name)
|
|
return s.client.Delete(ctx, path)
|
|
}
|
|
|
|
// ListRepoVariables returns all action variables for a repository.
|
|
func (s *ActionsService) ListRepoVariables(ctx context.Context, owner, repo string) ([]types.ActionVariable, error) {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/variables", owner, repo)
|
|
return ListAll[types.ActionVariable](ctx, s.client, path, nil)
|
|
}
|
|
|
|
// CreateRepoVariable creates a new action variable in a repository.
|
|
// Forgejo expects a POST with {"value": "var-value"} body.
|
|
func (s *ActionsService) CreateRepoVariable(ctx context.Context, owner, repo, name, value string) error {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/variables/%s", owner, repo, name)
|
|
body := types.CreateVariableOption{Value: value}
|
|
return s.client.Post(ctx, path, body, nil)
|
|
}
|
|
|
|
// DeleteRepoVariable removes an action variable from a repository.
|
|
func (s *ActionsService) DeleteRepoVariable(ctx context.Context, owner, repo, name string) error {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/variables/%s", owner, repo, name)
|
|
return s.client.Delete(ctx, path)
|
|
}
|
|
|
|
// ListOrgSecrets returns all secrets for an organisation.
|
|
func (s *ActionsService) ListOrgSecrets(ctx context.Context, org string) ([]types.Secret, error) {
|
|
path := fmt.Sprintf("/api/v1/orgs/%s/actions/secrets", org)
|
|
return ListAll[types.Secret](ctx, s.client, path, nil)
|
|
}
|
|
|
|
// ListOrgVariables returns all action variables for an organisation.
|
|
func (s *ActionsService) ListOrgVariables(ctx context.Context, org string) ([]types.ActionVariable, error) {
|
|
path := fmt.Sprintf("/api/v1/orgs/%s/actions/variables", org)
|
|
return ListAll[types.ActionVariable](ctx, s.client, path, nil)
|
|
}
|
|
|
|
// DispatchWorkflow triggers a workflow run.
|
|
func (s *ActionsService) DispatchWorkflow(ctx context.Context, owner, repo, workflow string, opts map[string]any) error {
|
|
path := fmt.Sprintf("/api/v1/repos/%s/%s/actions/workflows/%s/dispatches", owner, repo, workflow)
|
|
return s.client.Post(ctx, path, opts, nil)
|
|
}
|