go-forge/webhooks.go
Snider de76399608 feat: LabelService, WebhookService, ContentService
Add three new services covering labels, webhooks, and file content
operations. LabelService handles repo and org labels without Resource
embedding due to heterogeneous paths. WebhookService embeds Resource
for standard CRUD on repo hooks plus action methods for test delivery
and org hooks. ContentService provides file CRUD and raw file retrieval.
Adds GetRaw method to Client for non-JSON responses.

Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:14:01 +00:00

34 lines
1.1 KiB
Go

package forge
import (
"context"
"fmt"
"forge.lthn.ai/core/go-forge/types"
)
// WebhookService handles webhook (hook) operations within a repository.
// Embeds Resource for standard CRUD on /api/v1/repos/{owner}/{repo}/hooks/{id}.
type WebhookService struct {
Resource[types.Hook, types.CreateHookOption, types.EditHookOption]
}
func newWebhookService(c *Client) *WebhookService {
return &WebhookService{
Resource: *NewResource[types.Hook, types.CreateHookOption, types.EditHookOption](
c, "/api/v1/repos/{owner}/{repo}/hooks/{id}",
),
}
}
// TestHook triggers a test delivery for a webhook.
func (s *WebhookService) TestHook(ctx context.Context, owner, repo string, id int64) error {
path := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/%d/tests", owner, repo, id)
return s.client.Post(ctx, path, nil, nil)
}
// ListOrgHooks returns all webhooks for an organisation.
func (s *WebhookService) ListOrgHooks(ctx context.Context, org string) ([]types.Hook, error) {
path := fmt.Sprintf("/api/v1/orgs/%s/hooks", org)
return ListAll[types.Hook](ctx, s.client, path, nil)
}