Skip to content

Commit

Permalink
add legacyhandler back (deleted it in 766 oops) (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero authored Aug 13, 2024
1 parent eb5a0d4 commit ee0083c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
6 changes: 5 additions & 1 deletion server/legacy/lyft/gateway/events_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ func NewVCSEventsController(
clientCreator githubapp.ClientCreator,
defaultTFVersion string,
) *VCSEventsController {
legacyHandler := &gateway_handlers.LegacyPullHandler{
Logger: logger,
VCSStatusUpdater: vcsStatusUpdater,
}
prSignaler := &pr.WorkflowSignaler{TemporalClient: temporalClient, DefaultTFVersion: defaultTFVersion}
prRequirementChecker := requirement.NewPRAggregate(globalCfg)
modifiedPullHandler := gateway_handlers.NewModifiedPullHandler(logger, asyncScheduler, rootConfigBuilder, globalCfg, prRequirementChecker, prSignaler)
modifiedPullHandler := gateway_handlers.NewModifiedPullHandler(logger, asyncScheduler, rootConfigBuilder, globalCfg, prRequirementChecker, prSignaler, legacyHandler)
closedPullHandler := &gateway_handlers.ClosedPullRequestHandler{
Logger: logger,
PRCloseSignaler: prSignaler,
Expand Down
36 changes: 36 additions & 0 deletions server/neptune/gateway/event/legacy_pull_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package event

import (
"context"
"fmt"

"github.com/runatlantis/atlantis/server/config/valid"
"github.com/runatlantis/atlantis/server/legacy/events/command"
"github.com/runatlantis/atlantis/server/legacy/http"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/models"
)

const PlatformModeApplyStatusMessage = "THIS IS A LEGACY STATUS CHECK AND IS NOT RELEVANT PLEASE LOOK AT atlantis/deploy status checks"

type vcsStatusUpdater interface {
UpdateCombined(ctx context.Context, repo models.Repo, pull models.PullRequest, status models.VCSStatus, cmdName fmt.Stringer, statusID string, output string) (string, error)
UpdateCombinedCount(ctx context.Context, repo models.Repo, pull models.PullRequest, status models.VCSStatus, cmdName fmt.Stringer, numSuccess int, numTotal int, statusID string) (string, error)
}

type LegacyPullHandler struct {
VCSStatusUpdater vcsStatusUpdater
Logger logging.Logger
}

func (l *LegacyPullHandler) Handle(ctx context.Context, request *http.BufferedRequest, event PullRequest, allRoots []*valid.MergedProjectCfg) error {
// mark legacy statuses as successful if there are no roots in general
// this is processed here to make it easy to clean up when we deprecate legacy mode
if len(allRoots) == 0 {
if _, statusErr := l.VCSStatusUpdater.UpdateCombinedCount(ctx, event.Pull.HeadRepo, event.Pull, models.SuccessVCSStatus, command.Plan, 0, 0, ""); statusErr != nil {
l.Logger.WarnContext(ctx, fmt.Sprintf("unable to update commit status: %s", statusErr))
}
return nil
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/runatlantis/atlantis/server/models"
)

type legacyHandler interface {
Handle(ctx context.Context, request *http.BufferedRequest, event PullRequest, allRoots []*valid.MergedProjectCfg) error
}

type prSignaler interface {
SignalWithStartWorkflow(ctx context.Context, rootCfgs []*valid.MergedProjectCfg, prRequest pr.Request) (client.WorkflowRun, error)
}
Expand All @@ -29,6 +33,7 @@ type ModifiedPullHandler struct {
RootConfigBuilder rootConfigBuilder
GlobalCfg valid.GlobalCfg
RequirementChecker requirementChecker
LegacyHandler legacyHandler
PRSignaler prSignaler
}

Expand All @@ -41,13 +46,14 @@ type PullRequest struct {
InstallationToken int64
}

func NewModifiedPullHandler(logger logging.Logger, scheduler scheduler, rootConfigBuilder rootConfigBuilder, globalCfg valid.GlobalCfg, requirementChecker requirementChecker, prSignaler prSignaler) *ModifiedPullHandler {
func NewModifiedPullHandler(logger logging.Logger, scheduler scheduler, rootConfigBuilder rootConfigBuilder, globalCfg valid.GlobalCfg, requirementChecker requirementChecker, prSignaler prSignaler, legacyHandler legacyHandler) *ModifiedPullHandler {
return &ModifiedPullHandler{
Logger: logger,
Scheduler: scheduler,
RootConfigBuilder: rootConfigBuilder,
GlobalCfg: globalCfg,
RequirementChecker: requirementChecker,
LegacyHandler: legacyHandler,
PRSignaler: prSignaler,
}
}
Expand Down Expand Up @@ -97,6 +103,7 @@ func (p *ModifiedPullHandler) handle(ctx context.Context, request *http.Buffered
}

fxns := []func(ctx context.Context, request *http.BufferedRequest, event PullRequest, allRoots []*valid.MergedProjectCfg) error{
p.LegacyHandler.Handle,
p.handlePlatformMode,
}
var combinedErrors *multierror.Error
Expand Down
37 changes: 35 additions & 2 deletions server/neptune/gateway/event/modified_pull_request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func TestModifiedPullHandler_Handle_SignalerFailure(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{root},
},
LegacyHandler: &mockLegacyHandler{
expectedAllRoots: []*valid.MergedProjectCfg{root},
expectedT: t,
},
PRSignaler: &mockPRSignaler{
error: assert.AnError,
expectedRoots: []*valid.MergedProjectCfg{root},
Expand Down Expand Up @@ -106,6 +110,11 @@ func TestModifiedPullHandler_Handle_BranchStrategy(t *testing.T) {
pull := event.PullRequest{
Pull: pullRequest,
}
legacyHandler := &mockLegacyHandler{
expectedEvent: pull,
expectedAllRoots: []*valid.MergedProjectCfg{legacyRoot},
expectedT: t,
}
prRequest := pr.Request{
Revision: "sha",
Repo: testRepo,
Expand Down Expand Up @@ -134,10 +143,12 @@ func TestModifiedPullHandler_Handle_BranchStrategy(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{legacyRoot},
},
PRSignaler: signaler,
LegacyHandler: legacyHandler,
PRSignaler: signaler,
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pull)
assert.NoError(t, err)
assert.True(t, legacyHandler.called)
assert.True(t, signaler.called)
}

Expand Down Expand Up @@ -185,6 +196,11 @@ func TestModifiedPullHandler_Handle_MergeStrategy(t *testing.T) {
pr := event.PullRequest{
Pull: pullRequest,
}
legacyHandler := &mockLegacyHandler{
expectedEvent: pr,
expectedAllRoots: []*valid.MergedProjectCfg{root},
expectedT: t,
}
pullHandler := event.ModifiedPullHandler{
Logger: logger,
Scheduler: &sync.SynchronousScheduler{Logger: logger},
Expand All @@ -195,10 +211,12 @@ func TestModifiedPullHandler_Handle_MergeStrategy(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{root},
},
PRSignaler: signaler,
LegacyHandler: legacyHandler,
PRSignaler: signaler,
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pr)
assert.NoError(t, err)
assert.True(t, legacyHandler.called)
assert.True(t, signaler.called)
}

Expand All @@ -219,6 +237,21 @@ func (r *mockConfigBuilder) Build(_ context.Context, commit *config.RepoCommit,
return r.rootConfigs, r.error
}

type mockLegacyHandler struct {
expectedEvent event.PullRequest
expectedAllRoots []*valid.MergedProjectCfg
expectedT *testing.T
error error
called bool
}

func (l *mockLegacyHandler) Handle(ctx context.Context, _ *http.BufferedRequest, event event.PullRequest, allRoots []*valid.MergedProjectCfg) error {
l.called = true
assert.Equal(l.expectedT, l.expectedEvent, event)
assert.Equal(l.expectedT, l.expectedAllRoots, allRoots)
return l.error
}

type mockPRSignaler struct {
called bool
error error
Expand Down

0 comments on commit ee0083c

Please sign in to comment.