Skip to content

Commit c890c9c

Browse files
committed
clean up feature allocation since its always true now
1 parent 0c16f78 commit c890c9c

File tree

6 files changed

+19
-299
lines changed

6 files changed

+19
-299
lines changed

server/legacy/events/policy_filter.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ func (p *ApprovedPolicyFilter) Filter(ctx context.Context, installationToken int
5858
return failedPolicies, nil
5959
}
6060

61-
// Dismiss PR reviews when event came from pull request change/atlantis plan comment
62-
if trigger == command.AutoTrigger || trigger == command.CommentTrigger {
63-
err := p.dismissStalePRReviews(ctx, installationToken, repo, prNum)
64-
if err != nil {
65-
return failedPolicies, errors.Wrap(err, "failed to dismiss stale PR reviews")
66-
}
67-
return failedPolicies, nil
68-
}
69-
7061
// Fetch reviewers who approved the PR
7162
approvedReviewers, err := p.prReviewFetcher.ListLatestApprovalUsernames(ctx, installationToken, repo, prNum)
7263
if err != nil {
@@ -87,39 +78,6 @@ func (p *ApprovedPolicyFilter) Filter(ctx context.Context, installationToken int
8778
return filteredFailedPolicies, nil
8879
}
8980

90-
func (p *ApprovedPolicyFilter) dismissStalePRReviews(ctx context.Context, installationToken int64, repo models.Repo, prNum int) error {
91-
shouldAllocate, err := p.allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
92-
RepoName: repo.FullName,
93-
})
94-
if err != nil {
95-
return errors.Wrap(err, "unable to allocate legacy deprecation feature flag")
96-
}
97-
// if legacy deprecation is enabled, don't dismiss stale PR reviews in legacy workflow
98-
if shouldAllocate {
99-
p.logger.InfoContext(ctx, "legacy deprecation feature flag enabled, not dismissing stale PR reviews")
100-
return nil
101-
}
102-
103-
approvalReviews, err := p.prReviewFetcher.ListApprovalReviews(ctx, installationToken, repo, prNum)
104-
if err != nil {
105-
return errors.Wrap(err, "failed to fetch GH PR reviews")
106-
}
107-
108-
for _, approval := range approvalReviews {
109-
isOwner, err := p.approverIsOwner(ctx, installationToken, approval)
110-
if err != nil {
111-
return errors.Wrap(err, "failed to validate approver is owner")
112-
}
113-
if isOwner {
114-
err = p.prReviewDismisser.Dismiss(ctx, installationToken, repo, prNum, approval.GetID())
115-
if err != nil {
116-
return errors.Wrap(err, "failed to dismiss GH PR reviews")
117-
}
118-
}
119-
}
120-
return nil
121-
}
122-
12381
func (p *ApprovedPolicyFilter) approverIsOwner(ctx context.Context, installationToken int64, approval *gh.PullRequestReview) (bool, error) {
12482
if approval.GetUser() == nil {
12583
return false, errors.New("failed to identify approver")

server/legacy/events/pr_project_context_builder.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package events
22

33
import (
4-
"fmt"
5-
64
"github.com/runatlantis/atlantis/server/config/valid"
75
"github.com/runatlantis/atlantis/server/legacy/events/command"
86
"github.com/runatlantis/atlantis/server/logging"
@@ -38,23 +36,14 @@ func (p *PlatformModeProjectContextBuilder) BuildProjectContext(
3836
repoDir string,
3937
contextFlags *command.ContextFlags,
4038
) []command.ProjectContext {
41-
shouldAllocate, err := p.allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
42-
if err != nil {
43-
p.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
44-
}
45-
46-
if shouldAllocate {
47-
return buildContext(
48-
ctx,
49-
cmdName,
50-
getSteps(cmdName, prjCfg.PullRequestWorkflow, contextFlags.LogLevel),
51-
p.CommentBuilder,
52-
prjCfg,
53-
commentArgs,
54-
repoDir,
55-
contextFlags,
56-
)
57-
}
58-
59-
return p.delegate.BuildProjectContext(ctx, cmdName, prjCfg, commentArgs, repoDir, contextFlags)
39+
return buildContext(
40+
ctx,
41+
cmdName,
42+
getSteps(cmdName, prjCfg.PullRequestWorkflow, contextFlags.LogLevel),
43+
p.CommentBuilder,
44+
prjCfg,
45+
commentArgs,
46+
repoDir,
47+
contextFlags,
48+
)
6049
}

server/legacy/events/vcs/github_client.go

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"encoding/base64"
1919
"fmt"
2020
"net/http"
21-
"strconv"
2221
"strings"
2322
"time"
2423

@@ -497,145 +496,8 @@ func (g *GithubClient) GetRepoStatuses(repo models.Repo, pull models.PullRequest
497496
// UpdateStatus updates the status badge on the pull request.
498497
// See https://github.com/blog/1227-commit-status-api.
499498
func (g *GithubClient) UpdateStatus(ctx context.Context, request types.UpdateStatusRequest) (string, error) {
500-
shouldAllocate, err := g.allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
501-
RepoName: request.Repo.FullName,
502-
})
503-
if err != nil {
504-
return "", errors.Wrap(err, "unable to allocate legacy deprecation feature flag")
505-
}
506-
// if legacy deprecation is enabled, don't mutate check runs in legacy workflow
507-
if shouldAllocate {
508-
g.logger.InfoContext(ctx, "legacy deprecation feature flag enabled, not updating check runs")
509-
return "", nil
510-
}
511-
512-
// Empty status ID means we create a new check run
513-
if request.StatusID == "" {
514-
return g.createCheckRun(ctx, request)
515-
}
516-
return request.StatusID, g.updateCheckRun(ctx, request, request.StatusID)
517-
}
518-
519-
func (g *GithubClient) createCheckRun(ctx context.Context, request types.UpdateStatusRequest) (string, error) {
520-
status, conclusion := g.resolveChecksStatus(request.State)
521-
createCheckRunOpts := github.CreateCheckRunOptions{
522-
Name: request.StatusName,
523-
HeadSHA: request.Ref,
524-
Status: &status,
525-
Output: g.createCheckRunOutput(request),
526-
}
527-
528-
if request.DetailsURL != "" {
529-
createCheckRunOpts.DetailsURL = &request.DetailsURL
530-
}
531-
532-
// Conclusion is required if status is Completed
533-
if status == Completed.String() {
534-
createCheckRunOpts.Conclusion = &conclusion
535-
}
536-
537-
checkRun, _, err := g.client.Checks.CreateCheckRun(ctx, request.Repo.Owner, request.Repo.Name, createCheckRunOpts)
538-
if err != nil {
539-
return "", err
540-
}
541-
542-
return strconv.FormatInt(*checkRun.ID, 10), nil
543-
}
544-
545-
func (g *GithubClient) updateCheckRun(ctx context.Context, request types.UpdateStatusRequest, checkRunID string) error {
546-
status, conclusion := g.resolveChecksStatus(request.State)
547-
updateCheckRunOpts := github.UpdateCheckRunOptions{
548-
Name: request.StatusName,
549-
Status: &status,
550-
Output: g.createCheckRunOutput(request),
551-
}
552-
553-
if request.DetailsURL != "" {
554-
updateCheckRunOpts.DetailsURL = &request.DetailsURL
555-
}
556-
557-
// Conclusion is required if status is Completed
558-
if status == Completed.String() {
559-
updateCheckRunOpts.Conclusion = &conclusion
560-
}
561-
562-
checkRunIDInt, err := strconv.ParseInt(checkRunID, 10, 64)
563-
if err != nil {
564-
return err
565-
}
566-
567-
_, _, err = g.client.Checks.UpdateCheckRun(ctx, request.Repo.Owner, request.Repo.Name, checkRunIDInt, updateCheckRunOpts)
568-
return err
569-
}
570-
571-
func (g *GithubClient) resolveState(state models.VCSStatus) string {
572-
switch state {
573-
case models.QueuedVCSStatus:
574-
return "Queued"
575-
case models.PendingVCSStatus:
576-
return "In Progress"
577-
case models.SuccessVCSStatus:
578-
return "Success"
579-
case models.FailedVCSStatus:
580-
return "Failed"
581-
}
582-
return "Failed"
583-
}
584-
585-
func (g *GithubClient) createCheckRunOutput(request types.UpdateStatusRequest) *github.CheckRunOutput {
586-
var summary string
587-
588-
// Project command
589-
if strings.Contains(request.StatusName, ":") {
590-
// plan/apply command
591-
if request.DetailsURL != "" {
592-
summary = fmt.Sprintf(projectCommandTemplateWithLogs,
593-
request.CommandName,
594-
request.Project,
595-
request.Workspace,
596-
g.resolveState(request.State),
597-
fmt.Sprintf("[Logs](%s)", request.DetailsURL),
598-
)
599-
} else {
600-
summary = fmt.Sprintf(projectCommandTemplate,
601-
request.CommandName,
602-
request.Project,
603-
request.Workspace,
604-
g.resolveState(request.State),
605-
)
606-
}
607-
} else {
608-
if request.NumSuccess != "" && request.NumTotal != "" {
609-
summary = fmt.Sprintf(commandTemplateWithCount,
610-
request.CommandName,
611-
request.NumTotal,
612-
request.NumSuccess,
613-
g.resolveState(request.State))
614-
} else {
615-
summary = fmt.Sprintf(commandTemplate,
616-
request.CommandName,
617-
g.resolveState(request.State))
618-
}
619-
}
620-
621-
// Add formatting to summary
622-
summary = strings.ReplaceAll(strings.ReplaceAll(summary, "{", "`"), "}", "`")
623-
624-
checkRunOutput := github.CheckRunOutput{
625-
Title: &request.StatusName,
626-
Summary: &summary,
627-
}
628-
629-
if request.Output == "" {
630-
return &checkRunOutput
631-
}
632-
if len(request.Output) > maxChecksOutputLength {
633-
terraformOutputTooLong := "Terraform output is too long for Github UI, please review the above link to view detailed logs."
634-
checkRunOutput.Text = &terraformOutputTooLong
635-
} else {
636-
checkRunOutput.Text = &request.Output
637-
}
638-
return &checkRunOutput
499+
// since legacy deprecation feature flag was enabled (2024), we don't need to do the updating of check runs
500+
return "", nil
639501
}
640502

641503
// Github Checks uses Status and Conclusion to report status of the check run. Need to map models.VcsStatus to Status and Conclusion

server/legacy/lyft/command/feature_runner.go

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package command
22

33
import (
4-
"fmt"
5-
64
"github.com/runatlantis/atlantis/server/config/valid"
75
"github.com/runatlantis/atlantis/server/legacy/events"
86
"github.com/runatlantis/atlantis/server/legacy/events/command"
@@ -33,20 +31,9 @@ func (a *PlatformModeRunner) Run(ctx *command.Context, cmd *command.Comment) {
3331
return
3432
}
3533

36-
shouldAllocate, err := a.Allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
37-
if err != nil {
38-
a.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
39-
}
40-
41-
// if this isn't allocated don't worry about the rest
42-
if !shouldAllocate {
43-
a.Runner.Run(ctx, cmd)
44-
return
45-
}
46-
4734
// now let's determine whether the repo is configured for platform mode by building commands
4835
var projectCmds []command.ProjectContext
49-
projectCmds, err = a.Builder.BuildApplyCommands(ctx, cmd)
36+
projectCmds, err := a.Builder.BuildApplyCommands(ctx, cmd)
5037
if err != nil {
5138
a.Logger.ErrorContext(ctx.RequestCtx, err.Error())
5239
return
@@ -74,12 +61,7 @@ type PlatformModeProjectRunner struct { //create object and test
7461

7562
// Plan runs terraform plan for the project described by ctx.
7663
func (p *PlatformModeProjectRunner) Plan(ctx command.ProjectContext) command.ProjectResult {
77-
shouldAllocate, err := p.Allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
78-
if err != nil {
79-
p.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
80-
}
81-
82-
if shouldAllocate && (ctx.WorkflowModeType == valid.PlatformWorkflowMode) {
64+
if ctx.WorkflowModeType == valid.PlatformWorkflowMode {
8365
return p.PlatformModeRunner.Plan(ctx)
8466
}
8567

@@ -88,12 +70,7 @@ func (p *PlatformModeProjectRunner) Plan(ctx command.ProjectContext) command.Pro
8870

8971
// PolicyCheck evaluates policies defined with Rego for the project described by ctx.
9072
func (p *PlatformModeProjectRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult {
91-
shouldAllocate, err := p.Allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
92-
if err != nil {
93-
p.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
94-
}
95-
96-
if shouldAllocate && (ctx.WorkflowModeType == valid.PlatformWorkflowMode) {
73+
if ctx.WorkflowModeType == valid.PlatformWorkflowMode {
9774
return p.PlatformModeRunner.PolicyCheck(ctx)
9875
}
9976

@@ -102,12 +79,7 @@ func (p *PlatformModeProjectRunner) PolicyCheck(ctx command.ProjectContext) comm
10279

10380
// Apply runs terraform apply for the project described by ctx.
10481
func (p *PlatformModeProjectRunner) Apply(ctx command.ProjectContext) command.ProjectResult {
105-
shouldAllocate, err := p.Allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
106-
if err != nil {
107-
p.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
108-
}
109-
110-
if shouldAllocate && (ctx.WorkflowModeType == valid.PlatformWorkflowMode) {
82+
if ctx.WorkflowModeType == valid.PlatformWorkflowMode {
11183
return command.ProjectResult{
11284
Command: command.Apply,
11385
RepoRelDir: ctx.RepoRelDir,
@@ -122,12 +94,7 @@ func (p *PlatformModeProjectRunner) Apply(ctx command.ProjectContext) command.Pr
12294
}
12395

12496
func (p *PlatformModeProjectRunner) Version(ctx command.ProjectContext) command.ProjectResult {
125-
shouldAllocate, err := p.Allocator.ShouldAllocate(feature.PlatformMode, feature.FeatureContext{RepoName: ctx.HeadRepo.FullName})
126-
if err != nil {
127-
p.Logger.ErrorContext(ctx.RequestCtx, fmt.Sprintf("unable to allocate for feature: %s, error: %s", feature.PlatformMode, err))
128-
}
129-
130-
if shouldAllocate && (ctx.WorkflowModeType == valid.PlatformWorkflowMode) {
97+
if ctx.WorkflowModeType == valid.PlatformWorkflowMode {
13198
return p.PlatformModeRunner.Version(ctx)
13299
}
133100

server/neptune/gateway/event/pr_error_handler.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,7 @@ type LegacyPREventErrorHandler struct {
5353
}
5454

5555
func (p *LegacyPREventErrorHandler) WrapWithHandling(ctx context.Context, event PREvent, commandName string, executor sync.Executor) sync.Executor {
56-
allocation, err := p.allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
57-
RepoName: event.GetRepo().FullName,
58-
})
59-
60-
if err != nil {
61-
return p.delegate.WrapWithHandling(ctx, event, commandName, executor)
62-
}
63-
64-
if allocation {
65-
return executor
66-
}
67-
68-
return p.delegate.WrapWithHandling(ctx, event, commandName, executor)
56+
return executor
6957
}
7058

7159
type NeptunePREventErrorHandler struct {
@@ -74,18 +62,6 @@ type NeptunePREventErrorHandler struct {
7462
}
7563

7664
func (p *NeptunePREventErrorHandler) WrapWithHandling(ctx context.Context, event PREvent, commandName string, executor sync.Executor) sync.Executor {
77-
allocation, err := p.allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
78-
RepoName: event.GetRepo().FullName,
79-
})
80-
81-
if err != nil {
82-
return p.delegate.WrapWithHandling(ctx, event, commandName, executor)
83-
}
84-
85-
if !allocation {
86-
return executor
87-
}
88-
8965
return p.delegate.WrapWithHandling(ctx, event, commandName, executor)
9066
}
9167

0 commit comments

Comments
 (0)