ghstatus

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ghstatus contains the Github status client.

This package contains the Github Status client and a few convience methods for rendering them. The client parses the raw JSON from the Github Status API, which is documented (incompletely) here: https://www.githubstatus.com/api

This is a relatively simple API. Retries were added by using a retryable HTTP client, but no other features pertaining to API rate limiting or caching have been added. As of this writing, no API rate limits are documented in the API, so it is currently assumed there either is no rate limit or it is very high.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestServerAndClient

func NewTestServerAndClient(t *testing.T) (*TestServer, Client)

NewTestServerAndClient creates a new test server with the client pointing to it.

Types

type Client

type Client interface {
	// Summary returns the summary.
	Summary(ctx context.Context) (SummaryResponse, error)

	// Status returns the status.
	Status(ctx context.Context) (StatusResponse, error)

	// Components returns the components.
	Components(ctx context.Context) (ComponentsResponse, error)

	// UnresolvedIncidents returns the unresolved incidents.
	UnresolvedIncidents(ctx context.Context) (IncidentsResponse, error)

	// AllIncidents returns all incidents.
	AllIncidents(ctx context.Context) (IncidentsResponse, error)

	// UpcomingScheduledMaintenances returns all upcoming scheduled maintenances.
	UpcomingScheduledMaintenances(ctx context.Context) (ScheduledMaintenancesResponse, error)

	// ActiveScheduledMaintenances returns all active scheduled maintenances.
	ActiveScheduledMaintenances(ctx context.Context) (ScheduledMaintenancesResponse, error)

	// AllScheduledMaintenances returns all scheduled maintenances.
	AllScheduledMaintenances(ctx context.Context) (ScheduledMaintenancesResponse, error)
}

Client is the github status client.

func NewClient

func NewClient(log *zap.Logger) Client

NewClient creates a new github status client.

type Component

type Component struct {
	// CreatedAt is when the component was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// Description is the description of the component.
	Description string `json:"description" yaml:"description"`

	// Group is is whether this component is in a group.
	Group bool `json:"group" yaml:"group"`

	// GroupID is the ID of the group this component belongs to.
	GroupID string `json:"group_id" yaml:"group_id"`

	// Name is the name of the component.
	Name string `json:"name" yaml:"name"`

	// OnlyShowIfDegraded designates whether this should only be shown if the component is degraded.
	OnlyShowIfDegraded bool `json:"only_show_if_degraded" yaml:"only_show_if_degraded"`

	// PageID is the page ID this component belongs to.
	PageID string `json:"page_id" yaml:"page_id"`

	// Position is the position of the component on the page.
	Position int `json:"position" yaml:"position"`

	// Showcase is whether the component should be showcased.
	Showcase bool `json:"showcase" yaml:"showcase"`

	// StartDate is the start date for the component.
	StartDate string `json:"start_date" yaml:"start_date"`

	// Status is the status of the component.
	Status ComponentStatus `json:"status" yaml:"status"`

	// UpdatedAt is when the component was last updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

Component is a github component along with its current status.

type ComponentStatus

type ComponentStatus string

ComponentStatus is the current status of a github component.

const (
	Operational         ComponentStatus = "operational"
	DegradedPerformance ComponentStatus = "degraded_performance"
	PartialOutage       ComponentStatus = "partial_outage"
	MajorOutage         ComponentStatus = "major_outage"
)

type ComponentsResponse

type ComponentsResponse struct {
	// Page is page metadata.
	Page Page `json:"page"`

	// Components are a list of components.
	Components []Component `json:"components"`
}

ComponentsResponse is the response from the components endpoint.

type Incident

type Incident struct {
	// CreatedAt is when the incident was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// ID is the identifier of the incident.
	ID string `json:"id" yaml:"id"`

	// Impact is the impact of the incident.
	Impact Indicator `json:"impact" yaml:"impact"`

	// IncidentUpdates are the updates for an incident.
	IncidentUpdates []IncidentUpdate `json:"incident_updates" yaml:"incident_updates"`

	// MonitoringAt is the time when the incident is being monitored.
	MonitoringAt time.Time `json:"monitoring_at" yaml:"monitoring_at"`

	// Name is the name of the incident.
	Name string `json:"name" yaml:"name"`

	// PageID is the ID of this page.
	PageID string `json:"page_id" yaml:"page_id"`

	// ResolvedAt is when the incident was resolved.
	ResolvedAt time.Time `json:"resolved_at" yaml:"resolved_at"`

	// ShortLink is the shortlink to this incident.
	Shortlink string `json:"shortlink" yaml:"shortlink"`

	// Status is the status of the incident.
	Status IncidentStatus `json:"status" yaml:"status"`

	// UpdatedAt is when the incident was last updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

Incident is an ongoing incident.

type IncidentStatus

type IncidentStatus string

IncidentStatus is the status of an incident.

const (
	Investigating IncidentStatus = "investigating"
	Identified    IncidentStatus = "identified"
	Monitoring    IncidentStatus = "monitoring"
	Resolved      IncidentStatus = "resolved"
	Postmorten    IncidentStatus = "postmortem"
)

type IncidentUpdate

type IncidentUpdate struct {
	// Body is the plaintext description of the update.
	Body string `json:"body" yaml:"body"`

	// CreatedAt is when the update was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// DisplayAt is when the update should be displayed.
	DisplayAt time.Time `json:"display_at" yaml:"display_at"`

	// ID is the identifier of the update.
	ID string `json:"id" yaml:"id"`

	// IncidentID is the identifier of the associated incident.
	IncidentID string `json:"incident_id" yaml:"incident_id"`

	// Status is the status of the incident associated with this update.
	Status IncidentStatus `json:"status" yaml:"status"`

	// UpdatedAt is when this update entry was last updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

IncidentUpdate is an update to an incident.

type IncidentsResponse

type IncidentsResponse struct {
	// Page is page metadata.
	Page Page `json:"page"`

	// Incidents is a list of incidents.
	Incidents []Incident `json:"incidents"`
}

IncidentsResponse is the response from one of the incident endpoints.

type Indicator

type Indicator string

Indicator is an indicator of the status of an incident or the overall status.

const (
	None     Indicator = "none"
	Minor    Indicator = "minor"
	Major    Indicator = "major"
	Critical Indicator = "critical"
)

type Page

type Page struct {
	// ID is the ID of the page.
	ID string `json:"id" yaml:"id"`

	// Name is the name of the page.
	Name string `json:"name" yaml:"name"`

	// URL is the URL of the page retrieved.
	URL string `json:"url" yaml:"url"`

	// UpdatedAt is when the page was last updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

Page describes metadata for the status page.

type ScheduledMaintenance

type ScheduledMaintenance struct {
	// CreatedAt is when the scheduled maintenance was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// ID is the identifier of the scheduled maintenance.
	ID string `json:"id" yaml:"id"`

	// Impact is the impact of the scheduled maintenance.
	Impact Indicator `json:"impact" yaml:"impact"`

	// IncidentUpdates are updates to the scheduled maintenance.
	IncidentUpdates []IncidentUpdate `json:"incident_updates" yaml:"incident_updates"`

	// MonitoringAt is the time when the scheduled maintenance is being monitored.
	MonitoringAt time.Time `json:"monitoring_at" yaml:"monitoring_at"`

	// Name is the name of the scheduled maintenance.
	Name string `json:"name" yaml:"name"`

	// PageID is the ID of this page.
	PageID string `json:"page_id" yaml:"page_id"`

	// ResolvedAt is the time when the scheduled maintenance is resolved.
	ResolvedAt time.Time `json:"resolved_at" yaml:"resolved_at"`

	// ScheduledFor is when the scheduled maintenance is scheduled.
	ScheduledFor time.Time `json:"scheduled_for" yaml:"scheduled_for"`

	// ScheduledUntil is when the scheduled maintenance is supposed to end.
	ScheduledUntil time.Time `json:"scheduled_until" yaml:"scheduled_until"`

	// Status is the status of the scheduled maintenance.
	Status ScheduledMaintenanceStatus `json:"status" yaml:"status"`

	// UpdatedAt is the time when the scheduled maintenance is updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

ScheduledMaintenance is a scheduled maintenance.

type ScheduledMaintenanceStatus

type ScheduledMaintenanceStatus string

ScheduledMaintenanceStatus is the status of a scheduled maintenance.

const (
	Scheduled  ScheduledMaintenanceStatus = "scheduled"
	InProgress ScheduledMaintenanceStatus = "in_progress"
	Verifying  ScheduledMaintenanceStatus = "verifying"
	Completed  ScheduledMaintenanceStatus = "completed"
)

type ScheduledMaintenancesResponse

type ScheduledMaintenancesResponse struct {
	// Page is page metadata.
	Page Page `json:"page"`

	// ScheduledMaintenances is a list of scheduled maintenances.
	ScheduledMaintenances []ScheduledMaintenance `json:"scheduled_maintenances"`
}

ScheduledMaintenancesResponse is the response from one of the scheduled maintenance endpoints.

type Status

type Status struct {
	// Description is the description of the overall status.
	Description string `json:"description" yaml:"description"`

	// Indicator is the indicator of the overall status.
	Indicator Indicator `json:"indicator" yaml:"indicator"`
}

Status is an overall description of the current github status.

type StatusResponse

type StatusResponse struct {
	// Page is page metadata.
	Page Page `json:"page"`

	// Status is the current github status.
	Status Status `json:"status"`
}

StatusResponse is the response from the status endpoint.

type SummaryResponse

type SummaryResponse struct {
	// Page is page metadata.
	Page Page `json:"page"`

	// Status is the current github status.
	Status Status `json:"status"`

	// Components are a list of components.
	Components []Component `json:"components"`

	// Incidents is a list of incidents.
	Incidents []Incident `json:"incidents"`

	// ScheduledMaintenances is a list of scheduled maintenances.
	ScheduledMaintenances []ScheduledMaintenance `json:"scheduled_maintenances"`
}

SummaryResponse is a response from the summary endpoint.

type TestServer

type TestServer struct {
	Summary                       []byte
	Status                        []byte
	Components                    []byte
	UnresolvedIncidents           []byte
	AllIncidents                  []byte
	UpcomingScheduledMaintenances []byte
	ActiveScheduledMaintenances   []byte
	AllScheduledMaintenances      []byte
}

TestServer is a test server with fixed responses that can be modified by callers.

func (*TestServer) SetSummary

func (ts *TestServer) SetSummary(t *testing.T, resp SummaryResponse)

SetSummary will set the summary response by encoding it into bytes.

func (*TestServer) SetSummaryRaw

func (ts *TestServer) SetSummaryRaw(resp []byte)

SetSummaryRaw will set the summary response to be the given raw bytes.

Directories

Path Synopsis
Package render contains functions for displaying the status responses in various formats.
Package render contains functions for displaying the status responses in various formats.

Jump to

Keyboard shortcuts

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