badges

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(service Service, cache Cache) http.Handler

NewHandler returns an implementation of the http.handler interface that can serve badges by by delegating to a transport-agnostic Service interface.

Types

type Badge

type Badge interface {
	// Name returns the label text that should appear on the left of a badge.
	Name() string
	// Status returns the badge status that should appear on the right of a badge.
	Status() string
	// Color returns a Color constant that indicates badge color.
	Color() Color
}

Badge is an interface for any type that represents a badge.

type Cache

type Cache interface {
	// Set writes a result to both warm and cold caches.
	Set(key, value string) error
	// Get reads a result from the warm cache. An empty string return value
	// indicates a cache miss.
	GetWarm(key string) (string, error)
	// Get reads a result from the cold cache. An empty string return value
	// indicates a cache miss.
	GetCold(key string) (string, error)
}

Cache is the public interface for any component that can cache results.

type CheckBadge

type CheckBadge struct {
	// contains filtered or unexported fields
}

CheckBadge is an implementation of Badge that represents the results of a GitHub check suite, or possibly the combined results of multiple GitHub check suites.

func (CheckBadge) Color

func (c CheckBadge) Color() Color

func (CheckBadge) Name

func (c CheckBadge) Name() string

func (CheckBadge) Status

func (c CheckBadge) Status() string

type CheckBadgeOptions

type CheckBadgeOptions struct {
	// BadgeName specifies a name that should be applied to the badge. If left
	// unspecified, it will default to "build".
	BadgeName string
	// Branch indicates the branch upon whose check suites the badge should be
	// based. If left unspecified, it will default to "main".
	Branch string
	// GitHubAppID specifies that the badge should be based on the results only of
	// check suites associated with the indicated GitHub App ID. If left
	// unspecified (0), the badge will reflect the combined results of multiple
	// check suites.
	GitHubAppID int
}

type CheckStatus

type CheckStatus uint8

CheckStatus represents the status of a GitHub check suite.

const (

	// CheckStatusUnknown represents the case where Badgr has been unable to
	// determine a check suite's status.
	CheckStatusUnknown CheckStatus = iota
	// CheckStatusFailed represents the case where a check suite has run to
	// completion and failed.
	CheckStatusFailed
	// CheckStatusTimedOut represents the case where a check suite has time out.
	CheckStatusTimedOut
	// CheckStatusActionRequired represents the case where a check suite has run
	// to completion but some action is required from a user.
	CheckStatusActionRequired
	// CheckStatusCancelled represents the case where execution of a test suite
	// has been voluntarily terminated by a user or some other process.
	CheckStatusCanceled
	// CheckStatusNeutral represents the case where a check suite has run to
	// completion and neither failed nor succeeded.
	CheckStatusNeutral
	// CheckStatusQueued represents the case where none of the checks in the check
	// suite have been reported yet as being complete or in progress.
	CheckStatusQueued
	// CheckStatusInProgress represents the case where one or more checks in the
	// suite has progressed past the queued state, but not all checks are
	// complete.
	CheckStatusInProgress
	// CheckStatusFailed represents the case where a check suite has run to
	// completion and succeeded.
	CheckStatusPassed
)

func (CheckStatus) Color

func (c CheckStatus) Color() Color

Color returns a Color constant that corresponds to the CheckStatus value.

func (CheckStatus) String

func (c CheckStatus) String() string

String returns a textual representation of a numeric CheckStatus value.

type Color

type Color string

Color represents the color of a badge.

const (
	// ColorGreen represents green.
	ColorGreen Color = "brightgreen"
	// ColorBlue represents blue.
	ColorBlue Color = "blue"
	// ColorYellow represents yellow.
	ColorYellow Color = "yellow"
	// ColorRed represents red.
	ColorRed Color = "red"
)

type ErrBadge

type ErrBadge struct {
	// contains filtered or unexported fields
}

ErrBadge is an implementation of a Badge that represents a Badgr failure, as opposed to a failure in whatever backend system (for instance, GitHub) that Badgr has queried.

func NewErrBadge

func NewErrBadge(status interface{}) ErrBadge

NewErrBadge return an implementation of a Badge that represents a Badgr failure, as opposed to a failure in whatever backend system (for instance, GitHub) that Badgr has queried.

func (ErrBadge) Color

func (e ErrBadge) Color() Color

func (ErrBadge) Name

func (e ErrBadge) Name() string

func (ErrBadge) Status

func (e ErrBadge) Status() string

type Service

type Service interface {
	// CheckBadge serves a badge based on check suite status.
	CheckBadge(
		ctx context.Context,
		owner string,
		repo string,
		opts *CheckBadgeOptions,
	) (CheckBadge, error)
}

Service is an interface for components that can handle requests for a badge.

func NewService

func NewService() Service

NewService returns an implementation of the Service interface for handling requests for a badge.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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