events

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRepoRelDir is the default directory we run commands in, relative
	// to the root of the repo.
	DefaultRepoRelDir = "."
	// DefaultWorkspace is the default Terraform workspace we run commands in.
	// This is also Terraform's default workspace.
	DefaultWorkspace = "default"
)
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`?"

DidYouMeanAtlantisComment is the comment we add to the pull request when someone runs a command with terraform instead of atlantis.

View Source
var HelpComment = "```cmake\n" +
	`atlantis
Terraform For Teams

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 all unapplied plans from this pull request
  atlantis apply

  # apply the plan for the root directory and staging workspace
  atlantis apply -d . -w staging

Commands:
  plan   Runs 'terraform plan' for the changes in this pull request.
         To plan a specific project, use the -d, -w and -p flags.
  apply  Runs 'terraform apply' on all unapplied plans from this pull request.
         To only apply a specific plan, use the -d, -w and -p flags.
  help   View help.

Flags:
  -h, --help   help for atlantis

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

HelpComment is the comment we add to the pull request when someone runs `atlantis help`.

Functions

This section is empty.

Types

type AutoplanCommand added in v0.4.0

type AutoplanCommand struct{}

AutoplanCommand is a plan command that is automatically triggered when a pull request is opened or updated.

func (AutoplanCommand) CommandName added in v0.4.0

func (c AutoplanCommand) CommandName() models.CommandName

CommandName is Plan.

func (AutoplanCommand) IsAutoplan added in v0.4.0

func (c AutoplanCommand) IsAutoplan() bool

IsAutoplan is true for autoplan commands (obviously).

func (AutoplanCommand) IsVerbose added in v0.4.0

func (c AutoplanCommand) IsVerbose() bool

IsVerbose is false for autoplan commands.

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
	// PullMergeable is true if Pull is able to be merged. This is available in
	// the CommandContext because we want to collect this information before we
	// set our own build statuses which can affect mergeability if users have
	// required the Atlantis status to be successful prior to merging.
	PullMergeable bool
}

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

type CommandResult added in v0.4.0

type CommandResult struct {
	Error          error
	Failure        string
	ProjectResults []models.ProjectResult
	// PlansDeleted is true if all plans created during this command were
	// deleted. This happens if automerging is enabled and one project has an
	// error since automerging requires all plans to succeed.
	PlansDeleted bool
}

CommandResult is the result of running a Command.

func (CommandResult) HasErrors added in v0.4.14

func (c CommandResult) HasErrors() bool

HasErrors returns true if there were any errors during the execution, even if it was only in one project.

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, maybePull *models.PullRequest, 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 CommentBuilder added in v0.4.5

type CommentBuilder interface {
	// BuildPlanComment builds a plan comment for the specified args.
	BuildPlanComment(repoRelDir string, workspace string, project string, commentArgs []string) string
	// BuildApplyComment builds an apply comment for the specified args.
	BuildApplyComment(repoRelDir string, workspace string, project string) string
}

CommentBuilder builds comment commands that can be used on pull requests.

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 end in "/". If empty then the comment specified no directory.
	RepoRelDir string
	// Flags are the extra arguments appended to the comment,
	// ex. atlantis plan -- -target=resource
	Flags []string
	// Name is the name of the command the comment specified.
	Name models.CommandName
	// Verbose is true if the command should output verbosely.
	Verbose bool
	// Workspace is the name of the Terraform workspace to run the command in.
	// If empty then the comment specified no workspace.
	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.
	// If empty then the comment specified no project.
	ProjectName string
}

CommentCommand is a command that was triggered by a pull request comment.

func NewCommentCommand added in v0.4.0

func NewCommentCommand(repoRelDir string, flags []string, name models.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() models.CommandName

CommandName returns the name of this command.

func (CommentCommand) IsAutoplan added in v0.4.0

func (c CommentCommand) IsAutoplan() bool

IsAutoplan will be false for comment commands.

func (CommentCommand) IsForSpecificProject added in v0.4.5

func (c CommentCommand) IsForSpecificProject() bool

IsForSpecificProject returns true if the command is for a specific dir, workspace or project name. Otherwise it's a command like "atlantis plan" or "atlantis apply".

func (CommentCommand) IsVerbose added in v0.4.0

func (c CommentCommand) IsVerbose() bool

IsVerbose is true if the command should give verbose output.

func (CommentCommand) String added in v0.4.0

func (c CommentCommand) String() string

String returns a string representation of the command.

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
	GitlabUser    string
	BitbucketUser string
}

CommentParser implements CommentParsing

func (*CommentParser) BuildApplyComment added in v0.4.5

func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, project string) string

BuildApplyComment builds an apply comment for the specified args.

func (*CommentParser) BuildPlanComment added in v0.4.5

func (e *CommentParser) BuildPlanComment(repoRelDir string, workspace string, project string, commentArgs []string) string

BuildPlanComment builds a plan comment for the specified args.

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 {
	// UpdateCombined updates the combined status of the head commit of pull.
	// A combined status represents all the projects modified in the pull.
	UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) error
	// UpdateCombinedCount updates the combined status to reflect the
	// numSuccess out of numTotal.
	UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) error
	// UpdateProject sets the commit status for the project represented by
	// ctx.
	UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error
}

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

type DefaultCommandRunner added in v0.4.0

type DefaultCommandRunner struct {
	VCSClient                vcs.Client
	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
	// GlobalAutomerge is true if we should automatically merge pull requests if all
	// plans have been successfully applied. This is set via a CLI flag.
	GlobalAutomerge   bool
	PendingPlanFinder PendingPlanFinder
	WorkingDir        WorkingDir
	DB                *db.BoltDB
}

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)

RunAutoplanCommand runs plan when a pull request is opened or updated.

func (*DefaultCommandRunner) RunCommentCommand added in v0.4.0

func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, 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.Client
}

DefaultCommitStatusUpdater implements CommitStatusUpdater.

func (*DefaultCommitStatusUpdater) UpdateCombined added in v0.5.0

func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) error

func (*DefaultCommitStatusUpdater) UpdateCombinedCount added in v0.5.0

func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) error

func (*DefaultCommitStatusUpdater) UpdateProject added in v0.5.0

type DefaultPendingPlanFinder added in v0.4.14

type DefaultPendingPlanFinder struct{}

DefaultPendingPlanFinder finds unapplied plans.

func (*DefaultPendingPlanFinder) DeletePlans added in v0.4.14

func (p *DefaultPendingPlanFinder) DeletePlans(pullDir string) error

deletePlans deletes all plans in pullDir.

func (*DefaultPendingPlanFinder) Find added in v0.4.14

func (p *DefaultPendingPlanFinder) Find(pullDir string) ([]PendingPlan, error)

Find finds all pending plans in pullDir. pullDir should be the working directory where Atlantis will operate on this pull request. It's one level up from where Atlantis clones the repo for each workspace.

type DefaultProjectCommandBuilder added in v0.4.0

type DefaultProjectCommandBuilder struct {
	ParserValidator     *yaml.ParserValidator
	ProjectFinder       ProjectFinder
	VCSClient           vcs.Client
	WorkingDir          WorkingDir
	WorkingDirLocker    WorkingDirLocker
	AllowRepoConfig     bool
	AllowRepoConfigFlag string
	PendingPlanFinder   *DefaultPendingPlanFinder
	CommentBuilder      CommentBuilder
}

DefaultProjectCommandBuilder implements ProjectCommandBuilder. This class combines the data from the comment and any repo config file or Atlantis server config and then generates a set of contexts.

func (*DefaultProjectCommandBuilder) BuildApplyCommands added in v0.4.5

BuildApplyCommands builds project apply commands for this comment. If the comment doesn't specify one project then there may be multiple commands to be run.

func (*DefaultProjectCommandBuilder) BuildAutoplanCommands added in v0.4.0

BuildAutoplanCommands builds project commands that will run plan on the projects determined to be modified.

func (*DefaultProjectCommandBuilder) BuildPlanCommands added in v0.4.5

BuildPlanCommands builds project plan commands for this comment. If the comment doesn't specify one project then there may be multiple commands to be run.

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
	RequireMergeableOverride bool
}

DefaultProjectCommandRunner implements ProjectCommandRunner.

func (*DefaultProjectCommandRunner) Apply added in v0.4.0

Apply runs terraform apply for the project described by ctx.

func (*DefaultProjectCommandRunner) Plan added in v0.4.0

Plan runs terraform plan for the project described by ctx.

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)

DetermineProjectsViaConfig returns the list of projects that were modified based on the modifiedFiles and config. We look at the WhenModified section of the config for each project and see if the modifiedFiles matches. The list will be de-duplicated.

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, pullNum int, workspace string) (func(), error)

func (*DefaultWorkingDirLocker) TryLockPull added in v0.4.5

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

func (*DefaultWorkingDirLocker) UnlockPull added in v0.4.5

func (d *DefaultWorkingDirLocker) UnlockPull(repoFullName string, pullNum int)

Unlock unlocks all workspaces for this pull.

type DirNotExistErr added in v0.4.14

type DirNotExistErr struct {
	RepoRelDir string
}

DirNotExistErr is an error caused by the directory not existing.

func (DirNotExistErr) Error added in v0.4.14

func (d DirNotExistErr) Error() string

Error implements the error interface.

type EventParser

type EventParser struct {
	GithubUser         string
	GithubToken        string
	GitlabUser         string
	GitlabToken        string
	BitbucketUser      string
	BitbucketToken     string
	BitbucketServerURL string
}

EventParser parses VCS events.

func (*EventParser) GetBitbucketCloudPullEventType added in v0.4.8

func (e *EventParser) GetBitbucketCloudPullEventType(eventTypeHeader string) models.PullRequestEventType

GetBitbucketCloudPullEventType returns the type of the pull request event given the Bitbucket Cloud header.

func (*EventParser) GetBitbucketServerPullEventType added in v0.4.8

func (e *EventParser) GetBitbucketServerPullEventType(eventTypeHeader string) models.PullRequestEventType

GetBitbucketServerPullEventType returns the type of the pull request event given the Bitbucket Server header.

func (*EventParser) ParseBitbucketCloudPullCommentEvent added in v0.4.8

func (e *EventParser) ParseBitbucketCloudPullCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error)

ParseBitbucketCloudPullCommentEvent parses a pull request comment event from Bitbucket Cloud (bitbucket.org). See EventParsing for return value docs.

func (*EventParser) ParseBitbucketCloudPullEvent added in v0.4.3

func (e *EventParser) ParseBitbucketCloudPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

ParseBitbucketCloudPullEvent parses a pull request event from Bitbucket Cloud (bitbucket.org). See EventParsing for return value docs.

func (*EventParser) ParseBitbucketServerPullCommentEvent added in v0.4.8

func (e *EventParser) ParseBitbucketServerPullCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error)

ParseBitbucketServerPullCommentEvent parses a pull request comment event from Bitbucket Server. See EventParsing for return value docs.

func (*EventParser) ParseBitbucketServerPullEvent added in v0.4.4

func (e *EventParser) ParseBitbucketServerPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

ParseBitbucketServerPullEvent parses a pull request event from Bitbucket Server. See EventParsing for return value docs.

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)

ParseGithubIssueCommentEvent parses GitHub pull request comment events. See EventParsing for return value docs.

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)

ParseGithubPull parses the response from the GitHub API endpoint (not from a webhook) that returns a pull request. See EventParsing for return value docs.

func (*EventParser) ParseGithubPullEvent added in v0.4.0

func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (pull models.PullRequest, pullEventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

ParseGithubPullEvent parses GitHub pull request events. See EventParsing for return value docs.

func (*EventParser) ParseGithubRepo added in v0.2.0

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

ParseGithubRepo parses the response from the GitHub API endpoint that returns a repo into the Atlantis model. See EventParsing for return value docs.

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 we can't get this information from the merge request. The only caller of this function already has that data so we can construct the pull request object correctly.

func (*EventParser) ParseGitlabMergeRequestCommentEvent added in v0.4.8

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

ParseGitlabMergeRequestCommentEvent parses GitLab merge request comment events. See EventParsing for return value docs.

func (*EventParser) ParseGitlabMergeRequestEvent added in v0.4.8

func (e *EventParser) ParseGitlabMergeRequestEvent(event gitlab.MergeEvent) (pull models.PullRequest, eventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

ParseGitlabMergeRequestEvent parses GitLab merge request events. pull is the parsed merge request. See EventParsing for return value docs.

type EventParsing

type EventParsing interface {
	// ParseGithubIssueCommentEvent parses GitHub pull request comment events.
	// baseRepo is the repo that the pull request will be merged into.
	// user is the pull request author.
	// pullNum is the number of the pull request that triggered the webhook.
	ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (
		baseRepo models.Repo, user models.User, pullNum int, err error)

	// ParseGithubPull parses the response from the GitHub API endpoint (not
	// from a webhook) that returns a pull request.
	// pull is the parsed pull request.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	ParseGithubPull(ghPull *github.PullRequest) (
		pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, err error)

	// ParseGithubPullEvent parses GitHub pull request events.
	// pull is the parsed pull request.
	// pullEventType is the type of event, for example opened/closed.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	// user is the pull request author.
	ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
		pull models.PullRequest, pullEventType models.PullRequestEventType,
		baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

	// ParseGithubRepo parses the response from the GitHub API endpoint that
	// returns a repo into the Atlantis model.
	ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error)

	// ParseGitlabMergeRequestEvent parses GitLab merge request events.
	// pull is the parsed merge request.
	// pullEventType is the type of event, for example opened/closed.
	// baseRepo is the repo the merge request will be merged into.
	// headRepo is the repo the merge request branch is from.
	// user is the pull request author.
	ParseGitlabMergeRequestEvent(event gitlab.MergeEvent) (
		pull models.PullRequest, pullEventType models.PullRequestEventType,
		baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

	// ParseGitlabMergeRequestCommentEvent parses GitLab merge request comment
	// events.
	// baseRepo is the repo the merge request will be merged into.
	// headRepo is the repo the merge request branch is from.
	// user is the pull request author.
	ParseGitlabMergeRequestCommentEvent(event gitlab.MergeCommentEvent) (
		baseRepo models.Repo, headRepo models.Repo, user models.User, err error)

	// ParseGitlabMergeRequest parses the response from the GitLab API endpoint
	// that returns a merge request.
	ParseGitlabMergeRequest(mr *gitlab.MergeRequest, baseRepo models.Repo) models.PullRequest

	// ParseBitbucketCloudPullEvent parses a pull request event from Bitbucket
	// Cloud (bitbucket.org).
	// pull is the parsed pull request.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	// user is the pull request author.
	ParseBitbucketCloudPullEvent(body []byte) (
		pull models.PullRequest, baseRepo models.Repo,
		headRepo models.Repo, user models.User, err error)

	// ParseBitbucketCloudPullCommentEvent parses a pull request comment event
	// from Bitbucket Cloud (bitbucket.org).
	// pull is the parsed pull request.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	// user is the pull request author.
	// comment is the comment that triggered the event.
	ParseBitbucketCloudPullCommentEvent(body []byte) (
		pull models.PullRequest, baseRepo models.Repo,
		headRepo models.Repo, user models.User, comment string, err error)

	// GetBitbucketCloudPullEventType returns the type of the pull request
	// event given the Bitbucket Cloud header.
	GetBitbucketCloudPullEventType(eventTypeHeader string) models.PullRequestEventType

	// ParseBitbucketServerPullEvent parses a pull request event from Bitbucket
	// Server.
	// pull is the parsed pull request.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	// user is the pull request author.
	ParseBitbucketServerPullEvent(body []byte) (
		pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo,
		user models.User, err error)

	// ParseBitbucketServerPullCommentEvent parses a pull request comment event
	// from Bitbucket Server.
	// pull is the parsed pull request.
	// baseRepo is the repo the pull request will be merged into.
	// headRepo is the repo the pull request branch is from.
	// user is the pull request author.
	// comment is the comment that triggered the event.
	ParseBitbucketServerPullCommentEvent(body []byte) (
		pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo,
		user models.User, comment string, err error)

	// GetBitbucketServerPullEventType returns the type of the pull request
	// event given the Bitbucket Server header.
	GetBitbucketServerPullEventType(eventTypeHeader string) models.PullRequestEventType
}

EventParsing parses webhook events from different VCS hosts into their respective Atlantis models. todo: rename to VCSParsing or the like because this also parses API responses #refactor

type FileWorkspace

type FileWorkspace struct {
	DataDir string
	// CheckoutMerge is true if we should check out the branch that corresponds
	// to what the base branch will look like *after* the pull request is merged.
	// If this is false, then we will check out the head branch from the pull
	// request.
	CheckoutMerge bool
	// TestingOverrideHeadCloneURL can be used during testing to override the
	// URL of the head repo to be cloned. If it's empty then we clone normally.
	TestingOverrideHeadCloneURL string
	// TestingOverrideBaseCloneURL can be used during testing to override the
	// URL of the base repo to be cloned. If it's empty then we clone normally.
	TestingOverrideBaseCloneURL 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

DeleteForWorkspace deletes the working dir for this workspace.

func (*FileWorkspace) GetPullDir added in v0.4.5

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

GetPullDir returns the dir where the workspaces for this pull are cloned. If the dir doesn't exist it will return an error.

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 LockURLGenerator

type LockURLGenerator interface {
	// GenerateLockURL returns the full URL to the lock at lockID.
	GenerateLockURL(lockID string) string
}

LockURLGenerator generates urls to locks.

type MarkdownRenderer added in v0.2.0

type MarkdownRenderer struct {
	// GitlabSupportsCommonMark is true if the version of GitLab we're
	// using supports the CommonMark markdown format.
	// If we're not configured with a GitLab client, this will be false.
	GitlabSupportsCommonMark bool
}

MarkdownRenderer renders responses as markdown.

func (*MarkdownRenderer) Render added in v0.2.0

func (m *MarkdownRenderer) Render(res CommandResult, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType) string

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

type PendingPlan added in v0.4.5

type PendingPlan struct {
	// RepoDir is the absolute path to the root of the repo that holds this
	// plan.
	RepoDir string
	// RepoRelDir is the relative path from the repo to the project that
	// the plan is for.
	RepoRelDir string
	// Workspace is the workspace this plan should execute in.
	Workspace string
}

PendingPlan is a plan that has not been applied.

type PendingPlanFinder added in v0.4.5

type PendingPlanFinder interface {
	Find(pullDir string) ([]PendingPlan, error)
	DeletePlans(pullDir string) error
}

type ProjectCommandBuilder added in v0.4.0

type ProjectCommandBuilder interface {
	// BuildAutoplanCommands builds project commands that will run plan on
	// the projects determined to be modified.
	BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error)
	// BuildPlanCommands builds project plan commands for this comment. If the
	// comment doesn't specify one project then there may be multiple commands
	// to be run.
	BuildPlanCommands(ctx *CommandContext, commentCommand *CommentCommand) ([]models.ProjectCommandContext, error)
	// BuildApplyCommands builds project apply commands for this comment. If the
	// comment doesn't specify one project then there may be multiple commands
	// to be run.
	BuildApplyCommands(ctx *CommandContext, commentCommand *CommentCommand) ([]models.ProjectCommandContext, error)
}

ProjectCommandBuilder builds commands that run on individual projects.

type ProjectCommandRunner added in v0.4.0

type ProjectCommandRunner interface {
	// Plan runs terraform plan for the project described by ctx.
	Plan(ctx models.ProjectCommandContext) models.ProjectResult
	// Apply runs terraform apply for the project described by ctx.
	Apply(ctx models.ProjectCommandContext) models.ProjectResult
}

ProjectCommandRunner runs project commands. A project command is a command for a specific TF project.

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 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.Client
	WorkingDir WorkingDir
	Logger     logging.SimpleLogging
	DB         *db.BoltDB
}

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 PullCommand added in v0.4.8

type PullCommand interface {
	// CommandName is the name of the command we're running.
	CommandName() models.CommandName
	// IsVerbose is true if the output of this command should be verbose.
	IsVerbose() bool
	// IsAutoplan is true if this is an autoplan command vs. a comment command.
	IsAutoplan() bool
}

PullCommand is a command to run on a pull request.

type RepoWhitelistChecker added in v0.4.0

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

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

func NewRepoWhitelistChecker added in v0.4.3

func NewRepoWhitelistChecker(whitelist string) (*RepoWhitelistChecker, error)

NewRepoWhitelistChecker constructs a new checker and validates that the whitelist isn't malformed.

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

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

StepRunner runs steps. Steps are individual pieces of execution like `terraform plan`.

type TFCommandRunner added in v0.4.8

type TFCommandRunner interface {
	// RunCommandWithVersion runs a Terraform command using the version v.
	RunCommandWithVersion(log *logging.SimpleLogger, path string, args []string, v *version.Version, workspace string) (string, error)
}

TFCommandRunner runs Terraform commands.

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 sends the webhook.
	Send(log *logging.SimpleLogger, res webhooks.ApplyResult) error
}

WebhooksSender sends webhook.

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)
	GetPullDir(r models.Repo, p models.PullRequest) (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, pullNum int, workspace string) (func(), error)
	// TryLockPull tries to acquire a lock for all the workspaces in this repo
	// 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.
	TryLockPull(repoFullName string, pullNum int) (func(), error)
}

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 db handles our database layer.
Package db handles our database layer.
mocks/matchers
Code generated by pegomock.
Code generated by pegomock.
matchers
Code generated by pegomock.
Code generated by pegomock.
Package runtime holds code for actually running commands vs.
Package runtime holds code for actually running commands vs.
mocks/matchers
Code generated by pegomock.
Code generated by pegomock.
mocks/matchers
Code generated by pegomock.
Code generated by pegomock.
vcs
bitbucketcloud
Package bitbucketcloud holds code for Bitbucket Cloud aka (bitbucket.org).
Package bitbucketcloud holds code for Bitbucket Cloud aka (bitbucket.org).
common
Package common is used to share common code between all VCS clients without running into circular dependency issues.
Package common is used to share common code between all VCS clients without running into circular dependency issues.
mocks/matchers
Code generated by pegomock.
Code generated by pegomock.
mocks/matchers
Code generated by pegomock.
Code generated by pegomock.
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