Skip to content

Commit

Permalink
remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Samra Belachew committed Jun 30, 2023
1 parent 2f78c2c commit e53187c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 315 deletions.
5 changes: 1 addition & 4 deletions server/legacy/lyft/gateway/events_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ func NewVCSEventsController(
}
prSignaler := &pr.WorkflowSignaler{TemporalClient: temporalClient, DefaultTFVersion: defaultTFVersion}
prRequirementChecker := requirement.NewPRAggregate(globalCfg)
modifiedPullHandler := gateway_handlers.NewModifiedPullHandler(logger, asyncScheduler, rootConfigBuilder, globalCfg, prRequirementChecker, prSignaler, legacyHandler, featureAllocator)
modifiedPullHandler := gateway_handlers.NewModifiedPullHandler(logger, asyncScheduler, rootConfigBuilder, globalCfg, prRequirementChecker, prSignaler, legacyHandler)
closedPullHandler := &gateway_handlers.ClosedPullRequestHandler{
WorkerProxy: pullEventSNSProxy,
Allocator: featureAllocator,
Logger: logger,
PRCloseSignaler: prSignaler,
Scope: scope.SubScope("pull.closed"),
Expand Down Expand Up @@ -121,7 +120,6 @@ func NewVCSEventsController(
logger,
snsWriter,
asyncScheduler,
featureAllocator,
prSignaler,
deploySignaler,
vcsClient,
Expand Down Expand Up @@ -160,7 +158,6 @@ func NewVCSEventsController(
SnsWriter: snsWriter,
Logger: logger,
CheckRunFetcher: checkRunFetcher,
Allocator: featureAllocator,
WorkflowSignaler: prSignaler,
Scope: scope.SubScope("pull.review"),
RootConfigBuilder: rootConfigBuilder,
Expand Down
15 changes: 1 addition & 14 deletions server/neptune/gateway/event/closed_pull_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/legacy/http"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/neptune/lyft/feature"
"github.com/uber-go/tally/v4"
"go.temporal.io/api/serviceerror"
)
Expand All @@ -17,7 +16,6 @@ type prCloseSignaler interface {

type ClosedPullRequestHandler struct {
WorkerProxy workerProxy
Allocator feature.Allocator
Logger logging.Logger
PRCloseSignaler prCloseSignaler
Scope tally.Scope
Expand All @@ -35,18 +33,7 @@ func (c *ClosedPullRequestHandler) Handle(ctx context.Context, request *http.Buf
}

func (c *ClosedPullRequestHandler) handlePlatformMode(ctx context.Context, event PullRequest) error {
shouldAllocate, err := c.Allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
RepoName: event.Pull.HeadRepo.FullName,
})
if err != nil {
c.Logger.ErrorContext(ctx, "unable to allocate pr mode")
return nil
}
if !shouldAllocate {
c.Logger.InfoContext(ctx, "handler not configured for allocation")
return nil
}
err = c.PRCloseSignaler.SendCloseSignal(ctx, event.Pull.HeadRepo.FullName, event.Pull.Num)
err := c.PRCloseSignaler.SendCloseSignal(ctx, event.Pull.HeadRepo.FullName, event.Pull.Num)

var workflowNotFoundErr *serviceerror.NotFound
if errors.As(err, &workflowNotFoundErr) {
Expand Down
91 changes: 0 additions & 91 deletions server/neptune/gateway/event/closed_pull_request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@ import (
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/models"
"github.com/runatlantis/atlantis/server/neptune/gateway/event"
"github.com/runatlantis/atlantis/server/neptune/lyft/feature"
"github.com/stretchr/testify/assert"
"github.com/uber-go/tally/v4"
"go.temporal.io/api/serviceerror"
)

func TestClosedPullHandler_Handle(t *testing.T) {
allocator := &testAllocator{
expectedAllocation: true,
expectedFeatureID: feature.LegacyDeprecation,
expectedFeatureCtx: feature.FeatureContext{
RepoName: repoFullName,
},
t: t,
}
workerProxy := &mockWorkerProxy{}
signaler := &testCloseSignaler{
t: t,
expectedRepoName: "repo",
expectedPullNum: 1,
}
pullHandler := event.ClosedPullRequestHandler{
Allocator: allocator,
Logger: logging.NewNoopCtxLogger(t),
WorkerProxy: workerProxy,
PRCloseSignaler: signaler,
Expand All @@ -51,78 +41,7 @@ func TestClosedPullHandler_Handle(t *testing.T) {
assert.NoError(t, err)
}

func TestClosedPullHandler_Handle_AllocationError(t *testing.T) {
allocator := &testAllocator{
expectedError: assert.AnError,
expectedFeatureID: feature.LegacyDeprecation,
expectedFeatureCtx: feature.FeatureContext{
RepoName: repoFullName,
},
t: t,
}
workerProxy := &mockWorkerProxy{}
signaler := &testCloseSignaler{}
pullHandler := event.ClosedPullRequestHandler{
Allocator: allocator,
Logger: logging.NewNoopCtxLogger(t),
WorkerProxy: workerProxy,
PRCloseSignaler: signaler,
}
pr := event.PullRequest{
Pull: models.PullRequest{
BaseRepo: testRepo,
HeadRepo: testRepo,
HeadBranch: "somebranch",
HeadCommit: "1234",
Num: 1,
},
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pr)
assert.False(t, signaler.called)
assert.True(t, workerProxy.called)
assert.NoError(t, err)
}

func TestClosedPullHandler_Handle_AllocationFail(t *testing.T) {
allocator := &testAllocator{
expectedFeatureID: feature.LegacyDeprecation,
expectedFeatureCtx: feature.FeatureContext{
RepoName: repoFullName,
},
t: t,
}
workerProxy := &mockWorkerProxy{}
signaler := &testCloseSignaler{}
pullHandler := event.ClosedPullRequestHandler{
Allocator: allocator,
Logger: logging.NewNoopCtxLogger(t),
WorkerProxy: workerProxy,
PRCloseSignaler: signaler,
}
pr := event.PullRequest{
Pull: models.PullRequest{
BaseRepo: testRepo,
HeadRepo: testRepo,
HeadBranch: "somebranch",
HeadCommit: "1234",
Num: 1,
},
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pr)
assert.False(t, signaler.called)
assert.True(t, workerProxy.called)
assert.NoError(t, err)
}

func TestClosedPullHandler_Handle_SignalError(t *testing.T) {
allocator := &testAllocator{
expectedAllocation: true,
expectedFeatureID: feature.LegacyDeprecation,
expectedFeatureCtx: feature.FeatureContext{
RepoName: repoFullName,
},
t: t,
}
workerProxy := &mockWorkerProxy{}
signaler := &testCloseSignaler{
t: t,
Expand All @@ -131,7 +50,6 @@ func TestClosedPullHandler_Handle_SignalError(t *testing.T) {
expectedPullNum: 1,
}
pullHandler := event.ClosedPullRequestHandler{
Allocator: allocator,
Logger: logging.NewNoopCtxLogger(t),
WorkerProxy: workerProxy,
PRCloseSignaler: signaler,
Expand All @@ -152,14 +70,6 @@ func TestClosedPullHandler_Handle_SignalError(t *testing.T) {
}

func TestClosedPullHandler_Handle_SignalNotFoundError(t *testing.T) {
allocator := &testAllocator{
expectedAllocation: true,
expectedFeatureID: feature.LegacyDeprecation,
expectedFeatureCtx: feature.FeatureContext{
RepoName: repoFullName,
},
t: t,
}
workerProxy := &mockWorkerProxy{}
signaler := &testCloseSignaler{
t: t,
Expand All @@ -168,7 +78,6 @@ func TestClosedPullHandler_Handle_SignalNotFoundError(t *testing.T) {
err: errors.Wrap(serviceerror.NewNotFound(""), "error wrapping"),
}
pullHandler := event.ClosedPullRequestHandler{
Allocator: allocator,
Logger: logging.NewNoopCtxLogger(t),
WorkerProxy: workerProxy,
PRCloseSignaler: signaler,
Expand Down
21 changes: 2 additions & 19 deletions server/neptune/gateway/event/comment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"time"

"github.com/hashicorp/go-multierror"
"github.com/runatlantis/atlantis/server/neptune/gateway/pr"
"github.com/runatlantis/atlantis/server/neptune/lyft/feature"

"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/config/valid"
"github.com/runatlantis/atlantis/server/legacy/events/command"
Expand All @@ -17,6 +14,7 @@ import (
"github.com/runatlantis/atlantis/server/models"
"github.com/runatlantis/atlantis/server/neptune/gateway/config"
"github.com/runatlantis/atlantis/server/neptune/gateway/deploy"
"github.com/runatlantis/atlantis/server/neptune/gateway/pr"
"github.com/runatlantis/atlantis/server/neptune/gateway/requirement"
"github.com/runatlantis/atlantis/server/neptune/sync"
"github.com/runatlantis/atlantis/server/neptune/workflows"
Expand Down Expand Up @@ -69,7 +67,7 @@ func (c Comment) GetRepo() models.Repo {
return c.BaseRepo
}

func NewCommentEventWorkerProxy(logger logging.Logger, snsWriter Writer, scheduler scheduler, allocator feature.Allocator, prSignaler prSignaler, deploySignaler deploySignaler, commentCreator commentCreator, vcsStatusUpdater statusUpdater, globalCfg valid.GlobalCfg, rootConfigBuilder rootConfigBuilder, legacyErrorHandler errorHandler, neptuneErrorHandler errorHandler, requirementChecker requirementChecker) *CommentEventWorkerProxy {
func NewCommentEventWorkerProxy(logger logging.Logger, snsWriter Writer, scheduler scheduler, prSignaler prSignaler, deploySignaler deploySignaler, commentCreator commentCreator, vcsStatusUpdater statusUpdater, globalCfg valid.GlobalCfg, rootConfigBuilder rootConfigBuilder, legacyErrorHandler errorHandler, neptuneErrorHandler errorHandler, requirementChecker requirementChecker) *CommentEventWorkerProxy {
return &CommentEventWorkerProxy{
logger: logger,
scheduler: scheduler,
Expand All @@ -84,7 +82,6 @@ func NewCommentEventWorkerProxy(logger logging.Logger, snsWriter Writer, schedul
deploySignaler: deploySignaler,
commentCreator: commentCreator,
requirementChecker: requirementChecker,
allocator: allocator,
prSignaler: prSignaler,
},
vcsStatusUpdater: vcsStatusUpdater,
Expand All @@ -99,27 +96,13 @@ type NeptuneWorkerProxy struct {
deploySignaler deploySignaler
commentCreator commentCreator
requirementChecker requirementChecker
allocator feature.Allocator
prSignaler prSignaler
}

func (p *NeptuneWorkerProxy) Handle(ctx context.Context, event Comment, cmd *command.Comment, roots []*valid.MergedProjectCfg, request *http.BufferedRequest) error {
if cmd.Name == command.Apply {
return p.handleApplies(ctx, event, cmd, roots)
}
// TODO: remove when we begin in-depth testing and rollout of pr mode
// feature allocator is only temporary while we continue building out implementation
shouldAllocate, err := p.allocator.ShouldAllocate(feature.LegacyDeprecation, feature.FeatureContext{
RepoName: event.Pull.HeadRepo.FullName,
})
if err != nil {
p.logger.ErrorContext(ctx, "unable to allocate pr mode")
return nil
}
if !shouldAllocate {
p.logger.InfoContext(ctx, "handler not configured for allocation")
return nil
}
prRequest := pr.Request{
Number: event.Pull.Num,
Revision: event.Pull.HeadCommit,
Expand Down
Loading

0 comments on commit e53187c

Please sign in to comment.