Skip to content

Commit 765cf7c

Browse files
authored
support terragrunt blocks (#1574)
* support terragrunt blocks
1 parent 2d6c6d4 commit 765cf7c

File tree

16 files changed

+196
-537
lines changed

16 files changed

+196
-537
lines changed

backend/controllers/github.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
606606
return nil
607607
}
608608

609-
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) {
609+
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) {
610610
ghService, token, err := utils.GetGithubService(gh, installationId, repoFullName, repoOwner, repoName)
611611
if err != nil {
612612
log.Printf("Error getting github service: %v", err)
@@ -616,19 +616,25 @@ func getDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
616616
var config *dg_configuration.DiggerConfig
617617
var diggerYmlStr string
618618
var dependencyGraph graph.Graph[string, dg_configuration.Project]
619+
620+
changedFiles, err := ghService.GetChangedFiles(prNumber)
621+
if err != nil {
622+
log.Printf("Error getting changed files: %v", err)
623+
return "", nil, nil, nil, fmt.Errorf("error getting changed files")
624+
}
619625
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
620626
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
621627
diggerYmlStr = string(diggerYmlBytes)
622-
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true)
628+
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true, changedFiles)
623629
if err != nil {
624630
log.Printf("Error loading digger config: %v", err)
625631
return err
626632
}
627633
return nil
628634
})
629635
if err != nil {
630-
log.Printf("Error generating projects: %v", err)
631-
return "", nil, nil, nil, fmt.Errorf("error generating projects")
636+
log.Printf("Error cloning and loading config: %v", err)
637+
return "", nil, nil, nil, fmt.Errorf("error cloning and loading config")
632638
}
633639

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

652-
diggerYmlStr, ghService, config, dependencyGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneUrl, prBranch)
658+
diggerYmlStr, ghService, config, dependencyGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneUrl, prBranch, prNumber)
653659
if err != nil {
654660
log.Printf("Error loading digger.yml: %v", err)
655661
return "", nil, nil, nil, nil, nil, fmt.Errorf("error loading digger.yml")

backend/controllers/github_after_merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func handlePushEventApplyAfterMerge(gh utils.GithubClientProvider, payload *gith
158158

159159
// ==== starting apply after merge part =======
160160
// TODO: Replace branch with actual commitID
161-
diggerYmlStr, ghService, config, projectsGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneURL, defaultBranch)
161+
diggerYmlStr, ghService, config, projectsGraph, err := getDiggerConfigForBranch(gh, installationId, repoFullName, repoOwner, repoName, cloneURL, defaultBranch, 0)
162162
if err != nil {
163163
log.Printf("getDiggerConfigForPR error: %v", err)
164164
return fmt.Errorf("error getting digger config")

cli/cmd/digger/default.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/diggerhq/digger/cli/pkg/azure"
65
"github.com/diggerhq/digger/cli/pkg/digger"
76
"github.com/diggerhq/digger/cli/pkg/drift"
87
"github.com/diggerhq/digger/cli/pkg/github"
@@ -24,21 +23,6 @@ var defaultCmd = &cobra.Command{
2423
case digger.GitHub:
2524
logLeader = os.Getenv("GITHUB_ACTOR")
2625
github.GitHubCI(lock, PolicyChecker, BackendApi, ReportStrategy, comment_updater.CommentUpdaterProviderBasic{}, drift.DriftNotificationProviderBasic{})
27-
case digger.GitLab:
28-
logLeader = os.Getenv("CI_PROJECT_NAME")
29-
gitLabCI(lock, PolicyChecker, BackendApi, ReportStrategy)
30-
case digger.Azure:
31-
// This should be refactored in the future because in this way the parsing
32-
// is done twice, both here and inside azureCI, a better solution might be
33-
// to encapsulate it into a method on the azure package and then grab the
34-
// value here and pass it into the azureCI call.
35-
azureContext := os.Getenv("AZURE_CONTEXT")
36-
parsedAzureContext, _ := azure.GetAzureReposContext(azureContext)
37-
logLeader = parsedAzureContext.BaseUrl
38-
azureCI(lock, PolicyChecker, BackendApi, ReportStrategy)
39-
case digger.BitBucket:
40-
logLeader = os.Getenv("BITBUCKET_STEP_TRIGGERER_UUID")
41-
bitbucketCI(lock, PolicyChecker, BackendApi, ReportStrategy)
4226
case digger.None:
4327
print("No CI detected.")
4428
os.Exit(10)

0 commit comments

Comments
 (0)