events

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const ProjectConfigFile = "atlantis.yaml"

ProjectConfigFile is the filename of Atlantis project config.

Variables

View Source
var DidYouMeanAtlantisComment = "Did you mean to use `atlantis` instead of `terraform`?"
View Source
var HelpComment = "```cmake\n" +
	`atlantis
Terraform automation and collaboration for your team

Usage:
  atlantis <command> [options]

Commands:
  plan   Runs 'terraform plan' for the changes in this pull request.
  apply  Runs 'terraform apply' on the plans generated by 'atlantis plan'.
  help   View help.

Flags:
  -h, --help   help for atlantis

Use "atlantis [command] --help" for more information about a command.
`

Functions

This section is empty.

Types

type ApplyExecutor

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

ApplyExecutor handles executing terraform apply.

func (*ApplyExecutor) Execute

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

Execute executes apply for the ctx.

type AtlantisWorkspace added in v0.2.2

type AtlantisWorkspace 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, workspace string) (string, error)
	// GetWorkspace returns the path to the workspace for this repo and pull.
	GetWorkspace(r models.Repo, p models.PullRequest, workspace string) (string, error)
	// Delete deletes the workspace for this repo and pull.
	Delete(r models.Repo, p models.PullRequest) error
}

AtlantisWorkspace handles the workspace on disk for running commands.

type AtlantisWorkspaceLocker added in v0.2.2

type AtlantisWorkspaceLocker interface {
	// TryLock tries to acquire a lock for this repo, workspace and pull.
	TryLock(repoFullName string, workspace string, pullNum int) bool
	// Unlock deletes the lock for this repo, workspace and pull. If there was no
	// lock it will do nothing.
	Unlock(repoFullName, workspace string, pullNum int)
}

AtlantisWorkspaceLocker is used to prevent multiple commands from executing at the same time for a single repo, pull, and workspace. We need to prevent this from happening because a specific repo/pull/workspace has a single workspace on disk and we haven't written Atlantis (yet) to handle concurrent execution within this workspace. This locker is called AtlantisWorkspaceLocker to differentiate it from the Terraform concept of workspaces, not directories on disk managed by Atlantis.

type Command

type Command struct {
	Name      CommandName
	Workspace string
	Verbose   bool
	Flags     []string
	// Dir is the path relative to the repo root to run the command in.
	// If empty string then it wasn't specified. "." is the root of the repo.
	// Dir will never end in "/".
	Dir string
}

type CommandContext

type CommandContext struct {
	// BaseRepo is the repository that the pull request will be merged into.
	BaseRepo models.Repo
	// HeadRepo is the repository that is getting merged into the BaseRepo.
	// If the pull request branch is from the same repository then HeadRepo will
	// be the same as BaseRepo.
	// See https://help.github.com/articles/about-pull-request-merges/.
	HeadRepo models.Repo
	Pull     models.PullRequest
	// User is the user that triggered this command.
	User    models.User
	Command *Command
	Log     *logging.SimpleLogger
	// VCSHost is the host that the command came from.
	VCSHost vcs.Host
}

CommandContext represents the context of a command that came from a comment on a pull request.

type CommandHandler

type CommandHandler struct {
	PlanExecutor             Executor
	ApplyExecutor            Executor
	LockURLGenerator         LockURLGenerator
	VCSClient                vcs.ClientProxy
	GithubPullGetter         GithubPullGetter
	GitlabMergeRequestGetter GitlabMergeRequestGetter
	CommitStatusUpdater      CommitStatusUpdater
	EventParser              EventParsing
	AtlantisWorkspaceLocker  AtlantisWorkspaceLocker
	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))

SetLockURL sets a function that's used to return the URL for a lock.

type CommandName

type CommandName int

CommandName is the type of command.

const (
	Apply CommandName = iota
	Plan
)

func (CommandName) String

func (c CommandName) String() string

String returns the string representation of c.

type CommandResponse

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

CommandResponse is the result of running a Command.

type CommandRunner

type CommandRunner interface {
	// ExecuteCommand is the first step after a command request has been parsed.
	// It handles gathering additional information needed to execute the command
	// and then calling the appropriate services to finish executing the command.
	ExecuteCommand(baseRepo models.Repo, headRepo models.Repo, user models.User, pullNum int, cmd *Command, vcsHost vcs.Host)
}

CommandRunner is the first step after a command request has been parsed.

type CommentParseResult added in v0.3.0

type CommentParseResult struct {
	// Command is the successfully parsed command. Will be nil if
	// CommentResponse or Ignore is set.
	Command *Command
	// CommentResponse is set when we should respond immediately to the command
	// for example for atlantis help.
	CommentResponse string
	// Ignore is set to true when we should just ignore this comment.
	Ignore bool
}

CommentParseResult describes the result of parsing a comment as a command.

type CommentParser added in v0.3.0

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

CommentParser implements CommentParsing

func (*CommentParser) Parse added in v0.3.0

func (e *CommentParser) Parse(comment string, vcsHost vcs.Host) CommentParseResult

Parse parses the comment as an Atlantis command.

Valid commands contain:

  • The initial "executable" name, 'run' or 'atlantis' or '@GithubUser' where GithubUser is the API user Atlantis is running as.
  • Then a command, either 'plan', 'apply', or 'help'.
  • Then optional flags, then an optional separator '--' followed by optional extra flags to be appended to the terraform plan/apply command.

Examples: - atlantis help - run plan - @GithubUser plan -w staging - atlantis plan -w staging -d dir --verbose - atlantis plan --verbose -- -key=value -key2 value2

nolint: gocyclo

type CommentParsing added in v0.3.0

type CommentParsing interface {
	// Parse attempts to parse a pull request comment to see if it's an Atlantis
	// commmand.
	Parse(comment string, vcsHost vcs.Host) CommentParseResult
}

CommentParsing handles parsing pull request comments.

type CommitStatusUpdater added in v0.2.0

type CommitStatusUpdater interface {
	// Update updates the status of the head commit of pull.
	Update(repo models.Repo, pull models.PullRequest, status vcs.CommitStatus, cmd *Command, host vcs.Host) error
	// UpdateProjectResult updates the status of the head commit given the
	// state of response.
	UpdateProjectResult(ctx *CommandContext, res CommandResponse) error
}

CommitStatusUpdater updates the status of a commit with the VCS host. We set the status to signify whether the plan/apply succeeds.

type CommonData

type CommonData struct {
	Command string
	Verbose bool
	Log     string
}

CommonData is data that all responses have.

type DefaultAtlantisWorkspaceLocker added in v0.2.2

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

DefaultAtlantisWorkspaceLocker implements AtlantisWorkspaceLocker.

func NewDefaultAtlantisWorkspaceLocker added in v0.2.2

func NewDefaultAtlantisWorkspaceLocker() *DefaultAtlantisWorkspaceLocker

NewDefaultAtlantisWorkspaceLocker is a constructor.

func (*DefaultAtlantisWorkspaceLocker) TryLock added in v0.2.2

func (d *DefaultAtlantisWorkspaceLocker) TryLock(repoFullName string, workspace string, pullNum int) bool

TryLock returns true if a lock is acquired for this repo, pull and workspace and false otherwise.

func (*DefaultAtlantisWorkspaceLocker) Unlock added in v0.2.2

func (d *DefaultAtlantisWorkspaceLocker) Unlock(repoFullName, workspace string, pullNum int)

Unlock unlocks the repo, pull and workspace.

type DefaultCommitStatusUpdater added in v0.2.0

type DefaultCommitStatusUpdater struct {
	Client vcs.ClientProxy
}

DefaultCommitStatusUpdater implements CommitStatusUpdater.

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

Update updates the commit status.

func (*DefaultCommitStatusUpdater) UpdateProjectResult added in v0.2.0

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

UpdateProjectResult updates the commit status based on the status of res.

type DefaultProjectFinder added in v0.2.1

type DefaultProjectFinder struct{}

DefaultProjectFinder implements ProjectFinder.

func (*DefaultProjectFinder) DetermineProjects added in v0.3.0

func (p *DefaultProjectFinder) DetermineProjects(log *logging.SimpleLogger, modifiedFiles []string, repoFullName string, repoDir string) []models.Project

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

type DefaultProjectPreExecutor added in v0.2.1

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

DefaultProjectPreExecutor implements ProjectPreExecutor.

func (*DefaultProjectPreExecutor) Execute added in v0.2.1

Execute executes the pre plan/apply tasks.

type ErrData

type ErrData struct {
	Error string
	CommonData
}

ErrData is data about an error response.

type EventParser

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

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 {
	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
}

Executor is the generic interface implemented by each command type: help, plan, and apply.

type FailureData

type FailureData struct {
	Failure string
	CommonData
}

FailureData is data about a failure response.

type FileWorkspace

type FileWorkspace struct {
	DataDir string
}

FileWorkspace implements AtlantisWorkspace with the file system.

func (*FileWorkspace) Clone

func (w *FileWorkspace) Clone(
	log *logging.SimpleLogger,
	baseRepo models.Repo,
	headRepo models.Repo,
	p models.PullRequest,
	workspace 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, workspace string) (string, error)

GetWorkspace returns the path to the workspace for this repo and pull.

type GithubPullGetter added in v0.2.0

type GithubPullGetter interface {
	// GetPullRequest gets the pull request with id pullNum for the repo.
	GetPullRequest(repo models.Repo, pullNum int) (*github.PullRequest, error)
}

GithubPullGetter makes API calls to get pull requests.

type GitlabMergeRequestGetter added in v0.2.0

type GitlabMergeRequestGetter interface {
	// GetMergeRequest gets the pull request with the id pullNum for the repo.
	GetMergeRequest(repoFullName string, pullNum int) (*gitlab.MergeRequest, error)
}

GitlabMergeRequestGetter makes API calls to get merge requests.

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))
}

LockURLGenerator consumes lock URLs.

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 markdown string. nolint: interfacer

type PlanExecutor

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

PlanExecutor handles everything related to running terraform plan.

func (*PlanExecutor) Execute

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

Execute executes terraform plan for the ctx.

func (*PlanExecutor) SetLockURL

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

SetLockURL takes a function that given a lock id, will return a url to view that lock.

type PlanSuccess

type PlanSuccess struct {
	TerraformOutput string
	LockURL         string
}

PlanSuccess is the result of a successful plan.

type PreExecuteResult

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

PreExecuteResult is the result of running the pre execute.

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, just to the
	// project root.
	// Returns the parsed ProjectConfig or error if unable to read.
	Read(projectPath string) (ProjectConfig, error)
}

ProjectConfigReader implements reading project config.

type ProjectFinder

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

ProjectFinder determines what are the terraform project(s) within a repo.

type ProjectPreExecutor

type ProjectPreExecutor interface {
	// Execute executes the pre plan/apply tasks.
	Execute(ctx *CommandContext, repoDir string, project models.Project) PreExecuteResult
}

ProjectPreExecutor executes before the plan and apply executors. It handles the setup tasks that are common to both plan and apply.

type ProjectResult

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

ProjectResult is the result of executing a plan/apply for a project.

func (ProjectResult) Status

func (p ProjectResult) Status() vcs.CommitStatus

Status returns the vcs commit status of this project result.

type PullCleaner

type PullCleaner interface {
	// CleanUpPull deletes the workspaces used by the pull request on disk
	// and deletes any locks associated with this pull request for all workspaces.
	CleanUpPull(repo models.Repo, pull models.PullRequest, host vcs.Host) error
}

PullCleaner cleans up pull requests after they're closed/merged.

type PullClosedExecutor

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

PullClosedExecutor executes the tasks required to clean up a closed pull request.

func (*PullClosedExecutor) CleanUpPull

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

CleanUpPull cleans up after a closed pull request.

type ResultData

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

ResultData is data about a successful response.

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