slackrender

package
v0.19.968 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package slackrender renders Slack message text and blocks for Nuon workflow / workflow_step / workflow_step_approval lifecycle events.

The renderer is purely a pure function of its input Event — it never calls back into ctl-api. Producers (the slack lifecycle hook) are expected to enrich the Event from the same canonical sources the webhook hook uses.

This package mirrors the input shape used by slackbot's notify package (lifecycle.WebhookPayload / EventData / WorkflowRef / StepRef / etc.) so the rendering logic can be ported with minimal adaptation. The difference from slackbot is the OUTPUT contract: slackbot emits one inlined line; we keep the existing two-block shape — a SECTION block (bold headline + optional status sub-line) plus a CONTEXT block (small grey footer with org/install/workflow chips and an Open in Nuon link).

Index

Constants

View Source
const (
	KindWorkflow             = "workflow"
	KindWorkflowStep         = "workflow_step"
	KindWorkflowStepApproval = "workflow_step_approval"
)

Kind values for Event.Kind. Matches the wire vocabulary in services/ctl-api/internal/pkg/queue/signal/hooks/webhook.go.

View Source
const (
	TransitionStarted   = "started"
	TransitionSucceeded = "succeeded"
	TransitionFailed    = "failed"
	TransitionCancelled = "cancelled"

	TransitionRequested = "requested"
	TransitionApproved  = "approved"
	TransitionRejected  = "rejected"
)

Transition values for Event.Transition. British "cancelled" is the canonical wire value (matches webhook.go's transitionCanceled).

View Source
const (
	OwnerTypeInstalls    = "installs"
	OwnerTypeApps        = "apps"
	OwnerTypeAppBranches = "app_branches"
)

OwnerType values for WorkflowRef.OwnerType.

View Source
const (
	WorkflowTypeProvision          = "provision"
	WorkflowTypeReprovision        = "reprovision"
	WorkflowTypeManualDeploy       = "manual_deploy"
	WorkflowTypeActionWorkflowRun  = "action_workflow_run"
	WorkflowTypeDriftRun           = "drift_run"
	WorkflowTypeDeployComponents   = "deploy_components"
	WorkflowTypeTeardownComponent  = "teardown_component"
	WorkflowTypeTeardownComponents = "teardown_components"
	WorkflowTypeInputUpdate        = "input_update"
	WorkflowTypeSyncSecrets        = "sync_secrets"
	WorkflowTypeDeprovision        = "deprovision"
	WorkflowTypeDeprovisionSandbox = "deprovision_sandbox"
	WorkflowTypeReprovisionSandbox = "reprovision_sandbox"
	WorkflowTypeAppConfigBuild     = "app_config_build"
	WorkflowTypeAppBranchesRun     = "app_branches_manual_update"
)

WorkflowType values for WorkflowRef.Type.

View Source
const (
	TargetTypeInstallDeploys             = "install_deploys"
	TargetTypeInstallSandboxRuns         = "install_sandbox_runs"
	TargetTypeInstallActionWorkflowRuns  = "install_action_workflow_runs"
	TargetTypeInstallCloudFormationStack = "install_cloudformation_stack"
	TargetTypeInstallRunnerUpdate        = "install_runner_update"
)

TargetType values for StepRef.TargetType. Matches the actual string values stored in install_workflow_steps.step_target_type, which is the plural form of the app.WorkflowStepTargetType* constants — the singular constants exist but are not what the DB carries.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApprovalRef

type ApprovalRef struct {
	ID          string
	Type        string
	Plan        string
	RespondedBy string
}

ApprovalRef carries the structured approval block on workflow_step_approval events.

type ContextLinks struct {
	Org        string
	Install    string
	Workflow   string
	Sandbox    string
	Component  string
	Approval   string
	RespondAPI string
}

ContextLinks contains dashboard / API URLs for the entities referenced in the event. Any field may be empty.

type Event

type Event struct {
	Kind       string
	Transition string

	OrgID   string
	OrgName string

	Workflow WorkflowRef
	Step     *StepRef
	Parent   *ParentRef
	Outcome  *Outcome
	Approval *ApprovalRef
	Links    *ContextLinks
}

Event is the input to every Build* renderer function. It mirrors the ctl-api webhook payload shape (lifecycleEventData) one-to-one so the slack lifecycle hook can build it from the same enrichment sources.

func (Event) IsTerminal

func (e Event) IsTerminal() bool

IsTerminal reports whether the event represents a terminal transition.

type LinkChip

type LinkChip struct {
	Label string
	URL   string
}

LinkChip is a (label, url) pair rendered as a clickable mrkdwn chip in the trailing context block.

type Message

type Message struct {
	Text   string
	Blocks []any
}

Message is the rendered output of a Build* call: a fallback text string (used by Slack when blocks aren't supported) and the structured blocks posted as the message body.

func BuildChildMessage

func BuildChildMessage(e Event) Message

BuildChildMessage renders the per-event threaded reply.

func BuildDriftDetectedMessage

func BuildDriftDetectedMessage(e Event) Message

BuildDriftDetectedMessage renders a standalone (non-threaded) drift notification.

Drift workflows produce no useful "running drift check" signal for subscribers — the only event that matters is "drift was actually detected on resource X". So drift events are deliberately NOT anchored under a parent post; each detection is its own top-level message that links directly to the affected component or sandbox.

Headline: "🌊 Drift detected — <component name>" for component drift, "🌊 Drift detected on sandbox" for sandbox drift. Footer carries the org / install chips. The link chip points at the most specific resource available (component → sandbox → install).

func BuildFlatMessage

func BuildFlatMessage(e Event) Message

BuildFlatMessage renders a defensive single-block fallback for events without a workflow id (e.g. install-created). Same shape as the child.

func BuildParentMessage

func BuildParentMessage(e Event, startedAt time.Time) Message

BuildParentMessage renders the workflow's parent post — emitted on the first event for a workflow. The parent's shape (headline + status + footer + links) is identical to BuildParentRollup so the post never visually grows or rearranges across edits.

startedAt is the workflow's first-event timestamp. When zero, the "running 5m" / "ran 5m" line is omitted.

func BuildParentRollup

func BuildParentRollup(e Event, startedAt time.Time) Message

BuildParentRollup renders the parent post on every subsequent edit. Identical layout to BuildParentMessage by design.

type Outcome

type Outcome struct {
	Status     string
	Error      string
	DurationMs int64
}

Outcome is set on terminal transitions (succeeded / failed / cancelled).

type ParentRef

type ParentRef struct {
	WorkflowID string
	StepID     string
	Kind       string
	ActionName string
}

ParentRef is set when this workflow was launched from another workflow's step (e.g. an action workflow run launched from a deploy step).

type StepRef

type StepRef struct {
	ID            string
	Name          string
	Idx           int
	TargetType    string
	TargetID      string
	ComponentID   string
	ComponentName string
	SandboxID     string
	ExecutionType string
}

StepRef identifies a workflow step. Present only on workflow_step / workflow_step_approval events.

type WorkflowRef

type WorkflowRef struct {
	ID        string
	Type      string
	OwnerID   string
	OwnerType string
	OwnerName string
}

WorkflowRef identifies the workflow this event is about.

Jump to

Keyboard shortcuts

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