go-forge/webhooks.go
Claude 1ffb4bee5a
All checks were successful
Security Scan / security (push) Successful in 8s
Test / test (push) Successful in 1m20s
feat: upgrade to core v0.8.0-alpha.1, replace banned stdlib imports
Replace fmt, errors, strings, path/filepath, encoding/json with Core
primitives across 23 files. Keep encoding/json for streaming
NewDecoder/NewEncoder, strings for Fields/FieldsFuncSeq.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 13:27:06 +00:00

41 lines
1.4 KiB
Go

package forge
import (
"context"
"iter"
core "dappco.re/go/core"
"dappco.re/go/core/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 := core.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 := core.Sprintf("/api/v1/orgs/%s/hooks", org)
return ListAll[types.Hook](ctx, s.client, path, nil)
}
// IterOrgHooks returns an iterator over all webhooks for an organisation.
func (s *WebhookService) IterOrgHooks(ctx context.Context, org string) iter.Seq2[types.Hook, error] {
path := core.Sprintf("/api/v1/orgs/%s/hooks", org)
return ListIter[types.Hook](ctx, s.client, path, nil)
}