6
6
"encoding/json"
7
7
"errors"
8
8
"fmt"
9
+ "github.com/diggerhq/digger/libs/digger_config/terragrunt/tac"
9
10
"github.com/diggerhq/digger/libs/git_utils"
10
11
"log/slog"
11
12
"math/rand"
@@ -416,7 +417,6 @@ func handlePushEvent(gh utils.GithubClientProvider, payload *github.PushEvent, a
416
417
loadProjectsOnPush := os .Getenv ("DIGGER_LOAD_PROJECTS_ON_PUSH" )
417
418
418
419
if loadProjectsOnPush == "true" {
419
-
420
420
if strings .HasSuffix (ref , defaultBranch ) {
421
421
slog .Debug ("Loading projects from GitHub repo (push event)" , "loadProjectsOnPush" , loadProjectsOnPush , "ref" , ref , "defaultBranch" , defaultBranch )
422
422
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
428
428
slog .Debug ("Skipping loading projects from GitHub repo" , "loadProjectsOnPush" , loadProjectsOnPush )
429
429
}
430
430
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
+
431
440
return nil
432
441
}
433
442
@@ -914,7 +923,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
914
923
return nil
915
924
}
916
925
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 ) {
918
927
slog .Info ("Getting Digger config for branch" ,
919
928
slog .Group ("repository" ,
920
929
slog .String ("fullName" , repoFullName ),
@@ -954,7 +963,7 @@ func GetDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
954
963
955
964
slog .Debug ("Successfully read digger.yml file" , "configLength" , len (diggerYmlStr ))
956
965
957
- config , _ , dependencyGraph , err = dg_configuration .LoadDiggerConfig (dir , true , changedFiles )
966
+ config , _ , dependencyGraph , _ , err = dg_configuration .LoadDiggerConfig (dir , true , changedFiles , taConfig )
958
967
if err != nil {
959
968
slog .Error ("Error loading and parsing Digger config" ,
960
969
"directory" , dir ,
@@ -1046,6 +1055,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
1046
1055
1047
1056
// check if items should be loaded from cache
1048
1057
useCache := false
1058
+ var taConfig * tac.AtlantisConfig = nil
1049
1059
if val , _ := os .LookupEnv ("DIGGER_CONFIG_REPO_CACHE_ENABLED" ); val == "1" && ! slices .Contains (prLabels , "digger:no-cache" ) {
1050
1060
useCache = true
1051
1061
slog .Info ("Attempting to load config from cache" ,
@@ -1054,7 +1064,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
1054
1064
"prNumber" , prNumber ,
1055
1065
)
1056
1066
1057
- diggerYmlStr , config , dependencyGraph , err := retrieveConfigFromCache (orgId , repoFullName )
1067
+ _ , _ , _ , taConfigTemp , err := retrieveConfigFromCache (orgId , repoFullName )
1058
1068
if err != nil {
1059
1069
slog .Info ("Could not load from cache, falling back to live loading" ,
1060
1070
"orgId" , orgId ,
@@ -1065,9 +1075,8 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
1065
1075
slog .Info ("Successfully loaded config from cache" ,
1066
1076
"orgId" , orgId ,
1067
1077
"repoFullName" , repoFullName ,
1068
- "projectCount" , len (config .Projects ),
1069
1078
)
1070
- return diggerYmlStr , ghService , config , * dependencyGraph , & prBranch , & prCommitSha , changedFiles , nil
1079
+ taConfig = taConfigTemp
1071
1080
}
1072
1081
}
1073
1082
@@ -1084,7 +1093,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
1084
1093
"prNumber" , prNumber ,
1085
1094
)
1086
1095
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 )
1088
1097
if err != nil {
1089
1098
slog .Error ("Error loading Digger config from repository" ,
1090
1099
"prNumber" , prNumber ,
@@ -1098,7 +1107,7 @@ func getDiggerConfigForPR(gh utils.GithubClientProvider, orgId uint, prLabels []
1098
1107
return diggerYmlStr , ghService , config , dependencyGraph , & prBranch , & prCommitSha , changedFiles , nil
1099
1108
}
1100
1109
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 ) {
1102
1111
slog .Debug ("Retrieving config from cache" ,
1103
1112
"orgId" , orgId ,
1104
1113
"repoFullName" , repoFullName ,
@@ -1111,7 +1120,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
1111
1120
"repoFullName" , repoFullName ,
1112
1121
"error" , err ,
1113
1122
)
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 )
1115
1124
}
1116
1125
1117
1126
var config dg_configuration.DiggerConfig
@@ -1122,7 +1131,18 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
1122
1131
"repoFullName" , repoFullName ,
1123
1132
"error" , err ,
1124
1133
)
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 )
1126
1146
}
1127
1147
1128
1148
slog .Debug ("Creating project dependency graph from cached config" ,
@@ -1138,7 +1158,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
1138
1158
"repoFullName" , repoFullName ,
1139
1159
"error" , err ,
1140
1160
)
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 )
1142
1162
}
1143
1163
1144
1164
slog .Info ("Successfully retrieved config from cache" ,
@@ -1147,7 +1167,7 @@ func retrieveConfigFromCache(orgId uint, repoFullName string) (string, *dg_confi
1147
1167
"projectCount" , len (config .Projects ),
1148
1168
)
1149
1169
1150
- return repoCache .DiggerYmlStr , & config , & projectsGraph , nil
1170
+ return repoCache .DiggerYmlStr , & config , & projectsGraph , & taConfig , nil
1151
1171
}
1152
1172
1153
1173
func GetRepoByInstllationId (installationId int64 , repoOwner string , repoName string ) (* models.Repo , error ) {
0 commit comments