requireconditional

package
v0.0.0-...-070363a Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package requireconditional provides the core implementation for the `blend/require-conditional-status-checks` GitHub Action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSatisfied

func CheckSatisfied(ctx context.Context, action *githubactions.Action, client *github.Client, cfg *Config, required []string) ([]string, error)

CheckSatisfied determines which `required` checks have successfully completed and which are still running. If **any** checks have completed unsuccessfully, an error will be returned.

This uses the `GET /repos/:org/:repo/commits/:ref/check-runs` API to get the status and conclusion of all checks associated with the `HEAD` SHA for the current pull request and checks the status of the `required` checks.

func Run

func Run(action *githubactions.Action) error

Run executes the Require Conditional Status Checks GitHub Action; it parses a list of checks from the GitHub Actions inputs to determine **which** checks should be required for a given pull request. This is directly tied to the files changed in the PR.

func Wait

func Wait(ctx context.Context, action *githubactions.Action, client *github.Client, cfg *Config, incomplete []string) error

Wait polls the checks associated with the the `HEAD` SHA for the current pull request until either - **all** required runs have completed successfully - **at least one** required run has completed unsuccessfully - the context is done (due to timeout)

Types

type Check

type Check struct {
	Job   string   `json:"job,omitempty" yaml:"job,omitempty"`
	Paths []string `json:"paths,omitempty" yaml:"paths,omitempty"`
}

Check represents a required check on a pull request.

func (Check) Required

func (c Check) Required(cc *github.CommitsComparison) (bool, error)

Required determines if a check should be required for a given pair of compared commits.

type Config

type Config struct {
	GitHubToken    string
	Timeout        time.Duration
	Interval       time.Duration
	ChecksYAML     string
	ChecksFilename string
	GitHubRootURL  string
	EventName      string
	EventAction    string
	GitHubOrg      string
	GitHubRepo     string
	BaseSHA        string
	HeadSHA        string
}

Config represents parsed configuration for this GitHub Action.

func NewFromInputs

func NewFromInputs(action *githubactions.Action) (*Config, error)

NewFromInputs parses GitHub Actions inputs into a `Config`.

func (Config) GetChecks

func (c Config) GetChecks(ctx context.Context, client *github.Client) ([]Check, error)

GetChecks returns the checks for the current `Config`. Will be from either `ChecksYAML` or `ChecksFilename`. Using `ChecksFilename` will require a request to the GitHub API to read the file.

func (Config) Validate

func (c Config) Validate() error

Validate checks that a `Config` is valid. - The `EventName` must be `pull_request` - The `EventAction` must be `opened`, `synchronize` or `reopened` - The `BaseSHA` must be set to something - The `HeadSHA` must be set to something - The `GitHubOrg` must be set to something - The `GitHubRepo` must be set to something - The `GitHubRootURL` must be set to something - The `GitHubToken` must be set to something - Exactly one of `ChecksYAML` and `ChecksFilename` must be set

Jump to

Keyboard shortcuts

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