66 "encoding/json"
77 "errors"
88 "fmt"
9+ "github.com/diggerhq/digger/libs/digger_config/terragrunt/tac"
910 "github.com/diggerhq/digger/libs/git_utils"
1011 "log/slog"
1112 "math/rand"
@@ -416,7 +417,6 @@ func handlePushEvent(gh utils.GithubClientProvider, payload *github.PushEvent, a
416417 loadProjectsOnPush := os .Getenv ("DIGGER_LOAD_PROJECTS_ON_PUSH" )
417418
418419 if loadProjectsOnPush == "true" {
419-
420420 if strings .HasSuffix (ref , defaultBranch ) {
421421 slog .Debug ("Loading projects from GitHub repo (push event)" , "loadProjectsOnPush" , loadProjectsOnPush , "ref" , ref , "defaultBranch" , defaultBranch )
422422 err := services .LoadProjectsFromGithubRepo (gh , strconv .FormatInt (installationId , 10 ), repoFullName , repoOwner , repoName , cloneURL , defaultBranch )
@@ -428,6 +428,15 @@ func handlePushEvent(gh utils.GithubClientProvider, payload *github.PushEvent, a
428428 slog .Debug ("Skipping loading projects from GitHub repo" , "loadProjectsOnPush" , loadProjectsOnPush )
429429 }
430430
431+ repoCacheEnabled := os .Getenv ("DIGGER_CONFIG_REPO_CACHE_ENABLED" )
432+ if repoCacheEnabled == "1" && strings .HasSuffix (ref , defaultBranch ) {
433+ go func () {
434+ if err := sendProcessCacheRequest (repoFullName , defaultBranch , installationId ); err != nil {
435+ slog .Error ("Failed to process cache request" , "error" , err , "repoFullName" , repoFullName )
436+ }
437+ }()
438+ }
439+
431440 return nil
432441}
433442
@@ -914,7 +923,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
914923 return nil
915924}
916925
917- func GetDiggerConfigForBranch (gh utils.GithubClientProvider , installationId int64 , repoFullName string , repoOwner string , repoName string , cloneUrl string , branch string , changedFiles []string ) (string , * dg_github.GithubService , * dg_configuration.DiggerConfig , graph.Graph [string , dg_configuration.Project ], error ) {
926+ func GetDiggerConfigForBranch (gh utils.GithubClientProvider , installationId int64 , repoFullName string , repoOwner string , repoName string , cloneUrl string , branch string , changedFiles []string , taConfig * tac. AtlantisConfig ) (string , * dg_github.GithubService , * dg_configuration.DiggerConfig , graph.Graph [string , dg_configuration.Project ], error ) {
918927 slog .Info ("Getting Digger config for branch" ,
919928 slog .Group ("repository" ,
920929 slog .String ("fullName" , repoFullName ),
@@ -954,7 +963,7 @@ func GetDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
954963
955964 slog .Debug ("Successfully read digger.yml file" , "configLength" , len (diggerYmlStr ))
956965
957- config , _ , dependencyGraph , err = dg_configuration .LoadDiggerConfig (dir , true , changedFiles )
966+ config , _ , dependencyGraph , _ , err = dg_configuration .LoadDiggerConfig (dir , true , changedFiles , taConfig )
958967 if err != nil {
959968 slog .Error ("Error loading and parsing Digger config" ,
960969 "directory" , dir ,
@@ -1046,6 +1055,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
10461055
10471056 // check if items should be loaded from cache
10481057 useCache := false
1058+ var taConfig * tac.AtlantisConfig = nil
10491059 if val , _ := os .LookupEnv ("DIGGER_CONFIG_REPO_CACHE_ENABLED" ); val == "1" && ! slices .Contains (prLabels , "digger:no-cache" ) {
10501060 useCache = true
10511061 slog .Info ("Attempting to load config from cache" ,
@@ -1054,7 +1064,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
10541064 "prNumber" , prNumber ,
10551065 )
10561066
1057- diggerYmlStr , config , dependencyGraph , err := retrieveConfigFromCache (orgId , repoFullName )
1067+ _ , _ , _ , taConfigTemp , err := retrieveConfigFromCache (orgId , repoFullName )
10581068 if err != nil {
10591069 slog .Info ("Could not load from cache, falling back to live loading" ,
10601070 "orgId" , orgId ,
@@ -1065,9 +1075,8 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
10651075 slog .Info ("Successfully loaded config from cache" ,
10661076 "orgId" , orgId ,
10671077 "repoFullName" , repoFullName ,
1068- "projectCount" , len (config .Projects ),
10691078 )
1070- return diggerYmlStr , ghService , config , * dependencyGraph , & prBranch , & prCommitSha , changedFiles , nil
1079+ taConfig = taConfigTemp
10711080 }
10721081 }
10731082
@@ -1084,7 +1093,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
10841093 "prNumber" , prNumber ,
10851094 )
10861095
1087- diggerYmlStr , ghService , config , dependencyGraph , err := GetDiggerConfigForBranch (gh , installationId , repoFullName , repoOwner , repoName , cloneUrl , prBranch , changedFiles )
1096+ diggerYmlStr , ghService , config , dependencyGraph , err := GetDiggerConfigForBranch (gh , installationId , repoFullName , repoOwner , repoName , cloneUrl , prBranch , changedFiles , taConfig )
10881097 if err != nil {
10891098 slog .Error ("Error loading Digger config from repository" ,
10901099 "prNumber" , prNumber ,
@@ -1098,7 +1107,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
10981107 return diggerYmlStr , ghService , config , dependencyGraph , & prBranch , & prCommitSha , changedFiles , nil
10991108}
11001109
1101- func retrieveConfigFromCache (orgId uint , repoFullName string ) (string , * dg_configuration.DiggerConfig , * graph.Graph [string , dg_configuration.Project ], error ) {
1110+ func retrieveConfigFromCache (orgId uint , repoFullName string ) (string , * dg_configuration.DiggerConfig , * graph.Graph [string , dg_configuration.Project ], * tac. AtlantisConfig , error ) {
11021111 slog .Debug ("Retrieving config from cache" ,
11031112 "orgId" , orgId ,
11041113 "repoFullName" , repoFullName ,
@@ -1111,7 +1120,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
11111120 "repoFullName" , repoFullName ,
11121121 "error" , err ,
11131122 )
1114- return "" , nil , nil , fmt .Errorf ("failed to load repo cache: %v" , err )
1123+ return "" , nil , nil , nil , fmt .Errorf ("failed to load repo cache: %v" , err )
11151124 }
11161125
11171126 var config dg_configuration.DiggerConfig
@@ -1122,7 +1131,18 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
11221131 "repoFullName" , repoFullName ,
11231132 "error" , err ,
11241133 )
1125- return "" , nil , nil , fmt .Errorf ("failed to unmarshal config from cache: %v" , err )
1134+ return "" , nil , nil , nil , fmt .Errorf ("failed to unmarshal config from cache: %v" , err )
1135+ }
1136+
1137+ var taConfig tac.AtlantisConfig
1138+ err = json .Unmarshal (repoCache .TerragruntAtlantisConfig , & taConfig )
1139+ if err != nil {
1140+ slog .Error ("Failed to unmarshal config from cache" ,
1141+ "orgId" , orgId ,
1142+ "repoFullName" , repoFullName ,
1143+ "error" , err ,
1144+ )
1145+ return "" , nil , nil , nil , fmt .Errorf ("failed to unmarshal config from cache: %v" , err )
11261146 }
11271147
11281148 slog .Debug ("Creating project dependency graph from cached config" ,
@@ -1138,7 +1158,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
11381158 "repoFullName" , repoFullName ,
11391159 "error" , err ,
11401160 )
1141- return "" , nil , nil , fmt .Errorf ("error creating dependency graph from cached config: %v" , err )
1161+ return "" , nil , nil , nil , fmt .Errorf ("error creating dependency graph from cached config: %v" , err )
11421162 }
11431163
11441164 slog .Info ("Successfully retrieved config from cache" ,
@@ -1147,7 +1167,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
11471167 "projectCount" , len (config .Projects ),
11481168 )
11491169
1150- return repoCache .DiggerYmlStr , & config , & projectsGraph , nil
1170+ return repoCache .DiggerYmlStr , & config , & projectsGraph , & taConfig , nil
11511171}
11521172
11531173func GetRepoByInstllationId (installationId int64 , repoOwner string , repoName string ) (* models.Repo , error ) {
0 commit comments