Skip to content

Commit

Permalink
fix: rename flag to ignore-vcs-status-names per suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
bakayolo committed Oct 4, 2024
1 parent 8a5ac11 commit 69ea14f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const (
UseTFPluginCache = "use-tf-plugin-cache"
VarFileAllowlistFlag = "var-file-allowlist"
VCSStatusName = "vcs-status-name"
OtherVCSStatusNamesToIgnore = "other-vcs-status-names-to-ignore"
IgnoreVCSStatusNames = "ignore-vcs-status-names"
TFEHostnameFlag = "tfe-hostname"
TFELocalExecutionModeFlag = "tfe-local-execution-mode"
TFETokenFlag = "tfe-token"
Expand Down Expand Up @@ -176,7 +176,7 @@ const (
DefaultGitlabHostname = "gitlab.com"
DefaultLockingDBType = "boltdb"
DefaultLogLevel = "info"
DefaultOtherVCSStatusNamesToIgnore = ""
DefaultIgnoreVCSStatusNames = ""
DefaultMaxCommentsPerCommand = 100
DefaultParallelPoolSize = 15
DefaultStatsNamespace = "atlantis"
Expand Down Expand Up @@ -441,9 +441,9 @@ var stringFlags = map[string]stringFlag{
description: "Comma-separated list of additional paths where variable definition files can be read from." +
" If this argument is not provided, it defaults to Atlantis' data directory, determined by the --data-dir argument.",
},
OtherVCSStatusNamesToIgnore: {
IgnoreVCSStatusNames: {
description: "Comma-separated list of other Atlantis servers to ignore for pull request statuses.",
defaultValue: DefaultOtherVCSStatusNamesToIgnore,
defaultValue: DefaultIgnoreVCSStatusNames,
},
VCSStatusName: {
description: "Name used to identify Atlantis for pull request statuses.",
Expand Down Expand Up @@ -924,8 +924,8 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig, v *viper.Viper) {
if c.VCSStatusName == "" {
c.VCSStatusName = DefaultVCSStatusName
}
if c.OtherVCSStatusNamesToIgnore == "" {
c.OtherVCSStatusNamesToIgnore = DefaultOtherVCSStatusNamesToIgnore
if c.IgnoreVCSStatusNames == "" {
c.IgnoreVCSStatusNames = DefaultIgnoreVCSStatusNames
}
if c.TFEHostname == "" {
c.TFEHostname = DefaultTFEHostname
Expand Down
2 changes: 1 addition & 1 deletion cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var testFlags = map[string]interface{}{
UseTFPluginCache: true,
VarFileAllowlistFlag: "/path",
VCSStatusName: "my-status",
OtherVCSStatusNamesToIgnore: "",
IgnoreVCSStatusNames: "",
WebBasicAuthFlag: false,
WebPasswordFlag: "atlantis",
WebUsernameFlag: "atlantis",
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Client interface {
ReactToComment(logger logging.SimpleLogging, repo models.Repo, pullNum int, commentID int64, reaction string) error
HidePrevCommandComments(logger logging.SimpleLogging, repo models.Repo, pullNum int, command string, dir string) error
PullIsApproved(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error)
PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, otherStatusNamesToIgnore []string) (bool, error)
PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (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.
Expand Down
22 changes: 11 additions & 11 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,16 @@ func CheckRunPassed(checkRun CheckRun) bool {
return checkRun.Conclusion == "SUCCESS" || checkRun.Conclusion == "SKIPPED" || checkRun.Conclusion == "NEUTRAL"
}

func StatusContextPassed(statusContext StatusContext, vcsstatusname string, otherStatusNamesToIgnore []string) bool {
func StatusContextPassed(statusContext StatusContext, vcsstatusname string, ignoreVCSStatusNames []string) bool {
// iterates through the list of other status names that were set to be ignored, allowing other atlantis servers
// to not be considered when determining if the status context is successful
otherStatusNamesOK := false
if len(otherStatusNamesToIgnore) > 0 {
if len(ignoreVCSStatusNames) > 0 {
otherStatusNamesOK = true
}
for _, otherStatusNameToIgnore := range otherStatusNamesToIgnore {
if !strings.HasPrefix(string(statusContext.Context), fmt.Sprintf("%s/%s", otherStatusNameToIgnore, command.Plan.String())) ||
!strings.HasPrefix(string(statusContext.Context), fmt.Sprintf("%s/%s", otherStatusNameToIgnore, command.Apply.String())) {
for _, ignoreVCSStatusName := range ignoreVCSStatusNames {
if !strings.HasPrefix(string(statusContext.Context), fmt.Sprintf("%s/%s", ignoreVCSStatusName, command.Plan.String())) ||
!strings.HasPrefix(string(statusContext.Context), fmt.Sprintf("%s/%s", ignoreVCSStatusName, command.Apply.String())) {
otherStatusNamesOK = false
break
}
Expand All @@ -727,7 +727,7 @@ func StatusContextPassed(statusContext StatusContext, vcsstatusname string, othe
statusContext.State == "SUCCESS" || otherStatusNamesOK
}

func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun, statusContexts []StatusContext, vcsstatusname string, otherStatusNamesToIgnore []string) bool {
func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun, statusContexts []StatusContext, vcsstatusname string, ignoreVCSStatusNames []string) bool {
for _, checkRun := range checkRuns {
if checkRun.Name == expectedContext {
return CheckRunPassed(checkRun)
Expand All @@ -736,7 +736,7 @@ func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun,

for _, statusContext := range statusContexts {
if statusContext.Context == expectedContext {
return StatusContextPassed(statusContext, vcsstatusname, otherStatusNamesToIgnore)
return StatusContextPassed(statusContext, vcsstatusname, ignoreVCSStatusNames)
}
}

Expand All @@ -761,7 +761,7 @@ func (g *GithubClient) ExpectedWorkflowPassed(expectedWorkflow WorkflowFileRefer
}

// IsMergeableMinusApply checks review decision (which takes into account CODEOWNERS) and required checks for PR (excluding the atlantis apply check).
func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo models.Repo, pull *github.PullRequest, vcsstatusname string, otherStatusNamesToIgnore []string) (bool, error) {
func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo models.Repo, pull *github.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (bool, error) {
if pull.Number == nil {
return false, errors.New("pull request number is nil")
}
Expand All @@ -784,7 +784,7 @@ func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo
// Go through all checks and workflows required by branch protection or rulesets
// Make sure that they can all be found in the statusCheckRollup and that they all pass
for _, requiredCheck := range requiredChecks {
if !ExpectedCheckPassed(requiredCheck, checkRuns, statusContexts, vcsstatusname, otherStatusNamesToIgnore) {
if !ExpectedCheckPassed(requiredCheck, checkRuns, statusContexts, vcsstatusname, ignoreVCSStatusNames) {
logger.Debug("%s: Expected Required Check: %s", notMergeablePrefix, requiredCheck)
return false, nil
}
Expand All @@ -804,7 +804,7 @@ func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo
}

// PullIsMergeable returns true if the pull request is mergeable.
func (g *GithubClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, otherStatusNamesToIgnore []string) (bool, error) {
func (g *GithubClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (bool, error) {
logger.Debug("Checking if GitHub pull request %d is mergeable", pull.Num)
githubPR, err := g.GetPullRequest(logger, repo, pull.Num)
if err != nil {
Expand All @@ -826,7 +826,7 @@ func (g *GithubClient) PullIsMergeable(logger logging.SimpleLogging, repo models
case "blocked":
if g.config.AllowMergeableBypassApply {
logger.Debug("AllowMergeableBypassApply feature flag is enabled - attempting to bypass apply from mergeable requirements")
isMergeableMinusApply, err := g.IsMergeableMinusApply(logger, repo, githubPR, vcsstatusname, otherStatusNamesToIgnore)
isMergeableMinusApply, err := g.IsMergeableMinusApply(logger, repo, githubPR, vcsstatusname, ignoreVCSStatusNames)
if err != nil {
return false, errors.Wrap(err, "getting pull request status")
}
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (c *InstrumentedClient) PullIsApproved(logger logging.SimpleLogging, repo m
return approved, err
}

func (c *InstrumentedClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, otherStatusNamesToIgnore []string) (bool, error) {
func (c *InstrumentedClient) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (bool, error) {
scope := c.StatsScope.SubScope("pull_is_mergeable")
scope = SetGitScopeTags(scope, repo.FullName, pull.Num)

Expand All @@ -193,7 +193,7 @@ func (c *InstrumentedClient) PullIsMergeable(logger logging.SimpleLogging, repo
executionSuccess := scope.Counter(metrics.ExecutionSuccessMetric)
executionError := scope.Counter(metrics.ExecutionErrorMetric)

mergeable, err := c.Client.PullIsMergeable(logger, repo, pull, vcsstatusname, otherStatusNamesToIgnore)
mergeable, err := c.Client.PullIsMergeable(logger, repo, pull, vcsstatusname, ignoreVCSStatusNames)

if err != nil {
executionError.Inc(1)
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/events/vcs/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func (d *ClientProxy) DiscardReviews(repo models.Repo, pull models.PullRequest)
return d.clients[repo.VCSHost.Type].DiscardReviews(repo, pull)
}

func (d *ClientProxy) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, otherStatusNamesToIgnore []string) (bool, error) {
return d.clients[repo.VCSHost.Type].PullIsMergeable(logger, repo, pull, vcsstatusname, otherStatusNamesToIgnore)
func (d *ClientProxy) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (bool, error) {
return d.clients[repo.VCSHost.Type].PullIsMergeable(logger, repo, pull, vcsstatusname, ignoreVCSStatusNames)
}

func (d *ClientProxy) UpdateStatus(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error {
Expand Down
16 changes: 8 additions & 8 deletions server/events/vcs/pull_status_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ type PullReqStatusFetcher interface {
}

type pullReqStatusFetcher struct {
client Client
vcsStatusName string
otherStatusNamesToIgnore []string
client Client
vcsStatusName string
ignoreVCSStatusNames []string
}

func NewPullReqStatusFetcher(client Client, vcsStatusName string, otherStatusNamesToIgnore []string) PullReqStatusFetcher {
func NewPullReqStatusFetcher(client Client, vcsStatusName string, ignoreVCSStatusNames []string) PullReqStatusFetcher {
return &pullReqStatusFetcher{
client: client,
vcsStatusName: vcsStatusName,
otherStatusNamesToIgnore: otherStatusNamesToIgnore,
client: client,
vcsStatusName: vcsStatusName,
ignoreVCSStatusNames: ignoreVCSStatusNames,
}
}

Expand All @@ -32,7 +32,7 @@ func (f *pullReqStatusFetcher) FetchPullStatus(logger logging.SimpleLogging, pul
return pullStatus, errors.Wrapf(err, "fetching pull approval status for repo: %s, and pull number: %d", pull.BaseRepo.FullName, pull.Num)
}

mergeable, err := f.client.PullIsMergeable(logger, pull.BaseRepo, pull, f.vcsStatusName, f.otherStatusNamesToIgnore)
mergeable, err := f.client.PullIsMergeable(logger, pull.BaseRepo, pull, f.vcsStatusName, f.ignoreVCSStatusNames)
if err != nil {
return pullStatus, errors.Wrapf(err, "fetching mergeability status for repo: %s, and pull number: %d", pull.BaseRepo.FullName, pull.Num)
}
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
userConfig.QuietPolicyChecks,
)

pullReqStatusFetcher := vcs.NewPullReqStatusFetcher(vcsClient, userConfig.VCSStatusName, strings.Split(userConfig.OtherVCSStatusNamesToIgnore, ","))
pullReqStatusFetcher := vcs.NewPullReqStatusFetcher(vcsClient, userConfig.VCSStatusName, strings.Split(userConfig.IgnoreVCSStatusNames, ","))
planCommandRunner := events.NewPlanCommandRunner(
userConfig.SilenceVCSStatusNoPlans,
userConfig.SilenceVCSStatusNoProjects,
Expand Down
2 changes: 1 addition & 1 deletion server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type UserConfig struct {
LogLevel string `mapstructure:"log-level"`
MarkdownTemplateOverridesDir string `mapstructure:"markdown-template-overrides-dir"`
MaxCommentsPerCommand int `mapstructure:"max-comments-per-command"`
OtherVCSStatusNamesToIgnore string `mapstructure:"other-vcs-status-names-to-ignore"`
IgnoreVCSStatusNames string `mapstructure:"ignore-vcs-status-names"`
ParallelPoolSize int `mapstructure:"parallel-pool-size"`
ParallelPlan bool `mapstructure:"parallel-plan"`
ParallelApply bool `mapstructure:"parallel-apply"`
Expand Down

0 comments on commit 69ea14f

Please sign in to comment.