models

package
v0.0.0-...-26736ab Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const KeyDirRepositories string = "/github/repositories/tracked"

KeyDirRepositories is the key used to store tracked GitHub repositories

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionOutput

type ActionOutput struct {
	// Text is the output string
	Text string `json:"text"`

	// Error indicates if the text is error output
	Error bool
}

ActionOutput holds a line of output from an action. Indicates if the line is an error or normal.

type ActionStage

type ActionStage string

ActionStage indicates how the action is currently existing

const (
	// Queued indicates an action is set to be run, but hasn't started yet.
	Queued ActionStage = "queued"

	// Running indicates an action is running.
	Running ActionStage = "running"

	// Done indicates an action has finished running.
	Done ActionStage = "done"

	// ErrDone indicates that an action finished running because it
	// encountered an error.
	ErrDone ActionStage = "err_done"
)

type ActionState

type ActionState struct {
	// Stage indicates how the action is currently existing
	Stage ActionStage `json:"stage"`

	// Output holds the raw action output
	Output []ActionOutput `json:"output"`
}

ActionState holds the state of an action.

func NewActionState

func NewActionState() *ActionState

NewActionState creates a new ActionState with the Stage field set to Queued

func (*ActionState) AddOutput

func (s *ActionState) AddOutput(txt string)

AddOutput saves a line of output to the state

func (ActionState) Done

func (s ActionState) Done() bool

Done indicates if a state's Stage is in a done state

func (*ActionState) SetError

func (s *ActionState) SetError(errStr string)

SetError saves an error to in Output and sets the Stage to ErrDone

func (*ActionState) SetErrorf

func (s *ActionState) SetErrorf(errFormat string, v ...interface{})

SetErrorf acts like SetError but it provides string formatting functionality via fmt.Sprintf

type DockerActionConfig

type DockerActionConfig struct {
	// Directory indicates the directory where the Dockerfile to build
	// is located.
	Directory string `json:"directory"`

	// Tag indicates the value of the Docker image tag to apply.
	Tag string `json:"tag"`
}

DockerActionConfig holds the config for a Docker action.

type HelmActionConfig

type HelmActionConfig struct {
	// Chart is the local path to a Helm chart to deploy, or if the
	// Repository field is set it holds the name of a Helm chart to deploy.
	Chart string `json:"chart"`

	// Repository is the name of the repository where the Chart is located.
	// If empty the Chart field is treated as a local path to a Helm chart.
	Repository string `json:"repository"`
}

HelmActionConfig holds the config for a Helm action.

type Job

type Job struct {
	// ID identifies the job.
	ID JobID `json:"id"`

	// Target identifies the Git event which triggered the job.
	Target JobTarget `json:"target"`

	// WorkingDir is the directory that the repository source is located.
	WorkingDir string `json:"working_dir"`

	// State holds the job state.
	State JobState `json:"state"`

	// Config holds the job configuration. Nil if it hasn't been
	// loaded yet.
	Config *JobConfig `json:"config"`
}

Job holds information about a job.

func NewJob

func NewJob(repoID RepositoryID, target JobTarget) *Job

NewJob creates a new Job. Intializes all JobState.Stage fields to Queued.

func (*Job) Create

func (j *Job) Create(ctx context.Context, etcdKV etcd.KeysAPI) error

Create stores a new job. Finds the next job ID and saves it in the Job.ID field. Does not work if the job has already been stored

func (Job) Get

func (j Job) Get(ctx context.Context, etcdKV etcd.KeysAPI) error

Get retrieves a job from Etcd. The ID, Metadata.Owner, and Metadata.Name fields must be set for method to work properly.

func (Job) Set

func (j Job) Set(ctx context.Context, etcdKV etcd.KeysAPI) error

Set stores a job in Etcd

type JobConfig

type JobConfig struct {
	// Units holds the config for the units in a file. Keys are
	// UnitConfig.ID values.
	Units map[string]UnitConfig `json:"units"`
}

JobConfig holds information about the config of a job. Data sourced from a file in the Git repository root.

func NewJobConfig

func NewJobConfig() JobConfig

NewJobConfig creates a new JobConfig

type JobID

type JobID struct {
	// RepositoryID is the GitHub repository.
	RepositoryID RepositoryID `json:"repository_id"`

	// ID is the unique identifying number of the job.
	ID int64 `json:"id"`
}

JobID identifies a job.

type JobState

type JobState struct {
	// PrepareState is the state of the prepare action
	PrepareState *ActionState `json:"prepare_state"`

	// CleanupState is the state of the cleanup action
	CleanupState *ActionState `json:"cleanup_state"`

	// Units holds unit states. Keys are UnitState.ID values.
	Units map[string]UnitState `json:"units"`
}

JobState holds information about the current run status of a Job.

func (JobState) Done

func (s JobState) Done() bool

Done indicates if the Job has finished executing

type JobTarget

type JobTarget struct {
	// Branch is the Git branch.
	Branch string `json:"branch"`

	// Commit is the Git Sha.
	Commit string `json:"commit"`
}

JobTarget identifies the Git event which triggered the job.

type Repository

type Repository struct {
	// ID holds information used to identify the repository
	ID RepositoryID `json:"id"`

	// WebHookID holds the ID of the created GitHub repository web hook
	WebHookID int64 `json:"web_hook_id"`
}

Repository contains tracked GitHub repository information

func GetAllRepositories

func GetAllRepositories(ctx context.Context,
	etcdKV etcd.KeysAPI) ([]Repository, error)

GetAllRepositories retrieves all repositories

func (Repository) Create

func (r Repository) Create(ctx context.Context, etcdKV etcd.KeysAPI) error

Creates creates the directory structure for a Repository in Etcd and Sets a directory. Does not work if Repository was previously saved.

func (Repository) Delete

func (r Repository) Delete(ctx context.Context, etcdKV etcd.KeysAPI) error

Delete removes a repository and all of its jobs from Etcd

func (Repository) Exists

func (r Repository) Exists(ctx context.Context,
	etcdKV etcd.KeysAPI) (bool, error)

Exists checks to see if repository exists in Etcd

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, etcdKV etcd.KeysAPI) error

Get retrieves a repository from Etcd. The `Owner` and `Name` fields must be set for this method to work properly

func (Repository) Set

func (r Repository) Set(ctx context.Context, etcdKV etcd.KeysAPI) error

Set stores a repository in Etcd

type RepositoryID

type RepositoryID struct {
	// Owner holds the GitHub username of the repository owner
	Owner string `json:"owner"`

	// Name holds the name of the repository
	Name string `json:"name"`
}

RepositoryID holds information required to identify a GitHub repository

type UnitConfig

type UnitConfig struct {
	// ID holds the name of the unit
	ID string `json:"id"`

	// Docker holds Docker unit config. Nil if not present.
	Docker *DockerActionConfig `json:"docker"`

	// Helm holds Helm unit config. Nil if not present.
	Helm *HelmActionConfig `json:"helm"`
}

UnitConfig holds the config for a unit

type UnitState

type UnitState struct {
	// ID is the name of a unit
	ID string `json:"id"`

	// DockerState is the state of the Docker action. Nil if the unit does
	// not contain a Docker action.
	DockerState *ActionState `json:"docker_state"`

	// HelmState is the state of the Helm action. Nil if the unit does not
	// contain a Helm action.
	HelmState *ActionState `json:"helm_state"`
}

UnitState holds the state of a unit.

Jump to

Keyboard shortcuts

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