Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support terragrunt blocks #1574

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions backend/controllers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
return nil
}

func getDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int64, repoFullName string, repoOwner string, repoName string, cloneUrl string, branch string) (string, *dg_github.GithubService, *dg_configuration.DiggerConfig, graph.Graph[string, dg_configuration.Project], error) {
func getDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int64, repoFullName string, repoOwner string, repoName string, cloneUrl string, branch string, prNumber int) (string, *dg_github.GithubService, *dg_configuration.DiggerConfig, graph.Graph[string, dg_configuration.Project], error) {
ghService, token, err := utils.GetGithubService(gh, installationId, repoFullName, repoOwner, repoName)
if err != nil {
log.Printf("Error getting github service: %v", err)
Expand All @@ -616,19 +616,25 @@ func getDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
var config *dg_configuration.DiggerConfig
var diggerYmlStr string
var dependencyGraph graph.Graph[string, dg_configuration.Project]

changedFiles, err := ghService.GetChangedFiles(prNumber)
if err != nil {
log.Printf("Error getting changed files: %v", err)
return "", nil, nil, nil, fmt.Errorf("error getting changed files")
}
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
diggerYmlStr = string(diggerYmlBytes)
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true)
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true, changedFiles)
if err != nil {
log.Printf("Error loading digger config: %v", err)
return err
}
return nil
})
if err != nil {
log.Printf("Error generating projects: %v", err)
return "", nil, nil, nil, fmt.Errorf("error generating projects")
log.Printf("Error cloning and loading config: %v", err)
return "", nil, nil, nil, fmt.Errorf("error cloning and loading config")
}

log.Printf("Digger config loadded successfully\n")
Expand All @@ -649,7 +655,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, installationId int64, r
return "", nil, nil, nil, nil, nil, fmt.Errorf("error getting branch name")
}

diggerYmlStr, ghService, config, dependencyGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneUrl, prBranch)
diggerYmlStr, ghService, config, dependencyGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneUrl, prBranch, prNumber)
if err != nil {
log.Printf("Error loading digger.yml: %v", err)
return "", nil, nil, nil, nil, nil, fmt.Errorf("error loading digger.yml")
Expand Down
2 changes: 1 addition & 1 deletion backend/controllers/github_after_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func handlePushEventApplyAfterMerge(gh utils.GithubClientProvider, payload *gith

// ==== starting apply after merge part =======
// TODO: Replace branch with actual commitID
diggerYmlStr, ghService, config, projectsGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneURL, defaultBranch)
diggerYmlStr, ghService, config, projectsGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneURL, defaultBranch, 0)
if err != nil {
log.Printf("getDiggerConfigForPR error: %v", err)
return fmt.Errorf("error getting digger config")
Expand Down
16 changes: 0 additions & 16 deletions cli/cmd/digger/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"github.com/diggerhq/digger/cli/pkg/azure"
"github.com/diggerhq/digger/cli/pkg/digger"
"github.com/diggerhq/digger/cli/pkg/drift"
"github.com/diggerhq/digger/cli/pkg/github"
Expand All @@ -24,21 +23,6 @@ var defaultCmd = &cobra.Command{
case digger.GitHub:
logLeader = os.Getenv("GITHUB_ACTOR")
github.GitHubCI(lock, PolicyChecker, BackendApi, ReportStrategy, comment_updater.CommentUpdaterProviderBasic{}, drift.DriftNotificationProviderBasic{})
case digger.GitLab:
logLeader = os.Getenv("CI_PROJECT_NAME")
gitLabCI(lock, PolicyChecker, BackendApi, ReportStrategy)
case digger.Azure:
// This should be refactored in the future because in this way the parsing
// is done twice, both here and inside azureCI, a better solution might be
// to encapsulate it into a method on the azure package and then grab the
// value here and pass it into the azureCI call.
azureContext := os.Getenv("AZURE_CONTEXT")
parsedAzureContext, _ := azure.GetAzureReposContext(azureContext)
logLeader = parsedAzureContext.BaseUrl
azureCI(lock, PolicyChecker, BackendApi, ReportStrategy)
case digger.BitBucket:
logLeader = os.Getenv("BITBUCKET_STEP_TRIGGERER_UUID")
bitbucketCI(lock, PolicyChecker, BackendApi, ReportStrategy)
case digger.None:
print("No CI detected.")
os.Exit(10)
Expand Down
Loading
Loading