Skip to content

Commit

Permalink
fix all issues and remove all unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Apr 19, 2024
1 parent 5c60e8a commit f4c4300
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 109 deletions.
2 changes: 2 additions & 0 deletions cmd/adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (a *Adhoc) NewServer(userConfig legacy.UserConfig, config legacy.Config) (S
GithubAppKeyFile: userConfig.GithubAppKeyFile,
GithubAppSlug: userConfig.GithubAppSlug,
GlobalCfg: globalCfg,
GithubUser: userConfig.GithubUser,
GithubToken: userConfig.GithubToken,
}
return adhoc.NewServer(cfg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"

"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/models"
"github.com/runatlantis/atlantis/server/neptune/adhoc/adhocgithubhelpers"
"github.com/runatlantis/atlantis/server/neptune/gateway/config"
root_config "github.com/runatlantis/atlantis/server/neptune/gateway/config"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
internal_gh "github.com/runatlantis/atlantis/server/vcs/provider/github"
"github.com/runatlantis/atlantis/server/vcs/provider/github/converter"
)

type AdhocTerraformWorkflowExecutionParams struct {
Expand All @@ -20,11 +19,30 @@ type AdhocTerraformWorkflowExecutionParams struct {
// Note that deploymentID is used in NewWorkflowStore(), but we don't care about that in adhoc mode so can leave it blank
}

func ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx context.Context, repoName string, revision string, githubRetriever *adhocgithubhelpers.AdhocGithubRetriever, rootCfgBuilder *root_config.Builder) (AdhocTerraformWorkflowExecutionParams, error) {
func ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(
ctx context.Context,
repoName string,
PRNum int,
pullFetcher *internal_gh.PRFetcher,
pullConverter converter.PullConverter,
installationRetriever *internal_gh.InstallationRetriever,
rootCfgBuilder *root_config.Builder) (AdhocTerraformWorkflowExecutionParams, error) {

Check failure on line 29 in server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

unnecessary leading newline (whitespace)

orgName := "lyft"
installationToken, err := installationRetriever.FindOrganizationInstallation(ctx, orgName)
if err != nil {
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "finding organization installation")
}

// TODO: in the future, could potentially pass in the owner instead of hardcoding lyft
repo, err := githubRetriever.GetRepository(ctx, "lyft", repoName)
ghCommit, err := pullFetcher.Fetch(ctx, installationToken.Token, orgName, repoName, PRNum)
if err != nil {
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "getting repo")
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "fetching commit")
}

actualCommit, err := pullConverter.Convert(ghCommit)
if err != nil {
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "converting commit")
}

opts := config.BuilderOptions{
Expand All @@ -35,20 +53,11 @@ func ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx context.Cont
}

rootCfgs, err := rootCfgBuilder.Build(ctx, &root_config.RepoCommit{
Repo: models.Repo{
FullName: repo.GetFullName(),
Owner: repo.Owner,
Name: repoName,
CloneURL: repo.URL,
VCSHost: models.VCSHost{
Hostname: "github.com",
Type: models.Github,
},
DefaultBranch: repo.DefaultBranch,
},
Branch: repo.DefaultBranch,
Sha: revision,
}, repo.Credentials.InstallationToken, opts)
Repo: actualCommit.HeadRepo,
Branch: actualCommit.HeadBranch,
Sha: actualCommit.HeadCommit,
OptionalPRNum: actualCommit.Num,
}, installationToken.Token, opts)
if err != nil {
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "building root cfgs")
}
Expand All @@ -58,8 +67,14 @@ func ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx context.Cont

rootCfgBuilder.Logger.Info("returning adhocexecution params")
return AdhocTerraformWorkflowExecutionParams{
Revision: revision,
GithubRepo: repo,
Revision: actualCommit.HeadCommit,
GithubRepo: github.Repo{
Owner: orgName,
Name: repoName,
URL: actualCommit.HeadRepo.CloneURL,
DefaultBranch: actualCommit.HeadRepo.DefaultBranch,
Credentials: github.AppCredentials{InstallationToken: installationToken.Token},
},
TerraformRoots: roots,
}, nil
}
50 changes: 0 additions & 50 deletions server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go

This file was deleted.

2 changes: 2 additions & 0 deletions server/neptune/adhoc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Config struct {
GithubAppKeyFile string
GithubAppSlug string
GithubHostname string
GithubUser string
GithubToken string

GlobalCfg valid.GlobalCfg
}
80 changes: 42 additions & 38 deletions server/neptune/adhoc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
ghClient "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
"github.com/runatlantis/atlantis/server/vcs/provider/github"
"github.com/runatlantis/atlantis/server/vcs/provider/github/converter"

assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/metrics"
adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers"
adhocGithubHelpers "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocgithubhelpers"
adhocconfig "github.com/runatlantis/atlantis/server/neptune/adhoc/config"
root_config "github.com/runatlantis/atlantis/server/neptune/gateway/config"
"github.com/runatlantis/atlantis/server/neptune/gateway/deploy"
Expand All @@ -38,7 +38,6 @@ import (
"github.com/runatlantis/atlantis/server/neptune/workflows"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities"
"github.com/runatlantis/atlantis/server/static"
github_converter "github.com/runatlantis/atlantis/server/vcs/provider/github/converter"
"github.com/uber-go/tally/v4"
"github.com/urfave/negroni"
"go.temporal.io/sdk/client"
Expand All @@ -47,22 +46,23 @@ import (
)

type Server struct {
Logger logging.Logger
CronScheduler *internalSync.CronScheduler
Crons []*internalSync.Cron
HTTPServerProxy *neptune_http.ServerProxy
Port int
StatsScope tally.Scope
StatsCloser io.Closer
TemporalClient *temporal.ClientWrapper
TerraformActivities *activities.Terraform
GithubActivities *activities.Github
TerraformTaskQueue string
RootConfigBuilder *root_config.Builder
GithubRetriever *adhocGithubHelpers.AdhocGithubRetriever
Repo string
Root string
Revision string
Logger logging.Logger
CronScheduler *internalSync.CronScheduler
Crons []*internalSync.Cron
HTTPServerProxy *neptune_http.ServerProxy
Port int
StatsScope tally.Scope
StatsCloser io.Closer
TemporalClient *temporal.ClientWrapper
TerraformActivities *activities.Terraform
GithubActivities *activities.Github
TerraformTaskQueue string
RootConfigBuilder *root_config.Builder
Repo string
PRNum int
InstallationRetriever *github.InstallationRetriever
PullFetcher *github.PRFetcher
PullConverter converter.PullConverter
}

func NewServer(config *adhocconfig.Config) (*Server, error) {
Expand Down Expand Up @@ -183,17 +183,19 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
Scope: scope.SubScope("event.filters.root"),
}

repoConverter := github_converter.RepoConverter{}
repoRetriever := &github.RepoRetriever{
pullFetcher := &github.PRFetcher{
ClientCreator: clientCreator,
RepoConverter: repoConverter,
}

// This exists to convert a repo name to a repo object
githubRetriever := &adhocGithubHelpers.AdhocGithubRetriever{
RepoRetriever: repoRetriever,
InstallationRetriever: installationFetcher,
repoConverter := converter.RepoConverter{
GithubUser: config.GithubUser,
GithubToken: config.GithubToken,
}

pullConverter := converter.PullConverter{
RepoConverter: repoConverter,
}

config.CtxLogger.Info(fmt.Sprintf("Starting adhoc server, params are: repo: %s, root: %s, revision: %s", config.GlobalCfg.AdhocMode.Repo, config.GlobalCfg.AdhocMode.Root, config.GlobalCfg.AdhocMode.Revision))

server := Server{
Expand All @@ -205,18 +207,20 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
Frequency: 1 * time.Minute,
},
},
HTTPServerProxy: httpServerProxy,
Port: config.ServerCfg.Port,
StatsScope: scope,
StatsCloser: statsCloser,
TemporalClient: temporalClient,
TerraformActivities: terraformActivities,
TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue,
GithubActivities: githubActivities,
RootConfigBuilder: rootConfigBuilder,
GithubRetriever: githubRetriever,
Repo: config.GlobalCfg.AdhocMode.Repo,
Revision: config.GlobalCfg.AdhocMode.Revision,
HTTPServerProxy: httpServerProxy,
Port: config.ServerCfg.Port,
StatsScope: scope,
StatsCloser: statsCloser,
TemporalClient: temporalClient,
TerraformActivities: terraformActivities,
TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue,
GithubActivities: githubActivities,
RootConfigBuilder: rootConfigBuilder,
Repo: config.GlobalCfg.AdhocMode.Repo,
PRNum: config.GlobalCfg.AdhocMode.PRNum,

Check failure on line 220 in server/neptune/adhoc/server.go

View workflow job for this annotation

GitHub Actions / runner / gotest

config.GlobalCfg.AdhocMode.PRNum undefined (type valid.AdhocMode has no field or method PRNum)

Check failure on line 220 in server/neptune/adhoc/server.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

config.GlobalCfg.AdhocMode.PRNum undefined (type valid.AdhocMode has no field or method PRNum) (typecheck)

Check failure on line 220 in server/neptune/adhoc/server.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

config.GlobalCfg.AdhocMode.PRNum undefined (type valid.AdhocMode has no field or method PRNum)) (typecheck)
InstallationRetriever: installationFetcher,
PullFetcher: pullFetcher,
PullConverter: pullConverter,
}
return &server, nil
}
Expand Down Expand Up @@ -275,7 +279,7 @@ func (s Server) Start() error {
go func() {
defer wg.Done()

adhocExecutionParams, err := adhoc.ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx, s.Repo, s.Revision, s.GithubRetriever, s.RootConfigBuilder)
adhocExecutionParams, err := adhoc.ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx, s.Repo, s.PRNum, s.PullFetcher, s.PullConverter, s.InstallationRetriever, s.RootConfigBuilder)
if err != nil {
s.Logger.Error(err.Error())
return
Expand Down

0 comments on commit f4c4300

Please sign in to comment.