-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEVCON-6918] Helper funcs for getting the github repo (#743)
- Loading branch information
Showing
4 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 20 additions & 5 deletions
25
server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
package adhoc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/runatlantis/atlantis/server/neptune/adhoc/adhocgithubhelpers" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" | ||
) | ||
|
||
type AdhocTerraformWorkflowExecutionParams struct { | ||
AtlantisRoot string | ||
AtlantisRepo string | ||
Revision string | ||
TerraformRoot terraform.Root | ||
GithubRepo github.Repo | ||
Revision string | ||
TerraformRoots []terraform.Root | ||
GithubRepo github.Repo | ||
// 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) (AdhocTerraformWorkflowExecutionParams, error) { | ||
// TODO: in the future, could potentially pass in the owner instead of hardcoding lyft | ||
repo, err := githubRetriever.GetRepository(ctx, "lyft", repoName) | ||
if err != nil { | ||
return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "getting repo") | ||
} | ||
|
||
return AdhocTerraformWorkflowExecutionParams{ | ||
Revision: revision, | ||
GithubRepo: repo, | ||
}, nil | ||
} |
50 changes: 50 additions & 0 deletions
50
server/neptune/adhoc/adhocgithubhelpers/adhoc_github_helpers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package adhocgithubhelpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/runatlantis/atlantis/server/models" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" | ||
internal "github.com/runatlantis/atlantis/server/vcs/provider/github" | ||
) | ||
|
||
type repoRetriever interface { | ||
Get(ctx context.Context, installationToken int64, owner, repo string) (models.Repo, error) | ||
} | ||
|
||
type installationRetriever interface { | ||
FindOrganizationInstallation(ctx context.Context, org string) (internal.Installation, error) | ||
} | ||
|
||
type AdhocGithubRetriever struct { | ||
RepoRetriever repoRetriever | ||
InstallationRetriever installationRetriever | ||
} | ||
|
||
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 github.Repo{}, errors.Wrap(err, "finding installation") | ||
} | ||
|
||
repo, err := r.RepoRetriever.Get(ctx, installation.Token, owner, repoName) | ||
if err != nil { | ||
return github.Repo{}, errors.Wrap(err, "getting repo") | ||
} | ||
|
||
if len(repo.DefaultBranch) == 0 { | ||
return github.Repo{}, fmt.Errorf("default branch was nil, this is a bug on github's side") | ||
} | ||
|
||
return github.Repo{ | ||
Owner: repo.Owner, | ||
Name: repo.Name, | ||
URL: repo.CloneURL, | ||
DefaultBranch: repo.DefaultBranch, | ||
Credentials: github.AppCredentials{ | ||
InstallationToken: installation.Token, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters