events

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const ProjectConfigFile = "atlantis.yaml"

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyExecutor

type ApplyExecutor struct {
	VCSClient         vcs.ClientProxy
	Terraform         *terraform.Client
	RequireApproval   bool
	Run               *run.Run
	Workspace         Workspace
	ProjectPreExecute *ProjectPreExecute
	Webhooks          webhooks.Sender
}

func (*ApplyExecutor) Execute

func (a *ApplyExecutor) Execute(ctx *CommandContext) CommandResponse

type Command

type Command struct {
	Name        CommandName
	Environment string
	Verbose     bool
	Flags       []string
}

type CommandContext

type CommandContext struct {
	BaseRepo models.Repo
	HeadRepo models.Repo
	Pull     models.PullRequest
	User     models.User
	Command  *Command
	Log      *logging.SimpleLogger
	VCSHost  vcs.Host
}

type CommandHandler

type CommandHandler struct {
	PlanExecutor             Executor
	ApplyExecutor            Executor
	HelpExecutor             Executor
	LockURLGenerator         LockURLGenerator
	VCSClient                vcs.ClientProxy
	GithubPullGetter         GithubPullGetter
	GitlabMergeRequestGetter GitlabMergeRequestGetter
	CommitStatusUpdater      CommitStatusUpdater
	EventParser              EventParsing
	EnvLocker                EnvLocker
	MarkdownRenderer         *MarkdownRenderer
	Logger                   logging.SimpleLogging
}

CommandHandler is the first step when processing a comment command.

func (*CommandHandler) ExecuteCommand

func (c *CommandHandler) ExecuteCommand(baseRepo models.Repo, headRepo models.Repo, user models.User, pullNum int, cmd *Command, vcsHost vcs.Host)

ExecuteCommand executes the command

func (*CommandHandler) SetLockURL

func (c *CommandHandler) SetLockURL(f func(id string) (url string))

type CommandName

type CommandName int
const (
	Apply CommandName = iota
	Plan
	Help
)

func (CommandName) String

func (c CommandName) String() string

type CommandResponse

type CommandResponse struct {
	Error          error
	Failure        string
	ProjectResults []ProjectResult
}

type CommandRunner

type CommandRunner interface {
	ExecuteCommand(baseRepo models.Repo, headRepo models.Repo, user models.User, pullNum int, cmd *Command, vcsHost vcs.Host)
}

type CommitStatusUpdater added in v0.2.0

type CommitStatusUpdater interface {
	Update(repo models.Repo, pull models.PullRequest, status vcs.CommitStatus, cmd *Command, host vcs.Host) error
	UpdateProjectResult(ctx *CommandContext, res CommandResponse) error
}

type CommonData

type CommonData struct {
	Command string
	Verbose bool
	Log     string
}

type DefaultCommitStatusUpdater added in v0.2.0

type DefaultCommitStatusUpdater struct {
	Client vcs.ClientProxy
}

func (*DefaultCommitStatusUpdater) Update added in v0.2.0

func (d *DefaultCommitStatusUpdater) Update(repo models.Repo, pull models.PullRequest, status vcs.CommitStatus, cmd *Command, host vcs.Host) error

func (*DefaultCommitStatusUpdater) UpdateProjectResult added in v0.2.0

func (d *DefaultCommitStatusUpdater) UpdateProjectResult(ctx *CommandContext, res CommandResponse) error

type EnvLock

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

EnvLock is used to prevent multiple runs and commands from occurring at the same time for a single repo, pull, and environment

func NewEnvLock

func NewEnvLock() *EnvLock

func (*EnvLock) TryLock

func (c *EnvLock) TryLock(repoFullName string, env string, pullNum int) bool

TryLock returns true if you acquired the lock and false if someone else already has the lock

func (*EnvLock) Unlock

func (c *EnvLock) Unlock(repoFullName, env string, pullNum int)

Unlock unlocks the repo and environment

type EnvLocker

type EnvLocker interface {
	TryLock(repoFullName string, env string, pullNum int) bool
	Unlock(repoFullName, env string, pullNum int)
}

type ErrData

type ErrData struct {
	Error string
	CommonData
}

type EventParser

type EventParser struct {
	GithubUser  string
	GithubToken string
	GitlabUser  string
	GitlabToken string
}

func (*EventParser) DetermineCommand

func (e *EventParser) DetermineCommand(comment string, vcsHost vcs.Host) (*Command, error)

DetermineCommand parses the comment as an atlantis command. If it succeeds, it returns the command. Otherwise it returns error.

func (*EventParser) ParseGithubIssueCommentEvent added in v0.2.0

func (e *EventParser) ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (baseRepo models.Repo, user models.User, pullNum int, err error)

func (*EventParser) ParseGithubPull added in v0.2.0

func (e *EventParser) ParseGithubPull(pull *github.PullRequest) (models.PullRequest, models.Repo, error)

func (*EventParser) ParseGithubRepo added in v0.2.0

func (e *EventParser) ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error)

func (*EventParser) ParseGitlabMergeCommentEvent added in v0.2.0

func (e *EventParser) ParseGitlabMergeCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User)

ParseGitlabMergeCommentEvent creates Atlantis models out of a GitLab event.

func (*EventParser) ParseGitlabMergeEvent added in v0.2.0

func (e *EventParser) ParseGitlabMergeEvent(event gitlab.MergeEvent) (models.PullRequest, models.Repo)

func (*EventParser) ParseGitlabMergeRequest added in v0.2.0

func (e *EventParser) ParseGitlabMergeRequest(mr *gitlab.MergeRequest) models.PullRequest

type EventParsing

type EventParsing interface {
	DetermineCommand(comment string, vcsHost vcs.Host) (*Command, error)
	ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (baseRepo models.Repo, user models.User, pullNum int, err error)
	ParseGithubPull(pull *github.PullRequest) (models.PullRequest, models.Repo, error)
	ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error)
	ParseGitlabMergeEvent(event gitlab.MergeEvent) (models.PullRequest, models.Repo)
	ParseGitlabMergeCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User)
	ParseGitlabMergeRequest(mr *gitlab.MergeRequest) models.PullRequest
}

type Executor

type Executor interface {
	Execute(ctx *CommandContext) CommandResponse
}

type FailureData

type FailureData struct {
	Failure string
	CommonData
}

type FileWorkspace

type FileWorkspace struct {
	DataDir string
}

func (*FileWorkspace) Clone

func (w *FileWorkspace) Clone(
	log *logging.SimpleLogger,
	baseRepo models.Repo,
	headRepo models.Repo,
	p models.PullRequest,
	env string) (string, error)

Clone git clones headRepo, checks out the branch and then returns the absolute path to the root of the cloned repo.

func (*FileWorkspace) Delete

func (w *FileWorkspace) Delete(r models.Repo, p models.PullRequest) error

Delete deletes the workspace for this repo and pull

func (*FileWorkspace) GetWorkspace

func (w *FileWorkspace) GetWorkspace(r models.Repo, p models.PullRequest, env string) (string, error)

type GithubPullGetter added in v0.2.0

type GithubPullGetter interface {
	GetPullRequest(repo models.Repo, pullNum int) (*github.PullRequest, error)
}

type GitlabMergeRequestGetter added in v0.2.0

type GitlabMergeRequestGetter interface {
	GetMergeRequest(repoFullName string, pullNum int) (*gitlab.MergeRequest, error)
}

type HelpExecutor

type HelpExecutor struct{}

func (*HelpExecutor) Execute

func (h *HelpExecutor) Execute(ctx *CommandContext) CommandResponse

type Hook

type Hook struct {
	Commands []string `yaml:"commands"`
}

Hook represents the commands that can be run at a certain stage.

type LockURLGenerator

type LockURLGenerator interface {
	// SetLockURL takes a function that given a lock id, will return a url
	// to view that lock
	SetLockURL(func(id string) (url string))
}

type MarkdownRenderer added in v0.2.0

type MarkdownRenderer struct{}

MarkdownRenderer renders responses as markdown

func (*MarkdownRenderer) Render added in v0.2.0

func (g *MarkdownRenderer) Render(res CommandResponse, cmdName CommandName, log string, verbose bool) string

Render formats the data into a string that can be commented back to GitHub. nolint: interfacer

type ModifiedProjectFinder

type ModifiedProjectFinder interface {
	// FindModified returns the list of projects that were modified based on
	// the modifiedFiles. The list will be de-duplicated.
	FindModified(log *logging.SimpleLogger, modifiedFiles []string, repoFullName string) []models.Project
}

type PlanExecutor

type PlanExecutor struct {
	VCSClient         vcs.ClientProxy
	Terraform         terraform.Runner
	Locker            locking.Locker
	LockURL           func(id string) (url string)
	Run               run.Runner
	Workspace         Workspace
	ProjectPreExecute ProjectPreExecutor
	ProjectFinder     ModifiedProjectFinder
}

PlanExecutor handles everything related to running terraform plan.

func (*PlanExecutor) Execute

func (p *PlanExecutor) Execute(ctx *CommandContext) CommandResponse

func (*PlanExecutor) SetLockURL

func (p *PlanExecutor) SetLockURL(f func(id string) (url string))

type PlanSuccess

type PlanSuccess struct {
	TerraformOutput string
	LockURL         string
}

type PreExecuteResult

type PreExecuteResult struct {
	ProjectResult    ProjectResult
	ProjectConfig    ProjectConfig
	TerraformVersion *version.Version
	LockResponse     locking.TryLockResponse
}

type ProjectConfig

type ProjectConfig struct {
	// PreInit is a slice of command strings to run prior to terraform init.
	PreInit []string
	// PreGet is a slice of command strings to run prior to terraform get.
	PreGet []string
	// PrePlan is a slice of command strings to run prior to terraform plan.
	PrePlan []string
	// PostPlan is a slice of command strings to run after terraform plan.
	PostPlan []string
	// PreApply is a slice of command strings to run prior to terraform apply.
	PreApply []string
	// PostApply is a slice of command strings to run after terraform apply.
	PostApply []string
	// TerraformVersion is the version specified in the config file or nil
	// if version wasn't specified.
	TerraformVersion *version.Version
	// contains filtered or unexported fields
}

ProjectConfig is a more usable version of projectConfigYAML that we can return to our callers. It holds the config for a project.

func (*ProjectConfig) GetExtraArguments

func (c *ProjectConfig) GetExtraArguments(command string) []string

GetExtraArguments returns the arguments that were specified to be appended to command in the project config file.

type ProjectConfigManager

type ProjectConfigManager struct{}

ProjectConfigManager deals with project config files that users can use to specify additional behaviour around how Atlantis executes for a project.

func (*ProjectConfigManager) Exists

func (c *ProjectConfigManager) Exists(projectPath string) bool

Exists returns true if an atlantis config file exists for the project at projectPath. projectPath is an absolute path to the project.

func (*ProjectConfigManager) Read

func (c *ProjectConfigManager) Read(execPath string) (ProjectConfig, error)

Read attempts to read the project config file for the project at projectPath. NOTE: projectPath is not the path to the actual config file. Returns the parsed ProjectConfig or error if unable to read.

type ProjectConfigReader

type ProjectConfigReader interface {
	// Exists returns true if a project config file exists at projectPath.
	Exists(projectPath string) bool
	// Read attempts to read the project config file for the project at projectPath.
	// NOTE: projectPath is not the path to the actual config file.
	// Returns the parsed ProjectConfig or error if unable to read.
	Read(projectPath string) (ProjectConfig, error)
}

ProjectConfigReader implements reading project config.

type ProjectFinder

type ProjectFinder struct{}

ProjectFinder identifies projects in a repo.

func (*ProjectFinder) FindModified

func (p *ProjectFinder) FindModified(log *logging.SimpleLogger, modifiedFiles []string, repoFullName string) []models.Project

FindModified returns the list of projects that were modified based on the modifiedFiles. The list will be de-duplicated.

type ProjectPreExecute

type ProjectPreExecute struct {
	Locker       locking.Locker
	ConfigReader ProjectConfigReader
	Terraform    terraform.Runner
	Run          run.Runner
}

func (*ProjectPreExecute) Execute

func (p *ProjectPreExecute) Execute(ctx *CommandContext, repoDir string, project models.Project) PreExecuteResult

type ProjectPreExecutor

type ProjectPreExecutor interface {
	Execute(ctx *CommandContext, repoDir string, project models.Project) PreExecuteResult
}

type ProjectResult

type ProjectResult struct {
	Path         string
	Error        error
	Failure      string
	PlanSuccess  *PlanSuccess
	ApplySuccess string
}

func (ProjectResult) Status

func (p ProjectResult) Status() vcs.CommitStatus

type PullCleaner

type PullCleaner interface {
	CleanUpPull(repo models.Repo, pull models.PullRequest, host vcs.Host) error
}

type PullClosedExecutor

type PullClosedExecutor struct {
	Locker    locking.Locker
	VCSClient vcs.ClientProxy
	Workspace Workspace
}

func (*PullClosedExecutor) CleanUpPull

func (p *PullClosedExecutor) CleanUpPull(repo models.Repo, pull models.PullRequest, host vcs.Host) error

type ResultData

type ResultData struct {
	Results map[string]string
	CommonData
}

type Workspace

type Workspace interface {
	// Clone git clones headRepo, checks out the branch and then returns the absolute
	// path to the root of the cloned repo.
	Clone(log *logging.SimpleLogger, baseRepo models.Repo, headRepo models.Repo, p models.PullRequest, env string) (string, error)
	GetWorkspace(r models.Repo, p models.PullRequest, env string) (string, error)
	Delete(r models.Repo, p models.PullRequest) error
}

Directories

Path Synopsis
Package locking handles locking projects when they have in-progress runs.
Package locking handles locking projects when they have in-progress runs.
boltdb
Package boltdb provides a locking implementation using Bolt.
Package boltdb provides a locking implementation using Bolt.
Package models holds all models that are needed across packages.
Package models holds all models that are needed across packages.
run
Package run handles running commands prior and following the regular Atlantis commands.
Package run handles running commands prior and following the regular Atlantis commands.
Package terraform handles the actual running of terraform commands
Package terraform handles the actual running of terraform commands
vcs

Jump to

Keyboard shortcuts

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