From 6c60758d1dec13de4a7ff0de0625368760547dad Mon Sep 17 00:00:00 2001 From: Shawna Monero Date: Thu, 4 Apr 2024 19:16:45 -0700 Subject: [PATCH] address comments --- .../adhoc_execution_params.go | 16 +++++++--------- .../adhocgithubhelpers/adhoc_github_helpers.go | 16 ++++++---------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go b/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go index 741addff2..bbdb19b1a 100644 --- a/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go +++ b/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go @@ -16,17 +16,15 @@ 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 (a *AdhocTerraformWorkflowExecutionParams) ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx context.Context, repoName string, revision string, githubRetriever *adhocgithubhelpers.AdhocGithubRetriever) error { +func ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx context.Context, repoName string, revision string, githubRetriever *adhocgithubhelpers.AdhocGithubRetriever) (AdhocTerraformWorkflowExecutionParams, error) { // TODO: in the future, could potentially pass in the owner instead of hardcoding lyft - repo, token, err := githubRetriever.GetRepositoryAndToken(ctx, "lyft", repoName) + repo, err := githubRetriever.GetRepository(ctx, "lyft", repoName) if err != nil { - return errors.Wrap(err, "getting repo") + return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "getting repo") } - githubRepo := adhocgithubhelpers.ConvertRepoToGithubRepo(repo, token) - - a.GithubRepo = githubRepo - a.Revision = revision - - return nil + return AdhocTerraformWorkflowExecutionParams{ + Revision: revision, + GithubRepo: repo, + }, nil } diff --git a/server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go b/server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go index 3666c224e..fb0854c57 100644 --- a/server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go +++ b/server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go @@ -23,32 +23,28 @@ type AdhocGithubRetriever struct { InstallationRetriever installationRetriever } -func (r *AdhocGithubRetriever) GetRepositoryAndToken(ctx context.Context, owner string, repoName string) (models.Repo, int64, error) { +func (r *AdhocGithubRetriever) GetRepository(ctx context.Context, owner string, repoName string) (github.Repo, error) { installation, err := r.InstallationRetriever.FindOrganizationInstallation(ctx, owner) if err != nil { - return models.Repo{}, installation.Token, errors.Wrap(err, "finding installation") + return github.Repo{}, errors.Wrap(err, "finding installation") } repo, err := r.RepoRetriever.Get(ctx, installation.Token, owner, repoName) if err != nil { - return repo, installation.Token, errors.Wrap(err, "getting repo") + return github.Repo{}, errors.Wrap(err, "getting repo") } if len(repo.DefaultBranch) == 0 { - return repo, installation.Token, fmt.Errorf("default branch was nil, this is a bug on github's side") + return github.Repo{}, fmt.Errorf("default branch was nil, this is a bug on github's side") } - return repo, installation.Token, nil -} - -func ConvertRepoToGithubRepo(repo models.Repo, token int64) github.Repo { return github.Repo{ Owner: repo.Owner, Name: repo.Name, URL: repo.CloneURL, DefaultBranch: repo.DefaultBranch, Credentials: github.AppCredentials{ - InstallationToken: token, + InstallationToken: installation.Token, }, - } + }, nil }