-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: Add ability to set pr status context with --status-name flag #841
Changes from all commits
6583d8c
17c2b7e
5399493
3c03db2
586c796
c670c85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -72,6 +72,7 @@ const ( | |||||
SlackTokenFlag = "slack-token" | ||||||
SSLCertFileFlag = "ssl-cert-file" | ||||||
SSLKeyFileFlag = "ssl-key-file" | ||||||
StatusName = "status-name" | ||||||
TFEHostnameFlag = "tfe-hostname" | ||||||
TFETokenFlag = "tfe-token" | ||||||
WriteGitCredsFlag = "write-git-creds" | ||||||
|
@@ -87,6 +88,7 @@ const ( | |||||
DefaultLogLevel = "info" | ||||||
DefaultPort = 4141 | ||||||
DefaultTFEHostname = "app.terraform.io" | ||||||
DefaultStatusName = "atlantis" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
|
||||||
var stringFlags = map[string]stringFlag{ | ||||||
|
@@ -202,6 +204,10 @@ var stringFlags = map[string]stringFlag{ | |||||
SSLKeyFileFlag: { | ||||||
description: fmt.Sprintf("File containing x509 private key matching --%s.", SSLCertFileFlag), | ||||||
}, | ||||||
StatusName: { | ||||||
description: "Name used for updating the pull request status.", | ||||||
defaultValue: DefaultStatusName, | ||||||
}, | ||||||
TFEHostnameFlag: { | ||||||
description: "Hostname of your Terraform Enterprise installation. If using Terraform Cloud no need to set.", | ||||||
defaultValue: DefaultTFEHostname, | ||||||
|
@@ -454,6 +460,9 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig) { | |||||
if c.Port == 0 { | ||||||
c.Port = DefaultPort | ||||||
} | ||||||
if c.StatusName == "" { | ||||||
c.StatusName = DefaultStatusName | ||||||
} | ||||||
if c.TFEHostname == "" { | ||||||
c.TFEHostname = DefaultTFEHostname | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,7 @@ func TestExecute_Defaults(t *testing.T) { | |
Equals(t, "", passedConfig.SlackToken) | ||
Equals(t, "", passedConfig.SSLCertFile) | ||
Equals(t, "", passedConfig.SSLKeyFile) | ||
Equals(t, "atlantis", passedConfig.StatusName) | ||
Equals(t, "app.terraform.io", passedConfig.TFEHostname) | ||
Equals(t, "", passedConfig.TFEToken) | ||
Equals(t, false, passedConfig.WriteGitCreds) | ||
|
@@ -719,6 +720,7 @@ write-git-creds: true | |
"TFE_HOSTNAME": "override-my-hostname", | ||
"TFE_TOKEN": "override-my-token", | ||
"WRITE_GIT_CREDS": "false", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed adding |
||
"STATUS_NAME": "override-status-name", | ||
} { | ||
os.Setenv("ATLANTIS_"+name, value) // nolint: errcheck | ||
} | ||
|
@@ -762,6 +764,7 @@ write-git-creds: true | |
Equals(t, "override-my-hostname", passedConfig.TFEHostname) | ||
Equals(t, "override-my-token", passedConfig.TFEToken) | ||
Equals(t, false, passedConfig.WriteGitCreds) | ||
Equals(t, "override-status-name", passedConfig.StatusName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to add |
||
} | ||
|
||
func TestExecute_FlagConfigOverride(t *testing.T) { | ||
|
@@ -799,6 +802,7 @@ require-mergeable: true | |
slack-token: slack-token | ||
ssl-cert-file: cert-file | ||
ssl-key-file: key-file | ||
status-name: status-name | ||
tfe-hostname: my-hostname | ||
tfe-token: my-token | ||
write-git-creds: true | ||
|
@@ -838,6 +842,7 @@ write-git-creds: true | |
cmd.SlackTokenFlag: "override-slack-token", | ||
cmd.SSLCertFileFlag: "override-cert-file", | ||
cmd.SSLKeyFileFlag: "override-key-file", | ||
cmd.StatusName: "override-status-name", | ||
cmd.TFEHostnameFlag: "override-my-hostname", | ||
cmd.TFETokenFlag: "override-my-token", | ||
cmd.WriteGitCredsFlag: false, | ||
|
@@ -875,6 +880,7 @@ write-git-creds: true | |
Equals(t, "override-slack-token", passedConfig.SlackToken) | ||
Equals(t, "override-cert-file", passedConfig.SSLCertFile) | ||
Equals(t, "override-key-file", passedConfig.SSLKeyFile) | ||
Equals(t, "override-status-name", passedConfig.StatusName) | ||
Equals(t, "override-my-hostname", passedConfig.TFEHostname) | ||
Equals(t, "override-my-token", passedConfig.TFEToken) | ||
Equals(t, false, passedConfig.WriteGitCreds) | ||
|
@@ -917,6 +923,7 @@ func TestExecute_FlagEnvVarOverride(t *testing.T) { | |
"SLACK_TOKEN": "slack-token", | ||
"SSL_CERT_FILE": "cert-file", | ||
"SSL_KEY_FILE": "key-file", | ||
"STATUS_NAME": "status-name", | ||
"TFE_HOSTNAME": "my-hostname", | ||
"TFE_TOKEN": "my-token", | ||
"WRITE_GIT_CREDS": "true", | ||
|
@@ -964,6 +971,7 @@ func TestExecute_FlagEnvVarOverride(t *testing.T) { | |
cmd.SlackTokenFlag: "override-slack-token", | ||
cmd.SSLCertFileFlag: "override-cert-file", | ||
cmd.SSLKeyFileFlag: "override-key-file", | ||
cmd.StatusName: "override-status-name", | ||
cmd.TFEHostnameFlag: "override-my-hostname", | ||
cmd.TFETokenFlag: "override-my-token", | ||
cmd.WriteGitCredsFlag: false, | ||
|
@@ -1003,6 +1011,7 @@ func TestExecute_FlagEnvVarOverride(t *testing.T) { | |
Equals(t, "override-slack-token", passedConfig.SlackToken) | ||
Equals(t, "override-cert-file", passedConfig.SSLCertFile) | ||
Equals(t, "override-key-file", passedConfig.SSLKeyFile) | ||
Equals(t, "override-status-name", passedConfig.StatusName) | ||
Equals(t, "override-my-hostname", passedConfig.TFEHostname) | ||
Equals(t, "override-my-token", passedConfig.TFEToken) | ||
Equals(t, false, passedConfig.WriteGitCreds) | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -39,11 +39,12 @@ type CommitStatusUpdater interface { | |||||||
|
||||||||
// DefaultCommitStatusUpdater implements CommitStatusUpdater. | ||||||||
type DefaultCommitStatusUpdater struct { | ||||||||
Client vcs.Client | ||||||||
Client vcs.Client | ||||||||
StatusName string | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) error { | ||||||||
src := fmt.Sprintf("atlantis/%s", command.String()) | ||||||||
src := fmt.Sprintf("%s/%s", d.StatusName, command.String()) | ||||||||
var descripWords string | ||||||||
switch status { | ||||||||
case models.PendingCommitStatus: | ||||||||
|
@@ -58,7 +59,7 @@ func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model | |||||||
} | ||||||||
|
||||||||
func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) error { | ||||||||
src := fmt.Sprintf("atlantis/%s", command.String()) | ||||||||
src := fmt.Sprintf("%s/%s", d.StatusName, command.String()) | ||||||||
cmdVerb := "planned" | ||||||||
if command == models.ApplyCommand { | ||||||||
cmdVerb = "applied" | ||||||||
|
@@ -71,7 +72,7 @@ func (d *DefaultCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandCont | |||||||
if projectID == "" { | ||||||||
projectID = fmt.Sprintf("%s/%s", ctx.RepoRelDir, ctx.Workspace) | ||||||||
} | ||||||||
src := fmt.Sprintf("atlantis/%s: %s", cmdName.String(), projectID) | ||||||||
src := fmt.Sprintf("%s/%s: %s", d.StatusName, cmdName.String(), projectID) | ||||||||
var descripWords string | ||||||||
switch status { | ||||||||
case models.PendingCommitStatus: | ||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,12 @@ | |
package events_test | ||
|
||
import ( | ||
"github.com/hashicorp/go-version" | ||
"github.com/runatlantis/atlantis/server/events/runtime" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/runatlantis/atlantis/server/events/runtime" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra newline |
||
. "github.com/petergtz/pegomock" | ||
"github.com/runatlantis/atlantis/server/events" | ||
"github.com/runatlantis/atlantis/server/events/mocks" | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,6 +44,7 @@ type UserConfig struct { | |||||
SlackToken string `mapstructure:"slack-token"` | ||||||
SSLCertFile string `mapstructure:"ssl-cert-file"` | ||||||
SSLKeyFile string `mapstructure:"ssl-key-file"` | ||||||
StatusName string `mapstructure:"status-name"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
TFEHostname string `mapstructure:"tfe-hostname"` | ||||||
TFEToken string `mapstructure:"tfe-token"` | ||||||
DefaultTFVersion string `mapstructure:"default-tf-version"` | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding PR will save some confusion as to what status we're talking about.