types

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &Config{ID: 1, Mode: Schedule, Options: DefaultOptions}
View Source
var DefaultOptions = Options{CloseTime: defaultCloseTime}

Functions

func CustomizeJobs

func CustomizeJobs(phaseType PhaseType, jobs []string)

Should only be used for tests or fake implementation.

func DoesCommitNeedTicket

func DoesCommitNeedTicket(commit *Commit, commitsOnTickets map[string]struct{}) bool

func JobsForPhase

func JobsForPhase(phaseType PhaseType) []string

func ShortSHA

func ShortSHA(sha string) string

Types

type Auth

type Auth struct {
	Token     string `orm:"pk;size(36)" json:"token"` // Internal token token.
	CreatedAt Time   `orm:"auto_now_add" json:"created_at"`
	User      *User  `orm:"rel(fk)" json:"user"`
	CodeToken string `orm:"null;size(40)" json:"code_token"` // API Token for Code Service. Can be null if auth doesn't support it.
}

type Clock

type Clock struct {
	Hour   int `json:"hour"`
	Minute int `json:"minute"`
}

type Commit

type Commit struct {
	ID          uint64 `orm:"pk;auto;column(id)" json:"id,string"`
	CreatedAt   Time   `orm:"auto_now_add;null" json:"created_at"`
	SHA         string `orm:"unique;column(sha)" json:"sha"`
	Message     string `json:"message"`
	Branch      string `json:"branch" orm:"-"`
	AuthorName  string `json:"author_name"`
	AuthorEmail string `json:"author_email"`
	URL         string `orm:"column(url)" json:"url"`
}

func (*Commit) DoesCommitNeedStagingNotification

func (commit *Commit) DoesCommitNeedStagingNotification() bool

Should this commit trigger slack notifications to its author regarding staging.

func (*Commit) IsNeedsStaging

func (commit *Commit) IsNeedsStaging() bool

func (*Commit) IsNoStagingVerification

func (commit *Commit) IsNoStagingVerification() bool

func (*Commit) IsNoVerify

func (commit *Commit) IsNoVerify() bool

func (*Commit) ShortSHA

func (commit *Commit) ShortSHA() string

type CommitsByID

type CommitsByID []*Commit

func (CommitsByID) Len

func (s CommitsByID) Len() int

func (CommitsByID) Less

func (s CommitsByID) Less(i, j int) bool

func (CommitsByID) Swap

func (s CommitsByID) Swap(i, j int)

type Config

type Config struct {
	ID uint64 `orm:"pk;auto;column(id)" json:"-"`

	// Current mode
	Mode Mode `json:"mode"`

	// JSON string for configuration, like the CloseTime config.
	// See: shared/types/options.go.
	Options Options `json:"options"`
}

Special settings table which should only have one row.

type Interval

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

func (Interval) WithDate

func (interval Interval) WithDate(year int, month time.Month, day int) Interval

type Intervals

type Intervals []Interval

func (Intervals) Len

func (intervals Intervals) Len() int

func (Intervals) Less

func (intervals Intervals) Less(i, j int) bool

func (Intervals) Swap

func (intervals Intervals) Swap(i, j int)

type Job

type Job struct {
	ID          uint64    `orm:"pk;auto;column(id)" json:"id,string"`
	StartedAt   Time      `orm:"null" json:"started_at"`
	CompletedAt Time      `orm:"null" json:"completed_at"`
	URL         *string   `orm:"column(url);null" json:"url"` // Link to this job
	Name        string    `json:"name"`                       // e.g. Delivery, Test, Build
	Result      JobResult `json:"result"`                     // Exit status
	Metadata    string    `orm:"null" json:"metadata"`        // JSON data
	Phase       *Phase    `orm:"rel(fk)" json:"-"`
}

func (*Job) DatadogTags

func (job *Job) DatadogTags() []string

type JobResult

type JobResult int
const (
	Ok JobResult = iota
	Error
)

func (JobResult) IsValid

func (j JobResult) IsValid() bool

func (JobResult) String

func (j JobResult) String() string

type Jobs

type Jobs []*Job

func (Jobs) CompletedNames

func (jobs Jobs) CompletedNames() []string

type JobsByID

type JobsByID []*Job

func (JobsByID) Len

func (s JobsByID) Len() int

func (JobsByID) Less

func (s JobsByID) Less(i, j int) bool

func (JobsByID) Swap

func (s JobsByID) Swap(i, j int)

type Metadata

type Metadata struct {
	Namespace string `orm:"pk;unique" json:"key"`
	Data      string `orm:"type(jsonb)" json:"data"`
}

type Mode

type Mode int
const (
	Schedule Mode = iota
	Manual
)

func ModeFromString

func ModeFromString(mode string) (Mode, error)

func (Mode) IsManualMode

func (m Mode) IsManualMode() bool

func (Mode) IsScheduleMode

func (m Mode) IsScheduleMode() bool

func (Mode) String

func (m Mode) String() string

type Moment

type Moment interface {
	Weekday() time.Weekday
	Clock() (hour, minute, second int)
}

type Options

type Options struct {
	// CloseTime is when trains should be automatically closed.
	// This is defined as an array of TimeIntervals.
	// Example: M-F 9-5.
	//  []TimeInterval{
	//      TimeInterval{
	//          Every: []time.Weekday{
	//              time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
	//          StartTime: Clock{Hour: 9, Minute: 0},
	//          EndTime: Clock{Hour: 17, Minute: 0},
	//      },
	//  }
	CloseTime            RepeatingTimeIntervals `json:"close_time"`
	ValidationError      error                  `orm:"-" json:"-"`
	InvalidOptionsString string                 `orm:"-" json:"-"`
}

func (Options) CloseTimeOverlap

func (o Options) CloseTimeOverlap(start time.Time, end time.Time) time.Duration

func (Options) FieldType

func (o Options) FieldType() int

func (*Options) FromString

func (o *Options) FromString(optionsString string) error

func (Options) InCloseTime

func (o Options) InCloseTime() bool

func (Options) RawValue

func (o Options) RawValue() interface{}

func (*Options) SetRaw

func (o *Options) SetRaw(raw interface{}) error

func (Options) String

func (o Options) String() string

Implement beego Fielder interface to handle serialization and deserialization.

type Phase

type Phase struct {
	ID          uint64    `orm:"pk;auto;column(id)" json:"id,string"`
	StartedAt   Time      `orm:"null" json:"started_at"`
	CompletedAt Time      `orm:"null" json:"completed_at"`
	Type        PhaseType `json:"type"` // delivery|verification|deploy
	Error       string    `orm:"null" json:"error"`
	Jobs        Jobs      `orm:"reverse(many)" json:"jobs"`

	// Computed fields
	PhaseGroup *PhaseGroup `orm:"-" json:"-"`
	Train      *Train      `orm:"-" json:"-"`
}

func (*Phase) Before

func (phase *Phase) Before(phaseType PhaseType) bool

func (*Phase) DatadogTags

func (phase *Phase) DatadogTags() []string

func (*Phase) EarlierPhasesComplete

func (phase *Phase) EarlierPhasesComplete() bool

func (*Phase) IsComplete

func (phase *Phase) IsComplete() bool

func (*Phase) IsInActivePhaseGroup

func (phase *Phase) IsInActivePhaseGroup() bool

type PhaseGroup

type PhaseGroup struct {
	ID           uint64 `orm:"pk;auto;column(id)" json:"id,string"`
	HeadSHA      string `orm:"column(head_sha)" json:"head_sha"`
	Delivery     *Phase `orm:"rel(fk)" json:"delivery"`
	Verification *Phase `orm:"rel(fk)" json:"verification"`
	Deploy       *Phase `orm:"rel(fk)" json:"deploy"`

	Train *Train `orm:"rel(fk);null" json:"-"`
}

func (*PhaseGroup) AddNewPhase

func (phaseGroup *PhaseGroup) AddNewPhase(phaseType PhaseType, train *Train) *Phase

func (*PhaseGroup) GitReference

func (phaseGroup *PhaseGroup) GitReference() string

func (*PhaseGroup) IsActivePhaseGroup

func (phaseGroup *PhaseGroup) IsActivePhaseGroup() bool

func (*PhaseGroup) Phases

func (phaseGroup *PhaseGroup) Phases() []*Phase

func (*PhaseGroup) SetReferences

func (phaseGroup *PhaseGroup) SetReferences(train *Train)

type PhaseType

type PhaseType int
const (
	Delivery PhaseType = iota
	Verification
	Deploy
)

func PhaseTypeFromString

func PhaseTypeFromString(phaseType string) (PhaseType, error)

func (PhaseType) String

func (e PhaseType) String() string

type RepeatingTimeInterval

type RepeatingTimeInterval struct {
	Every     []time.Weekday `json:"every"`
	StartTime Clock          `json:"start_time"`
	EndTime   Clock          `json:"end_time"`
}

func (RepeatingTimeInterval) Includes

func (interval RepeatingTimeInterval) Includes(testTime Moment) bool

Includes checks if the given time is in this RepeatingTimeInterval.

type RepeatingTimeIntervals

type RepeatingTimeIntervals []RepeatingTimeInterval

func (RepeatingTimeIntervals) TotalOverlap

func (repeatingTimeIntervals RepeatingTimeIntervals) TotalOverlap(start time.Time, end time.Time) time.Duration

TotalOverlap calculates the total overlap duration between the specified start and end times.

type Search struct {
	Params  map[string]string `json:"params"`
	Results interface{}       `json:"results"`
}

type Ticket

type Ticket struct {
	ID            uint64    `orm:"pk;auto;column(id)" json:"id,string"`
	Key           string    `json:"key"`
	Summary       string    `json:"summary"`
	AssigneeEmail string    `json:"assignee_email"`
	AssigneeName  string    `json:"assignee_name"`
	URL           string    `orm:"column(url)" json:"url"`
	CreatedAt     Time      `orm:"auto_now_add" json:"created_at"`
	ClosedAt      Time      `orm:"null" json:"closed_at"`
	DeletedAt     Time      `orm:"null" json:"deleted_at"`
	Commits       []*Commit `orm:"rel(m2m)" json:"commits"`
	Train         *Train    `orm:"rel(fk)" json:"-"`
}

func (*Ticket) IsComplete

func (ticket *Ticket) IsComplete() bool

func (*Ticket) TableUnique

func (_ *Ticket) TableUnique() [][]string

type TicketsByID

type TicketsByID []*Ticket

func (TicketsByID) Len

func (s TicketsByID) Len() int

func (TicketsByID) Less

func (s TicketsByID) Less(i, j int) bool

func (TicketsByID) Swap

func (s TicketsByID) Swap(i, j int)

type Time

type Time struct {
	Value time.Time
}

Custom type for JSON formatting. Implements beego 'fielder' interface.

func (Time) FieldType

func (t Time) FieldType() int

func (Time) Get

func (t Time) Get() *time.Time

func (Time) HasValue

func (t Time) HasValue() bool

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) RawValue

func (t Time) RawValue() interface{}

func (*Time) SetRaw

func (t *Time) SetRaw(value interface{}) error

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

type TimeInterval

type TimeInterval interface {
	Includes(time.Time) bool
}

type Train

type Train struct {
	ID               uint64        `orm:"pk;auto;column(id)" json:"id,string"`
	Engineer         *User         `orm:"rel(fk);null" json:"engineer"`
	CreatedAt        Time          `orm:"auto_now_add" json:"created_at"`
	DeployedAt       Time          `orm:"null" json:"deployed_at"`
	CancelledAt      Time          `orm:"null" json:"cancelled_at"`
	Closed           bool          `json:"closed"`
	ScheduleOverride bool          `json:"schedule_override"`
	Blocked          bool          `json:"blocked"`
	BlockedReason    *string       `orm:"null" json:"blocked_reason"`
	Branch           string        `json:"branch"`
	HeadSHA          string        `orm:"column(head_sha)" json:"head_sha"`
	TailSHA          string        `orm:"column(tail_sha)" json:"tail_sha"`
	Commits          []*Commit     `orm:"rel(m2m)" json:"commits"`      // Commits on this train.
	Tickets          []*Ticket     `orm:"reverse(many)" json:"tickets"` // Who's got a ticket to ride?
	ActivePhases     *PhaseGroup   `orm:"rel(fk)" json:"active_phases"`
	AllPhaseGroups   []*PhaseGroup `orm:"reverse(many)" json:"all_phase_groups"`

	// Computed fields
	ActivePhase         PhaseType `orm:"-" json:"active_phase"`
	LastDeliveredSHA    *string   `orm:"-" json:"last_delivered_sha"` // SHA for last successful delivery.
	PreviousID          *uint64   `orm:"-" json:"previous_id,string"`
	NextID              *uint64   `orm:"-" json:"next_id,string"`
	NotDeployableReason *string   `orm:"-" json:"not_deployable_reason"`
	Done                bool      `orm:"-" json:"done"`
	PreviousTrainDone   bool      `orm:"-" json:"previous_train_done"`
	CanRollback         bool      `orm:"-" json:"can_rollback"`
}

func (*Train) CommitsBetween

func (train *Train) CommitsBetween(headSHA string, tailSHA string) []*Commit

Return includes head but not tail.

func (*Train) CommitsSince

func (train *Train) CommitsSince(headSHA string) []*Commit

Return includes head.

func (*Train) DatadogTags

func (train *Train) DatadogTags() []string

func (*Train) GetNotDeployableReason

func (train *Train) GetNotDeployableReason() *string

func (*Train) GitReference

func (train *Train) GitReference() string

func (*Train) IsCancelled

func (train *Train) IsCancelled() bool

func (*Train) IsDeployable

func (train *Train) IsDeployable() bool

func (*Train) IsDeployed

func (train *Train) IsDeployed() bool

func (*Train) IsDeploying

func (train *Train) IsDeploying() bool

func (*Train) IsDone

func (train *Train) IsDone() bool

func (*Train) NewCommitsNeedingTickets

func (train *Train) NewCommitsNeedingTickets(headSHA string) []*Commit

func (*Train) Phase

func (train *Train) Phase(phaseType PhaseType) *Phase

func (*Train) SendCommitCountMetrics

func (train *Train) SendCommitCountMetrics()

func (*Train) SetActivePhase

func (train *Train) SetActivePhase()

type User

type User struct {
	ID        uint64 `orm:"pk;auto;column(id)" json:"id,string"`
	CreatedAt Time   `orm:"auto_now_add" json:"created_at"`
	Name      string `json:"name"`
	Email     string `orm:"unique" json:"email"`
	AvatarURL string `orm:"column(avatar_url)" json:"avatar_url"`
	Token     string `orm:"-" json:"-"`
	IsAdmin   bool   `orm:"-" json:"is_admin"`
}

Jump to

Keyboard shortcuts

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