@@ -23,40 +23,40 @@ import (
2323
2424func gitHubCI (lock locking.Lock ) {
2525 println ("Using GitHub." )
26- githubRepositoryOwner := os .Getenv ("GITHUB_REPOSITORY_OWNER " )
27- if githubRepositoryOwner != "" {
28- usage .SendUsageRecord (githubRepositoryOwner , "log" , "initialize" )
26+ githubActor := os .Getenv ("GITHUB_ACTOR " )
27+ if githubActor != "" {
28+ usage .SendUsageRecord (githubActor , "log" , "initialize" )
2929 } else {
3030 usage .SendUsageRecord ("" , "log" , "non github initialisation" )
3131 }
3232
3333 ghToken := os .Getenv ("GITHUB_TOKEN" )
3434 if ghToken == "" {
35- reportErrorAndExit (githubRepositoryOwner , "GITHUB_TOKEN is not defined" , 1 )
35+ reportErrorAndExit (githubActor , "GITHUB_TOKEN is not defined" , 1 )
3636 }
3737
3838 ghContext := os .Getenv ("GITHUB_CONTEXT" )
3939 if ghContext == "" {
40- reportErrorAndExit (githubRepositoryOwner , "GITHUB_CONTEXT is not defined" , 2 )
40+ reportErrorAndExit (githubActor , "GITHUB_CONTEXT is not defined" , 2 )
4141 }
4242
4343 parsedGhContext , err := github_models .GetGitHubContext (ghContext )
4444 if err != nil {
45- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to parse GitHub context. %s" , err ), 3 )
45+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to parse GitHub context. %s" , err ), 3 )
4646 }
4747 println ("GitHub context parsed successfully" )
4848
4949 walker := configuration.FileSystemDirWalker {}
5050
5151 diggerConfig , err := configuration .LoadDiggerConfig ("./" , & walker )
5252 if err != nil {
53- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to read Digger config. %s" , err ), 4 )
53+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to read Digger config. %s" , err ), 4 )
5454 }
5555 println ("Digger config read successfully" )
5656
5757 lock , err = locking .GetLock ()
5858 if err != nil {
59- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to create lock provider. %s" , err ), 5 )
59+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to create lock provider. %s" , err ), 5 )
6060 }
6161 println ("Lock provider has been created successfully" )
6262
@@ -68,7 +68,7 @@ func gitHubCI(lock locking.Lock) {
6868
6969 impactedProjects , requestedProject , prNumber , err := dg_github .ProcessGitHubEvent (ghEvent , diggerConfig , githubPrService )
7070 if err != nil {
71- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to process GitHub event. %s" , err ), 6 )
71+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to process GitHub event. %s" , err ), 6 )
7272 }
7373 logImpactedProjects (impactedProjects , prNumber )
7474 println ("GitHub event processed successfully" )
@@ -77,26 +77,26 @@ func gitHubCI(lock locking.Lock) {
7777 reply := utils .GetCommands ()
7878 err := githubPrService .PublishComment (prNumber , reply )
7979 if err != nil {
80- reportErrorAndExit (githubRepositoryOwner , "Failed to publish help command output" , 1 )
80+ reportErrorAndExit (githubActor , "Failed to publish help command output" , 1 )
8181 }
8282 }
8383
8484 if len (impactedProjects ) == 0 {
85- reportErrorAndExit (githubRepositoryOwner , "No projects impacted" , 0 )
85+ reportErrorAndExit (githubActor , "No projects impacted" , 0 )
8686 }
8787
8888 commandsToRunPerProject , coversAllImpactedProjects , err := dg_github .ConvertGithubEventToCommands (ghEvent , impactedProjects , requestedProject , diggerConfig .Workflows )
8989 if err != nil {
90- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to convert GitHub event to commands. %s" , err ), 7 )
90+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to convert GitHub event to commands. %s" , err ), 7 )
9191 }
9292 println ("GitHub event converted to commands successfully" )
9393 logCommands (commandsToRunPerProject )
9494
95- planStorage := newPlanStorage (ghToken , repoOwner , repositoryName , prNumber )
95+ planStorage := newPlanStorage (ghToken , repoOwner , repositoryName , githubActor , prNumber )
9696
97- allAppliesSuccessful , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , repoOwner , repositoryName , eventName , prNumber , githubPrService , lock , planStorage , "" )
97+ allAppliesSuccessful , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , parsedGhContext . Repository , githubActor , eventName , prNumber , githubPrService , lock , planStorage , "" )
9898 if err != nil {
99- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Failed to run commands. %s" , err ), 8 )
99+ reportErrorAndExit (githubActor , fmt .Sprintf ("Failed to run commands. %s" , err ), 8 )
100100 }
101101
102102 if diggerConfig .AutoMerge && allAppliesSuccessful && atLeastOneApply && coversAllImpactedProjects {
@@ -106,11 +106,11 @@ func gitHubCI(lock locking.Lock) {
106106
107107 println ("Commands executed successfully" )
108108
109- reportErrorAndExit (githubRepositoryOwner , "Digger finished successfully" , 0 )
109+ reportErrorAndExit (githubActor , "Digger finished successfully" , 0 )
110110
111111 defer func () {
112112 if r := recover (); r != nil {
113- reportErrorAndExit (githubRepositoryOwner , fmt .Sprintf ("Panic occurred. %s" , r ), 1 )
113+ reportErrorAndExit (githubActor , fmt .Sprintf ("Panic occurred. %s" , r ), 1 )
114114 }
115115 }()
116116}
@@ -177,10 +177,11 @@ func gitLabCI(lock locking.Lock) {
177177 fmt .Printf ("command: %s, project: %s\n " , strings .Join (v .Commands , ", " ), v .ProjectName )
178178 }
179179
180- //planStorage := newPlanStorage(ghToken, repoOwner, repositoryName, prNumber)
181- planStorage := newPlanStorage (gitlabToken , projectNamespace , projectName , * gitLabContext .MergeRequestIId )
180+ diggerProjectNamespace := gitLabContext .ProjectNamespace + "/" + gitLabContext .ProjectName
181+ planStorage := newPlanStorage ("" , "" , "" , gitLabContext .GitlabUserName , * gitLabContext .MergeRequestIId )
182+
183+ allAppliesSuccess , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , diggerProjectNamespace , gitLabContext .GitlabUserName , gitLabContext .EventType .String (), * gitLabContext .MergeRequestIId , gitlabService , lock , planStorage , currentDir )
182184
183- allAppliesSuccess , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , gitLabContext .ProjectNamespace , gitLabContext .ProjectName , gitLabContext .EventType .String (), * gitLabContext .MergeRequestIId , gitlabService , lock , planStorage , currentDir )
184185 if err != nil {
185186 fmt .Printf ("failed to execute command, %v" , err )
186187 os .Exit (8 )
@@ -251,8 +252,9 @@ func azureCI(lock locking.Lock) {
251252 }
252253
253254 var planStorage storage.PlanStorage
255+ diggerProjectNamespace := parsedAzureContext .BaseUrl + "/" + parsedAzureContext .ProjectName
254256
255- allAppliesSuccess , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , parsedAzureContext . ProjectName , parsedAzureContext .ProjectName , parsedAzureContext .EventType , prNumber , azureService , lock , planStorage , currentDir )
257+ allAppliesSuccess , atLeastOneApply , err := digger .RunCommandsPerProject (commandsToRunPerProject , diggerProjectNamespace , parsedAzureContext .BaseUrl , parsedAzureContext .EventType , prNumber , azureService , lock , planStorage , currentDir )
256258 if err != nil {
257259 reportErrorAndExit (parsedAzureContext .BaseUrl , fmt .Sprintf ("Failed to run commands. %s" , err ), 8 )
258260 }
@@ -320,24 +322,24 @@ func main() {
320322 }
321323}
322324
323- func newPlanStorage (ghToken string , repoOwner string , repositoryName string , prNumber int ) storage.PlanStorage {
325+ func newPlanStorage (ghToken string , ghRepoOwner string , ghRepositoryName string , requestedBy string , prNumber int ) storage.PlanStorage {
324326 var planStorage storage.PlanStorage
325327
326328 uploadDestination := strings .ToLower (os .Getenv ("PLAN_UPLOAD_DESTINATION" ))
327329 if uploadDestination == "github" {
328330 zipManager := utils.Zipper {}
329331 planStorage = & storage.GithubPlanStorage {
330332 Client : github .NewTokenClient (context .Background (), ghToken ),
331- Owner : repoOwner ,
332- RepoName : repositoryName ,
333+ Owner : ghRepoOwner ,
334+ RepoName : ghRepositoryName ,
333335 PullRequestNumber : prNumber ,
334336 ZipManager : zipManager ,
335337 }
336338 } else if uploadDestination == "gcp" {
337339 ctx , client := gcp .GetGoogleStorageClient ()
338340 bucketName := strings .ToLower (os .Getenv ("GOOGLE_STORAGE_BUCKET" ))
339341 if bucketName == "" {
340- reportErrorAndExit (repoOwner , fmt .Sprintf ("GOOGLE_STORAGE_BUCKET is not defined" ), 9 )
342+ reportErrorAndExit (requestedBy , fmt .Sprintf ("GOOGLE_STORAGE_BUCKET is not defined" ), 9 )
341343 }
342344 bucket := client .Bucket (bucketName )
343345 planStorage = & storage.PlanStorageGcp {
0 commit comments