hooks

package
v0.35.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Build events (swiftship)
	EventBuildStart          = "build.start"
	EventBuildAnalyzeDone    = "build.analyze.done"
	EventBuildPlanDone       = "build.plan.done"
	EventBuildGenerateDone   = "build.generate.done"
	EventBuildCompileStart   = "build.compile.start"
	EventBuildCompileSuccess = "build.compile.success"
	EventBuildCompileFailure = "build.compile.failure"
	EventBuildFixStart       = "build.fix.start"
	EventBuildFixDone        = "build.fix.done"
	EventBuildRunStart       = "build.run.start"
	EventBuildRunSuccess     = "build.run.success"
	EventBuildDone           = "build.done"

	// Legacy aliases (kept for backward compat with existing configs)
	EventBuildFail = "build.fail"

	// Store events (appstore)
	EventStoreUploadStart     = "store.upload.start"
	EventStoreUploadDone      = "store.upload.done"
	EventStoreUploadFailure   = "store.upload.failure"
	EventStoreProcessingStart = "store.processing.start"
	EventStoreProcessingDone  = "store.processing.done"
	EventStoreTestflightDist  = "store.testflight.distribute"
	EventStoreSubmitStart     = "store.submit.start"
	EventStoreSubmitDone      = "store.submit.done"
	EventStoreSubmitFailure   = "store.submit.failure"
	EventStoreReviewStatus    = "store.review.status"
	EventStoreReviewApproved  = "store.review.approved"
	EventStoreReviewRejected  = "store.review.rejected"
	EventStoreReleaseDone     = "store.release.done"
	EventStoreValidatePass    = "store.validate.pass"
	EventStoreValidateFail    = "store.validate.fail"

	// Legacy aliases
	EventStoreUploadFail     = "store.upload.fail"
	EventStoreSubmitFail     = "store.submit.fail"
	EventStoreRelease        = "store.release"
	EventStoreReviewStart    = "store.review.start"
	EventStoreReviewDone     = "store.review.done"
	EventStoreTestflightDone = "store.testflight.done"

	// Pipeline events
	EventPipelineStart    = "pipeline.start"
	EventPipelineStepDone = "pipeline.step.done"
	EventPipelineDone     = "pipeline.done"
	EventPipelineFailure  = "pipeline.failure"

	// Legacy aliases
	EventWorkflowStart = "workflow.start"
	EventWorkflowDone  = "workflow.done"
	EventWorkflowFail  = "workflow.fail"
	EventWorkflowStep  = "workflow.step"
)

Hook event constants. These are the lifecycle events that can trigger hooks.

Variables

View Source
var TemplateFS embed.FS
View Source
var TemplateNames = map[string]string{
	"indie": "templates/indie.yaml",
	"team":  "templates/team.yaml",
	"ci":    "templates/ci.yaml",
}

TemplateNames maps template identifiers to their embedded file paths.

Functions

func DryRunContext

func DryRunContext(ctx context.Context) context.Context

DryRunContext returns a context with dry-run mode enabled.

func Fire

func Fire(ctx context.Context, eventName string, vars map[string]string) error

Fire loads the hook config, finds hooks matching the given event, and executes them. If no config exists, it returns nil silently.

func FireSafe

func FireSafe(ctx context.Context, eventName string, vars map[string]string)

FireSafe fires a hook event, logging any errors to stderr without returning them. Use this from embedded hook points where failures must never block the main operation.

func GetTemplate

func GetTemplate(name string) ([]byte, error)

GetTemplate returns the content of an embedded template by name.

func NotifySlack

func NotifySlack(ctx context.Context, webhookURL, message string) error

NotifySlack sends a message via a Slack incoming webhook.

func NotifyTelegram

func NotifyTelegram(ctx context.Context, botToken, chatID, message string, silent bool) error

NotifyTelegram sends a message via the Telegram Bot API.

func ResetConfigCache

func ResetConfigCache()

ResetConfigCache clears the cached config (useful for testing or re-reading).

func ResolveBotToken

func ResolveBotToken(envVar, keychainService string) (string, error)

ResolveBotToken resolves a Telegram bot token from: env var, macOS keychain, or error.

func ResolveWebhookURL

func ResolveWebhookURL(envVar string) (string, error)

ResolveWebhookURL resolves a Slack webhook URL from an environment variable.

Types

type Config

type Config struct {
	Version   int                         `yaml:"version"`
	Notifiers map[string]NotifierConfig   `yaml:"notifiers"`
	Defaults  DefaultsConfig              `yaml:"defaults"`
	Hooks     map[string][]HookDefinition `yaml:"hooks"`
}

Config represents the top-level hooks.yaml configuration.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads and merges hooks configuration from global and project paths. Returns nil config (no error) if no config files exist.

func LoadConfigFromPath

func LoadConfigFromPath(path string) (*Config, error)

LoadConfigFromPath loads a single config file (used for validation).

func (*Config) ResolveLogDir

func (c *Config) ResolveLogDir() string

ResolveLogDir returns the expanded log directory path.

type DefaultsConfig

type DefaultsConfig struct {
	Timeout         string `yaml:"timeout"`
	ContinueOnError bool   `yaml:"continue_on_error"`
	LogDir          string `yaml:"log_dir"`
}

DefaultsConfig holds default settings for hook execution.

type HookContext

type HookContext struct {
	Event string
	Vars  map[string]string
}

HookContext carries the event name and key-value variables for template substitution.

type HookDefinition

type HookDefinition struct {
	Name     string `yaml:"name"`
	Run      string `yaml:"run"`
	Notify   string `yaml:"notify"`
	Template string `yaml:"template"`
	When     string `yaml:"when"` // "always", "success", "failure"
	Timeout  string `yaml:"timeout"`
}

HookDefinition defines a single hook action.

func (*HookDefinition) TimeoutDuration

func (h *HookDefinition) TimeoutDuration(defaults DefaultsConfig) time.Duration

TimeoutDuration returns the parsed timeout for a hook, falling back to the config default.

type NotifierConfig

type NotifierConfig struct {
	Enabled          bool   `yaml:"enabled"`
	BotTokenEnv      string `yaml:"bot_token_env"`
	BotTokenKeychain string `yaml:"bot_token_keychain"`
	ChatID           string `yaml:"chat_id"`
	WebhookURLEnv    string `yaml:"webhook_url_env"`
}

NotifierConfig represents a notifier service configuration.

type TemplateNotFoundError

type TemplateNotFoundError struct {
	Name string
}

TemplateNotFoundError is returned when a template name is not recognized.

func (*TemplateNotFoundError) Error

func (e *TemplateNotFoundError) Error() string

Jump to

Keyboard shortcuts

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