management

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCallbackURLNotConfigured is returned when BITBUCKET__CALLBACK_URL is
	// empty and webhook management requires it.
	ErrCallbackURLNotConfigured = errors.New("bitbucket callback url not configured")

	// ErrCallbackURLInvalid is returned when the callback URL is not https or
	// carries a query string or fragment.
	ErrCallbackURLInvalid = errors.New("bitbucket callback url invalid")

	// ErrSecretNotConfigured is returned when WEBHOOKS__SECRET is empty and
	// registration requires a verifiable secret.
	ErrSecretNotConfigured = errors.New("webhook secret not configured")

	// ErrOAuthDisabled is returned when the Bitbucket OAuth service is
	// disabled by configuration.
	ErrOAuthDisabled = errors.New("bitbucket oauth disabled")

	// ErrOAuthNotConnected is returned when no usable OAuth token exists.
	ErrOAuthNotConnected = errors.New("bitbucket oauth not connected")

	// ErrNotBitbucketRepo is returned when a project repository URL is not a
	// bitbucket.org URL.
	ErrNotBitbucketRepo = errors.New("not a bitbucket repository")
)

Functions

func Module

func Module() fx.Option

Types

type Config

type Config struct {
	// Secret is the shared signing secret Bitbucket attaches to deliveries
	// and the service registers on managed hooks.
	Secret string

	// CallbackURL is the public base URL (https scheme://host[/path], no
	// query string or fragment) where Bitbucket webhooks are delivered. The
	// full delivery path is appended by the management service.
	CallbackURL string
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages Bitbucket repository webhooks for projects, gated on the requesting admin's OAuth token. It is fully stateless.

func NewService

func NewService(
	config Config,
	client *bitbucket.Client,
	oauthSvc *oauth.Service,
	projectsSvc *projects.Service,
	logger *zap.Logger,
) *Service

NewService wires the management service. The Bitbucket client is the leaf pkg/bitbucket client; the OAuth service resolves the requesting admin's token; the projects service resolves slugs to repositories.

func (*Service) Register

func (s *Service) Register(ctx context.Context, userID int64, projectSlug string) (*WebhookStatus, error)

Register creates the project webhook in Bitbucket, or updates the existing one when a hook already targets our callback URL. Registration fails closed on an empty secret or invalid callback URL.

func (*Service) Status

func (s *Service) Status(ctx context.Context, userID int64, projectSlug string) (*WebhookStatus, error)

Status reports the live Bitbucket webhook state for a project. Local prerequisites (callback URL, OAuth connection) are reported as an unavailable status instead of errors; a missing secret never blocks status.

func (*Service) Unregister

func (s *Service) Unregister(ctx context.Context, userID int64, projectSlug string) error

Unregister deletes the project webhook from Bitbucket. Deleting a missing hook is an idempotent no-op.

type Status

type Status string

Status is the live management status of a project's Bitbucket webhook (canonical_webhook_contract).

const (
	StatusRegistered    Status = "registered"
	StatusNotRegistered Status = "not_registered"
	StatusFailed        Status = "failed"
	StatusUnavailable   Status = "unavailable"
)

Webhook status values (canonical_webhook_contract).

type WebhookStatus

type WebhookStatus struct {
	Status        Status
	HookUUID      *string
	CallbackURL   string
	FailureReason *string
	UpdatedAt     *string
}

WebhookStatus is the live management status of a project's Bitbucket webhook. No webhook state is persisted; every read queries Bitbucket.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL