statusmanager

package
v0.9.2 Latest Latest
Warning

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

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

Documentation

Overview

Package statusmanager provides Kubernetes-style status management for GitHub reconcilers using GitHub Check Runs API.

This package implements a pattern similar to Kubernetes reconciliation where: - Each commit SHA is treated like a Kubernetes resource generation - The reconciler tracks which SHA it has observed/processed - Status is persisted in GitHub Check Runs instead of PR comments - Check Runs provide per-commit status tracking with structured data

Architecture

The package is built around three main types:

StatusManager: The top-level manager that holds configuration like identity, project ID, and service name. It creates sessions for individual PR reconciliations.

Session: Represents a reconciliation session for a specific PR. It encapsulates all the state needed to read and write status for a particular commit SHA.

Status: The structured data that gets persisted in Check Runs. It includes the observed generation (SHA), status, conclusion, and reconciler-specific details.

Usage

First, create a StatusManager with your reconciler's identity:

sm, err := statusmanager.NewStatusManager[MyDetails](ctx, "my-reconciler")
if err != nil {
    return err
}

For each PR reconciliation, create a session:

session := sm.NewSession(githubClient, pullRequest)

Check the current state (optional):

status, err := session.ObservedState(ctx)
if err != nil {
    return err
}
// Use status to determine if reconciliation is needed

Update status during reconciliation:

// Set initial in-progress status
err = session.SetActualState(ctx, "Processing", &statusmanager.Status[MyDetails]{
    Status: "in_progress",
    Details: MyDetails{},
})

// ... perform reconciliation ...

// Set final status
err = session.SetActualState(ctx, "Complete", &statusmanager.Status[MyDetails]{
    Status: "completed",
    Conclusion: "success",
    Details: MyDetails{
        // ... reconciliation results ...
    },
})

Custom Markdown Rendering

If your details type implements the Markdown() method, it will be used to generate visible output in the Check Run:

type MyDetails struct {
    FilesProcessed int
    Errors []string
}

func (d MyDetails) Markdown() string {
    return fmt.Sprintf("Processed %d files", d.FilesProcessed)
}

Status Embedding

The structured status data is embedded in HTML comments within the Check Run output, making it both human-readable (via Markdown) and machine-parseable (via embedded JSON). This allows the reconciler to read back its previous state on subsequent runs.

Cloud Logging Integration

Each Check Run includes a details URL that links to Cloud Logging with pre-configured filters for the specific PR and commit SHA, making it easy to view logs for that particular reconciliation run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotated added in v0.7.4

type Annotated interface {
	Annotations() []*github.CheckRunAnnotation
}

Annotated is an interface for types that can provide GitHub check run annotations

type Session

type Session[T any] struct {
	// contains filtered or unexported fields
}

Session represents a reconciliation session for a specific resource

func (*Session[T]) ObservedState

func (s *Session[T]) ObservedState(ctx context.Context) (*Status[T], error)

ObservedState retrieves the last observed state for the current SHA

func (*Session[T]) SetActualState

func (s *Session[T]) SetActualState(ctx context.Context, title string, status *Status[T]) error

SetActualState updates the state for the current SHA

type Status

type Status[T any] struct {
	// ObservedGeneration is the last commit SHA that was fully processed
	ObservedGeneration string `json:"observedGeneration"`

	// Status represents the current status of the check run
	// Can be: "queued", "in_progress", or "completed"
	Status string `json:"status"`

	// Conclusion represents the conclusion when status is "completed"
	// Can be: "action_required", "cancelled", "failure", "neutral",
	// "success", "skipped", "stale", or "timed_out"
	Conclusion string `json:"conclusion,omitempty"`

	// Details contains reconciler-specific state data
	Details T `json:"details"`
}

Status represents the overall status of reconciliation

type StatusManager

type StatusManager[T any] struct {
	// contains filtered or unexported fields
}

StatusManager manages reconciliation status via GitHub Check Runs

func NewReadOnlyStatusManager added in v0.7.9

func NewReadOnlyStatusManager[T any](ctx context.Context, identity string) (*StatusManager[T], error)

NewReadOnlyStatusManager creates a new read-only status manager with the given identity. A read-only status manager will fail any operations that attempt to mutate GitHub state.

func NewStatusManager

func NewStatusManager[T any](ctx context.Context, identity string) (*StatusManager[T], error)

NewStatusManager creates a new status manager with the given identity

func (*StatusManager[T]) NewSession

func (sm *StatusManager[T]) NewSession(client *github.Client, res *githubreconciler.Resource, sha string) *Session[T]

NewSession creates a new reconciliation session for a GitHub resource and SHA. The resource provides owner, repo, and URL (used as key for log filtering). The SHA is the commit to attach check runs to.

func (*StatusManager[T]) ObservedStateAtSHA added in v0.7.6

func (sm *StatusManager[T]) ObservedStateAtSHA(
	ctx context.Context,
	client *github.Client,
	res *githubreconciler.Resource,
	sha string,
) (*Status[T], error)

ObservedStateAtSHA retrieves the status for a specific commit SHA without creating a session. This is useful for gathering historical status across multiple commits.

Jump to

Keyboard shortcuts

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