Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Apr 5, 2024
1 parent 14439fc commit 6c60758
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 6 additions & 10 deletions server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 6c60758

Please sign in to comment.