cigate

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cigate holds a deploy until the CI checks on a commit conclude.

Index

Constants

View Source
const (
	EnvTimeout      = "APP_CI_GATE_TIMEOUT"
	EnvPollInterval = "APP_CI_GATE_POLL_INTERVAL"
	EnvNoChecksWait = "APP_CI_GATE_NO_CHECKS_WAIT"
)

Environment variables that tune the gate.

View Source
const (
	DefaultTimeout      = 15 * time.Minute
	DefaultPollInterval = 15 * time.Second
	DefaultNoChecksWait = time.Minute
)

Defaults used when the environment leaves a value unset or invalid.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	Name  string
	State State
}

Check is one check run or commit status as the provider reports it.

type Config

type Config struct {
	Timeout      time.Duration
	PollInterval time.Duration
	NoChecksWait time.Duration
	Sleep        func(ctx context.Context, d time.Duration) error
	Now          func() time.Time
}

Config tunes polling. Sleep is replaceable so tests need no real time.

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv reads the gate settings, falling back to the defaults.

type GitHub

type GitHub struct {
	HTTP    *http.Client
	BaseURL string
	Token   string
	Owner   string
	Repo    string
	Now     func() time.Time
}

GitHub reads check runs and commit statuses from the GitHub REST API.

func (*GitHub) Checks

func (g *GitHub) Checks(ctx context.Context, sha string) ([]Check, error)

Checks returns check runs and legacy commit statuses for sha.

type Outcome

type Outcome string

Outcome is the gate verdict.

const (
	OutcomePass    Outcome = "pass"
	OutcomeFail    Outcome = "fail"
	OutcomeTimeout Outcome = "timeout"
)

Verdicts.

type Policy

type Policy struct {
	// Required names the checks that must pass; empty means every check seen.
	Required []string
	// IgnorePrefixes drops checks the platform posts itself, which would deadlock the gate.
	IgnorePrefixes []string
}

Policy picks which checks the gate waits for.

type Provider

type Provider interface {
	Checks(ctx context.Context, sha string) ([]Check, error)
}

Provider reads the checks reported for a commit.

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
}

RateLimitError tells the gate to wait before the next read.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type Result

type Result struct {
	Outcome Outcome
	Failing []string
	Pending []string
}

Result carries the verdict and the checks that decided it.

func Wait

func Wait(ctx context.Context, p Provider, sha string, pol Policy, cfg Config) (Result, error)

Wait polls p until every gated check concludes or the timeout passes. A failed check ends the wait at once. Read errors are retried until the timeout, so a flaky provider never reads as a pass.

func (Result) Reason

func (r Result) Reason() string

Reason is a one-line explanation for logs and delivery notes.

type State

type State int

State is the conclusion of one check.

const (
	Pending State = iota
	Passed
	Failed
)

Check states.

Jump to

Keyboard shortcuts

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