events

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Copyright 2017 HootSuite Media Inc.

Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.

Index

Constants

View Source
const (
	WorkspaceFlagLong  = "workspace"
	WorkspaceFlagShort = "w"
	DirFlagLong        = "dir"
	DirFlagShort       = "d"
	ProjectFlagLong    = "project"
	ProjectFlagShort   = "p"
	VerboseFlagLong    = "verbose"
	VerboseFlagShort   = ""
	DefaultWorkspace   = "default"
	DefaultDir         = "."
)
View Source
const ProjectConfigFile = "atlantis.yaml"

ProjectConfigFile is the filename of Atlantis project config.

View Source
const Wildcard = "*"

Wildcard matches 0-n of all characters except commas.

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] -- [terraform options]

Examples:
  # run plan in the root directory passing the -target flag to terraform
  atlantis plan -d . -- -target=resource

  # apply the plan generated
  atlantis apply -d .

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 AutoplanCommand added in v0.4.0

type AutoplanCommand struct{}

func (AutoplanCommand) CommandName added in v0.4.0

func (c AutoplanCommand) CommandName() CommandName

func (AutoplanCommand) IsAutoplan added in v0.4.0

func (c AutoplanCommand) IsAutoplan() bool

func (AutoplanCommand) IsVerbose added in v0.4.0

func (c AutoplanCommand) IsVerbose() bool

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
	Log  *logging.SimpleLogger
}

CommandContext represents the context of a command that should be executed for a pull request.

type CommandInterface added in v0.4.0

type CommandInterface interface {
	CommandName() CommandName
	IsVerbose() bool
	IsAutoplan() bool
}

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 CommandResult added in v0.4.0

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

CommandResult is the result of running a Command.

type CommandRunner

type CommandRunner interface {
	// RunCommentCommand 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.
	RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, user models.User, pullNum int, cmd *CommentCommand)
	RunAutoplanCommand(baseRepo models.Repo, headRepo models.Repo, pull models.PullRequest, user models.User)
}

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

type CommentCommand added in v0.4.0

type CommentCommand struct {
	// RepoRelDir is the path relative to the repo root to run the command in.
	// Will never be an empty string and will never end in "/".
	RepoRelDir string
	// CommentArgs are the extra arguments appended to comment,
	// ex. atlantis plan -- -target=resource
	Flags     []string
	Name      CommandName
	Verbose   bool
	Workspace string
	// ProjectName is the name of a project to run the command on. It refers to a
	// project specified in an atlantis.yaml file.
	ProjectName string
}

func NewCommentCommand added in v0.4.0

func NewCommentCommand(repoRelDir string, flags []string, name CommandName, verbose bool, workspace string, project string) *CommentCommand

NewCommentCommand constructs a CommentCommand, setting all missing fields to defaults.

func (CommentCommand) CommandName added in v0.4.0

func (c CommentCommand) CommandName() CommandName

func (CommentCommand) IsAutoplan added in v0.4.0

func (c CommentCommand) IsAutoplan() bool

func (CommentCommand) IsVerbose added in v0.4.0

func (c CommentCommand) IsVerbose() bool

func (CommentCommand) String added in v0.4.0

func (c CommentCommand) String() string

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 *CommentCommand
	// 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 models.VCSHostType) 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

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
	// command.
	Parse(comment string, vcsHost models.VCSHostType) 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, command CommandName) error
	// UpdateProjectResult updates the status of the head commit given the
	// state of response.
	UpdateProjectResult(ctx *CommandContext, commandName CommandName, res CommandResult) 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 DefaultCommandRunner added in v0.4.0

type DefaultCommandRunner struct {
	VCSClient                vcs.ClientProxy
	GithubPullGetter         GithubPullGetter
	GitlabMergeRequestGetter GitlabMergeRequestGetter
	CommitStatusUpdater      CommitStatusUpdater
	EventParser              EventParsing
	MarkdownRenderer         *MarkdownRenderer
	Logger                   logging.SimpleLogging
	// AllowForkPRs controls whether we operate on pull requests from forks.
	AllowForkPRs bool
	// AllowForkPRsFlag is the name of the flag that controls fork PR's. We use
	// this in our error message back to the user on a forked PR so they know
	// how to enable this functionality.
	AllowForkPRsFlag      string
	ProjectCommandBuilder ProjectCommandBuilder
	ProjectCommandRunner  ProjectCommandRunner
}

DefaultCommandRunner is the first step when processing a comment command.

func (*DefaultCommandRunner) RunAutoplanCommand added in v0.4.0

func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo models.Repo, pull models.PullRequest, user models.User)

func (*DefaultCommandRunner) RunCommentCommand added in v0.4.0

func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, user models.User, pullNum int, cmd *CommentCommand)

RunCommentCommand executes the command. We take in a pointer for maybeHeadRepo because for some events there isn't enough data to construct the Repo model and callers might want to wait until the event is further validated before making an additional (potentially wasteful) call to get the necessary data.

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, command CommandName) error

Update updates the commit status.

func (*DefaultCommitStatusUpdater) UpdateProjectResult added in v0.2.0

func (d *DefaultCommitStatusUpdater) UpdateProjectResult(ctx *CommandContext, commandName CommandName, res CommandResult) error

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

type DefaultProjectCommandBuilder added in v0.4.0

type DefaultProjectCommandBuilder struct {
	ParserValidator     *yaml.ParserValidator
	ProjectFinder       ProjectFinder
	VCSClient           vcs.ClientProxy
	WorkingDir          WorkingDir
	WorkingDirLocker    WorkingDirLocker
	AllowRepoConfig     bool
	AllowRepoConfigFlag string
}

func (*DefaultProjectCommandBuilder) BuildApplyCommand added in v0.4.0

func (*DefaultProjectCommandBuilder) BuildAutoplanCommands added in v0.4.0

func (*DefaultProjectCommandBuilder) BuildPlanCommand added in v0.4.0

type DefaultProjectCommandRunner added in v0.4.0

type DefaultProjectCommandRunner struct {
	Locker                  ProjectLocker
	LockURLGenerator        LockURLGenerator
	InitStepRunner          StepRunner
	PlanStepRunner          StepRunner
	ApplyStepRunner         StepRunner
	RunStepRunner           StepRunner
	PullApprovedChecker     runtime.PullApprovedChecker
	WorkingDir              WorkingDir
	Webhooks                WebhooksSender
	WorkingDirLocker        WorkingDirLocker
	RequireApprovalOverride bool
}

func (*DefaultProjectCommandRunner) Apply added in v0.4.0

func (*DefaultProjectCommandRunner) Plan added in v0.4.0

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.

func (*DefaultProjectFinder) DetermineProjectsViaConfig added in v0.4.0

func (p *DefaultProjectFinder) DetermineProjectsViaConfig(log *logging.SimpleLogger, modifiedFiles []string, config valid.Config, repoDir string) ([]valid.Project, error)

type DefaultProjectLocker added in v0.4.0

type DefaultProjectLocker struct {
	Locker locking.Locker
}

DefaultProjectLocker implements ProjectLocker.

func (*DefaultProjectLocker) TryLock added in v0.4.0

func (p *DefaultProjectLocker) TryLock(log *logging.SimpleLogger, pull models.PullRequest, user models.User, workspace string, project models.Project) (*TryLockResponse, error)

TryLock implements ProjectLocker.TryLock.

type DefaultWorkingDirLocker added in v0.4.0

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

DefaultWorkingDirLocker implements WorkingDirLocker.

func NewDefaultWorkingDirLocker added in v0.4.0

func NewDefaultWorkingDirLocker() *DefaultWorkingDirLocker

NewDefaultWorkingDirLocker is a constructor.

func (*DefaultWorkingDirLocker) TryLock added in v0.4.0

func (d *DefaultWorkingDirLocker) TryLock(repoFullName string, workspace string, pullNum int) (func(), error)

func (*DefaultWorkingDirLocker) Unlock added in v0.4.0

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

Unlock unlocks the repo, pull and workspace.

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) (pullModel models.PullRequest, baseRepo models.Repo, headRepo models.Repo, err error)

func (*EventParser) ParseGithubPullEvent added in v0.4.0

func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (models.PullRequest, models.Repo, models.Repo, models.User, 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, err error)

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, models.Repo, models.User, error)

func (*EventParser) ParseGitlabMergeRequest added in v0.2.0

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

ParseGitlabMergeRequest parses the merge requests and returns a pull request model. We require passing in baseRepo because although can't get this information from the merge request, the only caller of this function already has that data. This means we can construct the pull request object correctly.

type EventParsing

type EventParsing interface {
	ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (baseRepo models.Repo, user models.User, pullNum int, err error)
	// ParseGithubPull returns the pull request, base repo and head repo.
	ParseGithubPull(pull *github.PullRequest) (models.PullRequest, models.Repo, models.Repo, error)
	// ParseGithubPullEvent returns the pull request, head repo and user that
	// caused the event. Base repo is available as a field on PullRequest.
	ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
	ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error)
	// ParseGitlabMergeEvent returns the pull request, base repo, head repo and
	// user that caused the event.
	ParseGitlabMergeEvent(event gitlab.MergeEvent) (models.PullRequest, models.Repo, models.Repo, models.User, error)
	ParseGitlabMergeCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
	ParseGitlabMergeRequest(mr *gitlab.MergeRequest, baseRepo models.Repo) models.PullRequest
}

type FailureData

type FailureData struct {
	Failure string
	CommonData
}

FailureData is data about a failure response.

type FileWorkspace

type FileWorkspace struct {
	DataDir string
	// TestingOverrideCloneURL can be used during testing to override the URL
	// that is cloned. If it's empty then we clone normally.
	TestingOverrideCloneURL string
}

FileWorkspace implements WorkingDir 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. If the repo already exists and is at the right commit it does nothing. This is to support running commands in multiple dirs of the same repo without deleting existing plans.

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) DeleteForWorkspace added in v0.4.0

func (w *FileWorkspace) DeleteForWorkspace(r models.Repo, p models.PullRequest, workspace string) error

Delete deletes the working dir for this workspace.

func (*FileWorkspace) GetWorkingDir added in v0.4.0

func (w *FileWorkspace) GetWorkingDir(r models.Repo, p models.PullRequest, workspace string) (string, error)

GetWorkingDir 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 {
	GenerateLockURL(lockID string) 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 (m *MarkdownRenderer) Render(res CommandResult, cmdName CommandName, log string, verbose bool) string

Render formats the data into a markdown string. nolint: interfacer

type PlanSuccess

type PlanSuccess struct {
	TerraformOutput string
	LockURL         string
}

PlanSuccess is the result of a successful plan.

type ProjectCommandBuilder added in v0.4.0

type ProjectCommandBuilder interface {
	BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error)
	BuildPlanCommand(ctx *CommandContext, commentCommand *CommentCommand) (models.ProjectCommandContext, error)
	BuildApplyCommand(ctx *CommandContext, commentCommand *CommentCommand) (models.ProjectCommandContext, error)
}

type ProjectCommandResult added in v0.4.0

type ProjectCommandResult struct {
	Error        error
	Failure      string
	PlanSuccess  *PlanSuccess
	ApplySuccess string
}

type ProjectCommandRunner added in v0.4.0

type ProjectCommandRunner interface {
	Plan(ctx models.ProjectCommandContext) ProjectCommandResult
	Apply(ctx models.ProjectCommandContext) ProjectCommandResult
}

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
	DetermineProjectsViaConfig(log *logging.SimpleLogger, modifiedFiles []string, config valid.Config, repoDir string) ([]valid.Project, error)
}

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

type ProjectLocker added in v0.4.0

type ProjectLocker interface {
	// TryLock attempts to acquire the lock for this project. It returns true if the lock
	// was acquired. If it returns false, the lock was not acquired and the second
	// return value will be a string describing why the lock was not acquired.
	// The third return value is a function that can be called to unlock the
	// lock. It will only be set if the lock was acquired. Any errors will set
	// error.
	TryLock(log *logging.SimpleLogger, pull models.PullRequest, user models.User, workspace string, project models.Project) (*TryLockResponse, error)
}

ProjectLocker locks this project against other plans being run until this project is unlocked.

type ProjectResult

type ProjectResult struct {
	ProjectCommandResult
	RepoRelDir string
	Workspace  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 ProjectResultTmplData added in v0.4.0

type ProjectResultTmplData struct {
	Workspace  string
	RepoRelDir string
	Rendered   string
}

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

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

type PullClosedExecutor

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

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

CleanUpPull cleans up after a closed pull request.

type RepoWhitelistChecker added in v0.4.0

type RepoWhitelistChecker struct {
	// Whitelist is a comma separated list of rules with wildcards '*' allowed.
	Whitelist string
}

RepoWhitelistChecker implements checking if repos are whitelisted to be used with this Atlantis.

func (*RepoWhitelistChecker) IsWhitelisted added in v0.4.0

func (r *RepoWhitelistChecker) IsWhitelisted(repoFullName string, vcsHostname string) bool

IsWhitelisted returns true if this repo is in our whitelist and false otherwise.

type ResultData

type ResultData struct {
	Results []ProjectResultTmplData
	CommonData
}

ResultData is data about a successful response.

type StepRunner added in v0.4.0

type StepRunner interface {
	Run(ctx models.ProjectCommandContext, extraArgs []string, path string) (string, error)
}

type TerraformExec added in v0.4.0

type TerraformExec interface {
	RunCommandWithVersion(log *logging.SimpleLogger, path string, args []string, v *version.Version, workspace string) (string, error)
}

type TryLockResponse added in v0.4.0

type TryLockResponse struct {
	// LockAcquired is true if the lock was acquired.
	LockAcquired bool
	// LockFailureReason is the reason why the lock was not acquired. It will
	// only be set if LockAcquired is false.
	LockFailureReason string
	// UnlockFn will unlock the lock created by the caller. This might be called
	// if there is an error later and the caller doesn't want to continue to
	// hold the lock.
	UnlockFn func() error
	// LockKey is the key for the lock if the lock was acquired.
	LockKey string
}

TryLockResponse is the result of trying to lock a project.

type WebhooksSender added in v0.4.0

type WebhooksSender interface {
	Send(log *logging.SimpleLogger, res webhooks.ApplyResult) error
}

type WorkingDir added in v0.4.0

type WorkingDir 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)
	// GetWorkingDir returns the path to the workspace for this repo and pull.
	// If workspace does not exist on disk, error will be of type os.IsNotExist.
	GetWorkingDir(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
	DeleteForWorkspace(r models.Repo, p models.PullRequest, workspace string) error
}

WorkingDir handles the workspace on disk for running commands.

type WorkingDirLocker added in v0.4.0

type WorkingDirLocker interface {
	// TryLock tries to acquire a lock for this repo, workspace and pull.
	// It returns a function that should be used to unlock the workspace and
	// an error if the workspace is already locked. The error is expected to
	// be printed to the pull request.
	TryLock(repoFullName string, workspace string, pullNum int) (func(), error)
	// 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)
}

WorkingDirLocker 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.

Directories

Path Synopsis
Package runtime holds code for actually running commands vs.
Package runtime holds code for actually running commands vs.
vcs
raw
Package raw contains the golang representations of the YAML elements supported in atlantis.yaml.
Package raw contains the golang representations of the YAML elements supported in atlantis.yaml.
valid
Package valid contains the structs representing the atlantis.yaml config after it's been parsed and validated.
Package valid contains the structs representing the atlantis.yaml config after it's been parsed and validated.

Jump to

Keyboard shortcuts

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