mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-05 07:38:36 +00:00
@@ -64,6 +64,7 @@ const (
|
||||
GitlabWebhookSecretFlag = "gitlab-webhook-secret" // nolint: gosec
|
||||
HidePrevPlanComments = "hide-prev-plan-comments"
|
||||
LogLevelFlag = "log-level"
|
||||
AllowDraftPRs = "allow-draft-prs"
|
||||
PortFlag = "port"
|
||||
RepoConfigFlag = "repo-config"
|
||||
RepoConfigJSONFlag = "repo-config-json"
|
||||
@@ -253,6 +254,10 @@ var boolFlags = map[string]boolFlag{
|
||||
description: "Disable \"atlantis apply\" command so a specific project/workspace/directory has to be specified for applies.",
|
||||
defaultValue: false,
|
||||
},
|
||||
AllowDraftPRs: {
|
||||
description: "Enable autoplan for Github Draft Pull Requests",
|
||||
defaultValue: false,
|
||||
},
|
||||
HidePrevPlanComments: {
|
||||
description: "Hide previous plan comments to reduce clutter in the PR. " +
|
||||
"VCS support is limited to: GitHub.",
|
||||
|
||||
@@ -75,6 +75,7 @@ var testFlags = map[string]interface{}{
|
||||
GitlabUserFlag: "gitlab-user",
|
||||
GitlabWebhookSecretFlag: "gitlab-secret",
|
||||
LogLevelFlag: "debug",
|
||||
AllowDraftPRs: true,
|
||||
PortFlag: 8181,
|
||||
RepoWhitelistFlag: "github.com/runatlantis/atlantis",
|
||||
RequireApprovalFlag: true,
|
||||
|
||||
@@ -266,6 +266,7 @@ type EventParser struct {
|
||||
GithubToken string
|
||||
GitlabUser string
|
||||
GitlabToken string
|
||||
AllowDraftPRs bool
|
||||
BitbucketUser string
|
||||
BitbucketToken string
|
||||
BitbucketServerURL string
|
||||
@@ -418,11 +419,11 @@ func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
|
||||
}
|
||||
|
||||
if pullEvent.GetPullRequest().GetDraft() {
|
||||
// if the PR is in draft state we do not initiate actions proactively however,
|
||||
// we must still clean up locks in the event of a user initiated plan
|
||||
// Even if the PR is in draft state users can manually run plan or may
|
||||
// be using the -allow-draft-prs flag. If so then we need to ensure locks are cleaned up.
|
||||
if pullEvent.GetAction() == "closed" {
|
||||
pullEventType = models.ClosedPullEvent
|
||||
} else {
|
||||
} else if !e.AllowDraftPRs {
|
||||
pullEventType = models.OtherPullEvent
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -36,6 +36,7 @@ var parser = events.EventParser{
|
||||
GithubToken: "github-token",
|
||||
GitlabUser: "gitlab-user",
|
||||
GitlabToken: "gitlab-token",
|
||||
AllowDraftPRs: false,
|
||||
BitbucketUser: "bitbucket-user",
|
||||
BitbucketToken: "bitbucket-token",
|
||||
BitbucketServerURL: "http://mycorp.com:7490",
|
||||
@@ -160,6 +161,22 @@ func TestParseGithubPullEvent(t *testing.T) {
|
||||
Equals(t, models.User{Username: "user"}, actUser)
|
||||
}
|
||||
|
||||
func TestParseGithubPullEventFromDraft(t *testing.T) {
|
||||
// verify that draft PRs are treated as 'other' events by default
|
||||
testEvent := deepcopy.Copy(PullEvent).(github.PullRequestEvent)
|
||||
draftPR := true
|
||||
testEvent.PullRequest.Draft = &draftPR
|
||||
_, evType, _, _, _, err := parser.ParseGithubPullEvent(&testEvent)
|
||||
Ok(t, err)
|
||||
Equals(t, models.OtherPullEvent, evType)
|
||||
// verify that drafts are planned if requested
|
||||
parser.AllowDraftPRs = true
|
||||
defer func() { parser.AllowDraftPRs = false }()
|
||||
_, evType, _, _, _, err = parser.ParseGithubPullEvent(&testEvent)
|
||||
Ok(t, err)
|
||||
Equals(t, models.OpenedPullEvent, evType)
|
||||
}
|
||||
|
||||
func TestParseGithubPullEvent_EventType(t *testing.T) {
|
||||
cases := []struct {
|
||||
action string
|
||||
|
||||
@@ -290,6 +290,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
|
||||
GithubToken: userConfig.GithubToken,
|
||||
GitlabUser: userConfig.GitlabUser,
|
||||
GitlabToken: userConfig.GitlabToken,
|
||||
AllowDraftPRs: userConfig.PlanDrafts,
|
||||
BitbucketUser: userConfig.BitbucketUser,
|
||||
BitbucketToken: userConfig.BitbucketToken,
|
||||
BitbucketServerURL: userConfig.BitbucketBaseURL,
|
||||
|
||||
@@ -34,6 +34,7 @@ type UserConfig struct {
|
||||
GitlabWebhookSecret string `mapstructure:"gitlab-webhook-secret"`
|
||||
HidePrevPlanComments bool `mapstructure:"hide-prev-plan-comments"`
|
||||
LogLevel string `mapstructure:"log-level"`
|
||||
PlanDrafts bool `mapstructure:"allow-draft-prs"`
|
||||
Port int `mapstructure:"port"`
|
||||
RepoConfig string `mapstructure:"repo-config"`
|
||||
RepoConfigJSON string `mapstructure:"repo-config-json"`
|
||||
|
||||
Reference in New Issue
Block a user