Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for autoplanning on draft PR #1008

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
GitlabWebhookSecretFlag = "gitlab-webhook-secret" // nolint: gosec
HidePrevPlanComments = "hide-prev-plan-comments"
LogLevelFlag = "log-level"
PlanDrafts = "plan-drafts"
PortFlag = "port"
RepoConfigFlag = "repo-config"
RepoConfigJSONFlag = "repo-config-json"
Expand Down Expand Up @@ -258,6 +259,10 @@ var boolFlags = map[string]boolFlag{
"VCS support is limited to: GitHub.",
defaultValue: false,
},
PlanDrafts: {
description: "Enable autoplan for Github Draft Pull Requests",
defaultValue: false,
},
RequireApprovalFlag: {
description: "Require pull requests to be \"Approved\" before allowing the apply command to be run.",
defaultValue: false,
Expand Down
1 change: 1 addition & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var testFlags = map[string]interface{}{
GitlabUserFlag: "gitlab-user",
GitlabWebhookSecretFlag: "gitlab-secret",
LogLevelFlag: "debug",
PlanDrafts: true,
PortFlag: 8181,
RepoWhitelistFlag: "github.com/runatlantis/atlantis",
RequireApprovalFlag: true,
Expand Down
3 changes: 2 additions & 1 deletion server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ type EventParser struct {
GithubToken string
GitlabUser string
GitlabToken string
PlanDrafts bool
BitbucketUser string
BitbucketToken string
BitbucketServerURL string
Expand Down Expand Up @@ -417,7 +418,7 @@ func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
return
}

if pullEvent.GetPullRequest().GetDraft() {
if !e.PlanDrafts && pullEvent.GetPullRequest().GetDraft() {
// if the PR is in draft state we don't care about the action type
// we can set the type to Other and ignore the PR
pullEventType = models.OtherPullEvent
Expand Down
8 changes: 7 additions & 1 deletion server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var parser = events.EventParser{
GithubToken: "github-token",
GitlabUser: "gitlab-user",
GitlabToken: "gitlab-token",
PlanDrafts: false,
BitbucketUser: "bitbucket-user",
BitbucketToken: "bitbucket-token",
BitbucketServerURL: "http://mycorp.com:7490",
Expand Down Expand Up @@ -161,13 +162,18 @@ func TestParseGithubPullEvent(t *testing.T) {
}

func TestParseGithubPullEventFromDraft(t *testing.T) {
// verify that draft PRs are treated as 'other' events
// 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.PlanDrafts = true
_, evType, _, _, _, err = parser.ParseGithubPullEvent(&testEvent)
Ok(t, err)
Equals(t, models.OpenedPullEvent, evType)
}

func TestParseGithubPullEvent_EventType(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
GithubToken: userConfig.GithubToken,
GitlabUser: userConfig.GitlabUser,
GitlabToken: userConfig.GitlabToken,
PlanDrafts: userConfig.PlanDrafts,
BitbucketUser: userConfig.BitbucketUser,
BitbucketToken: userConfig.BitbucketToken,
BitbucketServerURL: userConfig.BitbucketBaseURL,
Expand Down
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"plan-drafts"`
Port int `mapstructure:"port"`
RepoConfig string `mapstructure:"repo-config"`
RepoConfigJSON string `mapstructure:"repo-config-json"`
Expand Down