vcs

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 21 Imported by: 49

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitStatusContextFromSrc added in v0.15.1

func GitStatusContextFromSrc(src string) *azuredevops.GitStatusContext

GitStatusContextFromSrc parses an Atlantis formatted src string into a context suitable for the status update API. In the AzureDevops branch policy UI there is a single string field used to drive these contexts where all text preceding the final '/' character is treated as the 'genre'.

func MustConstraint added in v0.4.12

func MustConstraint(constraint string) version.Constraints

MustConstraint returns a constraint. It panics on error.

func SplitAzureDevopsRepoFullName added in v0.10.0

func SplitAzureDevopsRepoFullName(repoFullName string) (owner string, project string, repo string)

SplitAzureDevopsRepoFullName splits a repo full name up into its owner, repo and project name segments. If the repoFullName is malformed, may return empty strings for owner, repo, or project. Azure DevOps uses repoFullName format owner/project/repo.

Ex. runatlantis/atlantis => (runatlantis, atlantis)

gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis)
azuredevops/project/atlantis => (azuredevops, project, atlantis)

Types

type AzureDevopsClient added in v0.10.0

type AzureDevopsClient struct {
	Client *azuredevops.Client
	// contains filtered or unexported fields
}

AzureDevopsClient represents an Azure DevOps VCS client

func NewAzureDevopsClient added in v0.10.0

func NewAzureDevopsClient(hostname string, token string) (*AzureDevopsClient, error)

NewAzureDevopsClient returns a valid Azure DevOps client.

func (*AzureDevopsClient) CreateComment added in v0.10.0

func (g *AzureDevopsClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error

CreateComment creates a comment on a pull request.

If comment length is greater than the max comment length we split into multiple comments.

func (*AzureDevopsClient) DownloadRepoConfigFile added in v0.15.0

func (g *AzureDevopsClient) DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)

func (*AzureDevopsClient) GetModifiedFiles added in v0.10.0

func (g *AzureDevopsClient) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)

GetModifiedFiles returns the names of files that were modified in the merge request relative to the repo root, e.g. parent/child/file.txt.

func (*AzureDevopsClient) GetPullRequest added in v0.10.0

func (g *AzureDevopsClient) GetPullRequest(repo models.Repo, num int) (*azuredevops.GitPullRequest, error)

GetPullRequest returns the pull request.

func (*AzureDevopsClient) HidePrevPlanComments added in v0.12.0

func (g *AzureDevopsClient) HidePrevPlanComments(repo models.Repo, pullNum int) error
func (g *AzureDevopsClient) MarkdownPullLink(pull models.PullRequest) (string, error)

MarkdownPullLink specifies the string used in a pull request comment to reference another pull request.

func (*AzureDevopsClient) MergePull added in v0.10.0

func (g *AzureDevopsClient) MergePull(pull models.PullRequest) error

MergePull merges the merge request using the default no fast-forward strategy If the user has set a branch policy that disallows no fast-forward, the merge will fail until we handle branch policies https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops

func (*AzureDevopsClient) PullIsApproved added in v0.10.0

func (g *AzureDevopsClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsApproved returns true if the merge request was approved by another reviewer. https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#require-a-minimum-number-of-reviewers

func (*AzureDevopsClient) PullIsMergeable added in v0.10.0

func (g *AzureDevopsClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsMergeable returns true if the merge request can be merged.

func (*AzureDevopsClient) SupportsSingleFileDownload added in v0.15.0

func (g *AzureDevopsClient) SupportsSingleFileDownload(repo models.Repo) bool

func (*AzureDevopsClient) UpdateStatus added in v0.10.0

func (g *AzureDevopsClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

UpdateStatus updates the build status of a commit.

type Client

type Client interface {
	// GetModifiedFiles returns the names of files that were modified in the merge request
	// relative to the repo root, e.g. parent/child/file.txt.
	GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)
	CreateComment(repo models.Repo, pullNum int, comment string, command string) error
	HidePrevPlanComments(repo models.Repo, pullNum int) error
	PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)
	PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)
	// UpdateStatus updates the commit status to state for pull. src is the
	// source of this status. This should be relatively static across runs,
	// ex. atlantis/plan or atlantis/apply.
	// description is a description of this particular status update and can
	// change across runs.
	// url is an optional link that users should click on for more information
	// about this status.
	UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error
	MergePull(pull models.PullRequest) error
	MarkdownPullLink(pull models.PullRequest) (string, error)

	// DownloadRepoConfigFile return `atlantis.yaml` content from VCS (which support fetch a single file from repository)
	// The first return value indicate that repo contain atlantis.yaml or not
	// if BaseRepo had one repo config file, its content will placed on the second return value
	DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)
	SupportsSingleFileDownload(repo models.Repo) bool
}

Client is used to make API calls to a VCS host like GitHub or GitLab.

type ClientProxy

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

ClientProxy proxies calls to the correct VCS client depending on which VCS host is required.

func NewClientProxy added in v0.5.0

func NewClientProxy(githubClient Client, gitlabClient Client, bitbucketCloudClient Client, bitbucketServerClient Client, azuredevopsClient Client) *ClientProxy

func (*ClientProxy) CreateComment

func (d *ClientProxy) CreateComment(repo models.Repo, pullNum int, comment string, command string) error

func (*ClientProxy) DownloadRepoConfigFile added in v0.15.0

func (d *ClientProxy) DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)

func (*ClientProxy) GetModifiedFiles

func (d *ClientProxy) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)

func (*ClientProxy) HidePrevPlanComments added in v0.12.0

func (d *ClientProxy) HidePrevPlanComments(repo models.Repo, pullNum int) error
func (d *ClientProxy) MarkdownPullLink(pull models.PullRequest) (string, error)

func (*ClientProxy) MergePull added in v0.4.14

func (d *ClientProxy) MergePull(pull models.PullRequest) error

func (*ClientProxy) PullIsApproved

func (d *ClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)

func (*ClientProxy) PullIsMergeable added in v0.4.13

func (d *ClientProxy) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)

func (*ClientProxy) SupportsSingleFileDownload added in v0.15.0

func (d *ClientProxy) SupportsSingleFileDownload(repo models.Repo) bool

func (*ClientProxy) UpdateStatus

func (d *ClientProxy) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

type GithubAnonymousCredentials added in v0.14.0

type GithubAnonymousCredentials struct{}

GithubAnonymousCredentials expose no credentials.

func (*GithubAnonymousCredentials) Client added in v0.14.0

func (c *GithubAnonymousCredentials) Client() (*http.Client, error)

Client returns a client with no credentials.

func (*GithubAnonymousCredentials) GetToken added in v0.14.0

func (c *GithubAnonymousCredentials) GetToken() (string, error)

GetToken returns an empty token.

func (*GithubAnonymousCredentials) GetUser added in v0.14.0

func (c *GithubAnonymousCredentials) GetUser() string

GetUser returns the username for these credentials.

type GithubAppCredentials added in v0.14.0

type GithubAppCredentials struct {
	AppID    int64
	KeyPath  string
	Hostname string
	// contains filtered or unexported fields
}

GithubAppCredentials implements GithubCredentials for github app installation token flow.

func (*GithubAppCredentials) Client added in v0.14.0

func (c *GithubAppCredentials) Client() (*http.Client, error)

Client returns a github app installation client.

func (*GithubAppCredentials) GetToken added in v0.14.0

func (c *GithubAppCredentials) GetToken() (string, error)

GetToken returns a fresh installation token.

func (*GithubAppCredentials) GetUser added in v0.14.0

func (c *GithubAppCredentials) GetUser() string

GetUser returns the username for these credentials.

type GithubAppTemporarySecrets added in v0.14.0

type GithubAppTemporarySecrets struct {
	// ID is the app id.
	ID int64
	// Key is the app's PEM-encoded key.
	Key string
	// Name is the app name.
	Name string
	// WebhookSecret is the generated webhook secret for this app.
	WebhookSecret string
	// URL is a link to the app, like https://github.com/apps/octoapp.
	URL string
}

GithubAppTemporarySecrets holds app credentials obtained from github after creation.

type GithubClient

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

GithubClient is used to perform GitHub actions.

func NewGithubClient

func NewGithubClient(hostname string, credentials GithubCredentials, logger *logging.SimpleLogger) (*GithubClient, error)

NewGithubClient returns a valid GitHub client.

func (*GithubClient) CreateComment

func (g *GithubClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error

CreateComment creates a comment on the pull request. If comment length is greater than the max comment length we split into multiple comments.

func (*GithubClient) DownloadRepoConfigFile added in v0.15.0

func (g *GithubClient) DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)

DownloadRepoConfigFile return `atlantis.yaml` content from VCS (which support fetch a single file from repository) The first return value indicate that repo contain atlantis.yaml or not if BaseRepo had one repo config file, its content will placed on the second return value

func (*GithubClient) ExchangeCode added in v0.14.0

func (g *GithubClient) ExchangeCode(code string) (*GithubAppTemporarySecrets, error)

ExchangeCode returns a newly created app's info

func (*GithubClient) GetModifiedFiles

func (g *GithubClient) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)

GetModifiedFiles returns the names of files that were modified in the pull request relative to the repo root, e.g. parent/child/file.txt.

func (*GithubClient) GetPullRequest

func (g *GithubClient) GetPullRequest(repo models.Repo, num int) (*github.PullRequest, error)

GetPullRequest returns the pull request.

func (*GithubClient) HidePrevPlanComments added in v0.12.0

func (g *GithubClient) HidePrevPlanComments(repo models.Repo, pullNum int) error
func (g *GithubClient) MarkdownPullLink(pull models.PullRequest) (string, error)

MarkdownPullLink specifies the string used in a pull request comment to reference another pull request.

func (*GithubClient) MergePull added in v0.4.14

func (g *GithubClient) MergePull(pull models.PullRequest) error

MergePull merges the pull request.

func (*GithubClient) PullIsApproved

func (g *GithubClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsApproved returns true if the pull request was approved.

func (*GithubClient) PullIsMergeable added in v0.4.13

func (g *GithubClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsMergeable returns true if the pull request is mergeable.

func (*GithubClient) SupportsSingleFileDownload added in v0.15.0

func (g *GithubClient) SupportsSingleFileDownload(repo models.Repo) bool

func (*GithubClient) UpdateStatus

func (g *GithubClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

UpdateStatus updates the status badge on the pull request. See https://github.com/blog/1227-commit-status-api.

type GithubCredentials added in v0.14.0

type GithubCredentials interface {
	Client() (*http.Client, error)
	GetToken() (string, error)
	GetUser() string
}

GithubCredentials handles creating http.Clients that authenticate.

type GithubUserCredentials added in v0.14.0

type GithubUserCredentials struct {
	User  string
	Token string
}

GithubUserCredentials implements GithubCredentials for the personal auth token flow.

func (*GithubUserCredentials) Client added in v0.14.0

func (c *GithubUserCredentials) Client() (*http.Client, error)

Client returns a client for basic auth user credentials.

func (*GithubUserCredentials) GetToken added in v0.14.0

func (c *GithubUserCredentials) GetToken() (string, error)

GetToken returns the user token.

func (*GithubUserCredentials) GetUser added in v0.14.0

func (c *GithubUserCredentials) GetUser() string

GetUser returns the username for these credentials.

type GitlabClient

type GitlabClient struct {
	Client *gitlab.Client
	// Version is set to the server version.
	Version *version.Version
}

func NewGitlabClient added in v0.4.12

func NewGitlabClient(hostname string, token string, logger *logging.SimpleLogger) (*GitlabClient, error)

NewGitlabClient returns a valid GitLab client.

func (*GitlabClient) CreateComment

func (g *GitlabClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error

CreateComment creates a comment on the merge request.

func (*GitlabClient) DownloadRepoConfigFile added in v0.15.0

func (g *GitlabClient) DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)

DownloadRepoConfigFile return `atlantis.yaml` content from VCS (which support fetch a single file from repository) The first return value indicate that repo contain atlantis.yaml or not if BaseRepo had one repo config file, its content will placed on the second return value

func (*GitlabClient) GetMergeRequest

func (g *GitlabClient) GetMergeRequest(repoFullName string, pullNum int) (*gitlab.MergeRequest, error)

func (*GitlabClient) GetModifiedFiles

func (g *GitlabClient) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)

GetModifiedFiles returns the names of files that were modified in the merge request relative to the repo root, e.g. parent/child/file.txt.

func (*GitlabClient) GetVersion added in v0.4.12

func (g *GitlabClient) GetVersion() (*version.Version, error)

GetVersion returns the version of the Gitlab server this client is using.

func (*GitlabClient) HidePrevPlanComments added in v0.12.0

func (g *GitlabClient) HidePrevPlanComments(repo models.Repo, pullNum int) error
func (g *GitlabClient) MarkdownPullLink(pull models.PullRequest) (string, error)

MarkdownPullLink specifies the string used in a pull request comment to reference another pull request.

func (*GitlabClient) MergePull added in v0.4.14

func (g *GitlabClient) MergePull(pull models.PullRequest) error

MergePull merges the merge request.

func (*GitlabClient) PullIsApproved

func (g *GitlabClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsApproved returns true if the merge request was approved.

func (*GitlabClient) PullIsMergeable added in v0.4.13

func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)

PullIsMergeable returns true if the merge request can be merged. In GitLab, there isn't a single field that tells us if the pull request is mergeable so for now we check the merge_status and approvals_before_merge fields. We aren't checking if there are unresolved discussions or failing pipelines because those only block merges if the repo is set to require that. In order to check if the repo required these, we'd need to make another API call to get the repo settings. For now I'm going to leave this as is and if some users require checking this as well then we can revisit. It's also possible that GitLab implements their own "mergeable" field in their API in the future. See: - https://gitlab.com/gitlab-org/gitlab-ee/issues/3169 - https://gitlab.com/gitlab-org/gitlab-ce/issues/42344

func (*GitlabClient) SupportsCommonMark added in v0.4.12

func (g *GitlabClient) SupportsCommonMark() bool

SupportsCommonMark returns true if the version of Gitlab this client is using supports the CommonMark markdown format.

func (*GitlabClient) SupportsSingleFileDownload added in v0.15.0

func (g *GitlabClient) SupportsSingleFileDownload(repo models.Repo) bool

func (*GitlabClient) UpdateStatus

func (g *GitlabClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

UpdateStatus updates the build status of a commit.

type NotConfiguredVCSClient

type NotConfiguredVCSClient struct {
	Host models.VCSHostType
}

NotConfiguredVCSClient is used as a placeholder when Atlantis isn't configured on startup to support a certain VCS host. For example, if there is no GitHub config then this client will be used which will error if it's ever called.

func (*NotConfiguredVCSClient) CreateComment

func (a *NotConfiguredVCSClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error

func (*NotConfiguredVCSClient) DownloadRepoConfigFile added in v0.15.0

func (a *NotConfiguredVCSClient) DownloadRepoConfigFile(pull models.PullRequest) (bool, []byte, error)

func (*NotConfiguredVCSClient) GetModifiedFiles

func (a *NotConfiguredVCSClient) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)

func (*NotConfiguredVCSClient) HidePrevPlanComments added in v0.12.0

func (a *NotConfiguredVCSClient) HidePrevPlanComments(repo models.Repo, pullNum int) error
func (a *NotConfiguredVCSClient) MarkdownPullLink(pull models.PullRequest) (string, error)

func (*NotConfiguredVCSClient) MergePull added in v0.4.14

func (a *NotConfiguredVCSClient) MergePull(pull models.PullRequest) error

func (*NotConfiguredVCSClient) PullIsApproved

func (a *NotConfiguredVCSClient) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)

func (*NotConfiguredVCSClient) PullIsMergeable added in v0.4.13

func (a *NotConfiguredVCSClient) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)

func (*NotConfiguredVCSClient) SupportsSingleFileDownload added in v0.15.0

func (a *NotConfiguredVCSClient) SupportsSingleFileDownload(repo models.Repo) bool

func (*NotConfiguredVCSClient) UpdateStatus

func (a *NotConfiguredVCSClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

Directories

Path Synopsis
Package bitbucketcloud holds code for Bitbucket Cloud aka (bitbucket.org).
Package bitbucketcloud holds code for Bitbucket Cloud aka (bitbucket.org).
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.
matchers
Code generated by pegomock.
Code generated by pegomock.

Jump to

Keyboard shortcuts

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