@@ -16,7 +16,6 @@ import (
16
16
"github.com/diggerhq/digger/backend/models"
17
17
"github.com/diggerhq/digger/backend/services"
18
18
"github.com/diggerhq/digger/backend/utils"
19
- "github.com/diggerhq/digger/libs/ci"
20
19
"github.com/diggerhq/digger/libs/comment_utils/reporting"
21
20
"github.com/diggerhq/digger/libs/digger_config"
22
21
"github.com/diggerhq/digger/libs/iac_utils"
@@ -624,6 +623,7 @@ type SetJobStatusRequest struct {
624
623
WorkflowUrl string `json:"workflow_url,omitempty"`
625
624
}
626
625
626
+
627
627
func (d DiggerController ) SetJobStatusForProject (c * gin.Context ) {
628
628
jobId := c .Param ("jobId" )
629
629
orgId , exists := c .Get (middleware .ORGANISATION_ID_KEY )
@@ -663,6 +663,42 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
663
663
)
664
664
665
665
switch request .Status {
666
+ case "created" :
667
+ job .Status = orchestrator_scheduler .DiggerJobCreated
668
+ err := models .DB .UpdateDiggerJob (job )
669
+ if err != nil {
670
+ slog .Error ("Error updating job status" ,
671
+ "jobId" , jobId ,
672
+ "status" , request .Status ,
673
+ "error" , err ,
674
+ )
675
+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Error updating job status" })
676
+ return
677
+ }
678
+
679
+ slog .Info ("Job status updated to created" , "jobId" , jobId )
680
+
681
+ // Update PR comment with real-time status
682
+ go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "created" )
683
+
684
+ case "triggered" :
685
+ job .Status = orchestrator_scheduler .DiggerJobTriggered
686
+ err := models .DB .UpdateDiggerJob (job )
687
+ if err != nil {
688
+ slog .Error ("Error updating job status" ,
689
+ "jobId" , jobId ,
690
+ "status" , request .Status ,
691
+ "error" , err ,
692
+ )
693
+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Error updating job status" })
694
+ return
695
+ }
696
+
697
+ slog .Info ("Job status updated to triggered" , "jobId" , jobId )
698
+
699
+ // Update PR comment with real-time status
700
+ go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "triggered" )
701
+
666
702
case "started" :
667
703
job .Status = orchestrator_scheduler .DiggerJobStarted
668
704
if request .WorkflowUrl != "" {
@@ -682,6 +718,9 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
682
718
683
719
slog .Info ("Job status updated to started" , "jobId" , jobId )
684
720
721
+ // Update PR comment with real-time status
722
+ go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "started" )
723
+
685
724
case "succeeded" :
686
725
job .Status = orchestrator_scheduler .DiggerJobSucceeded
687
726
job .TerraformOutput = request .TerraformOutput
@@ -839,6 +878,9 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
839
878
models .DB .UpdateDiggerJobSummary (job .DiggerJobID , request .JobSummary .ResourcesCreated , request .JobSummary .ResourcesUpdated , request .JobSummary .ResourcesDeleted )
840
879
}
841
880
881
+ // Update PR comment with real-time status for succeeded job
882
+ go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "succeeded" )
883
+
842
884
case "failed" :
843
885
job .Status = orchestrator_scheduler .DiggerJobFailed
844
886
job .TerraformOutput = request .TerraformOutput
@@ -858,12 +900,15 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
858
900
"batchId" , batchId ,
859
901
)
860
902
903
+ // Update PR comment with real-time status for failed job
904
+ go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "failed" )
905
+
861
906
default :
862
907
slog .Warn ("Unexpected job status received" ,
863
908
"jobId" , jobId ,
864
909
"status" , request .Status ,
865
910
)
866
- c .JSON (http .StatusBadRequest , gin.H {"error" : "Unexpected job status" })
911
+ c .JSON (http .StatusBadRequest , gin.H {"error" : fmt . Sprintf ( "Unexpected job status: %s. Valid statuses are: created, triggered, started, succeeded, failed" , request . Status ) })
867
912
return
868
913
}
869
914
@@ -965,6 +1010,12 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
965
1010
c .JSON (http .StatusOK , res )
966
1011
}
967
1012
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
968
1019
func updateWorkflowUrlForJob (githubClientProvider utils.GithubClientProvider , job * models.DiggerJob ) error {
969
1020
if job == nil {
970
1021
return fmt .Errorf ("job is nil" )
@@ -1153,80 +1204,6 @@ func UpdateCommentsForBatchGroup(gh utils.GithubClientProvider, batch *models.Di
1153
1204
return nil
1154
1205
}
1155
1206
1156
- func GetPrServiceFromBatch (batch * models.DiggerBatch , gh utils.GithubClientProvider ) (ci.PullRequestService , error ) {
1157
- slog .Debug ("Getting PR service for batch" ,
1158
- "batchId" , batch .ID ,
1159
- "vcs" , batch .VCS ,
1160
- "prNumber" , batch .PrNumber ,
1161
- )
1162
-
1163
- switch batch .VCS {
1164
- case "github" :
1165
- slog .Debug ("Using GitHub service for batch" ,
1166
- "batchId" , batch .ID ,
1167
- "installationId" , batch .GithubInstallationId ,
1168
- "repoFullName" , batch .RepoFullName ,
1169
- )
1170
-
1171
- service , _ , err := utils .GetGithubService (
1172
- gh ,
1173
- batch .GithubInstallationId ,
1174
- batch .RepoFullName ,
1175
- batch .RepoOwner ,
1176
- batch .RepoName ,
1177
- )
1178
-
1179
- if err != nil {
1180
- slog .Error ("Error getting GitHub service" ,
1181
- "batchId" , batch .ID ,
1182
- "repoFullName" , batch .RepoFullName ,
1183
- "error" , err ,
1184
- )
1185
- } else {
1186
- slog .Debug ("Successfully got GitHub service" ,
1187
- "batchId" , batch .ID ,
1188
- "repoFullName" , batch .RepoFullName ,
1189
- )
1190
- }
1191
-
1192
- return service , err
1193
-
1194
- case "gitlab" :
1195
- slog .Debug ("Using GitLab service for batch" ,
1196
- "batchId" , batch .ID ,
1197
- "projectId" , batch .GitlabProjectId ,
1198
- "repoFullName" , batch .RepoFullName ,
1199
- )
1200
-
1201
- service , err := utils .GetGitlabService (
1202
- utils.GitlabClientProvider {},
1203
- batch .GitlabProjectId ,
1204
- batch .RepoName ,
1205
- batch .RepoFullName ,
1206
- batch .PrNumber ,
1207
- "" ,
1208
- )
1209
-
1210
- if err != nil {
1211
- slog .Error ("Error getting GitLab service" ,
1212
- "batchId" , batch .ID ,
1213
- "projectId" , batch .GitlabProjectId ,
1214
- "error" , err ,
1215
- )
1216
- } else {
1217
- slog .Debug ("Successfully got GitLab service" ,
1218
- "batchId" , batch .ID ,
1219
- "projectId" , batch .GitlabProjectId ,
1220
- )
1221
- }
1222
-
1223
- return service , err
1224
- }
1225
-
1226
- slog .Error ("Unsupported VCS type" , "vcs" , batch .VCS , "batchId" , batch .ID )
1227
- return nil , fmt .Errorf ("could not retrieve a service for %v" , batch .VCS )
1228
- }
1229
-
1230
1207
func CreateTerraformOutputsSummary (gh utils.GithubClientProvider , batch * models.DiggerBatch ) error {
1231
1208
slog .Info ("Creating Terraform outputs summary" ,
1232
1209
"batchId" , batch .ID ,
@@ -1259,7 +1236,7 @@ func CreateTerraformOutputsSummary(gh utils.GithubClientProvider, batch *models.
1259
1236
"prNumber" , batch .PrNumber ,
1260
1237
)
1261
1238
1262
- prService , err := GetPrServiceFromBatch (batch , gh )
1239
+ prService , err := utils . GetPrServiceFromBatch (batch , gh )
1263
1240
if err != nil {
1264
1241
slog .Error ("Error getting PR service" ,
1265
1242
"batchId" , batch .ID ,
@@ -1462,7 +1439,7 @@ func AutomergePRforBatchIfEnabled(gh utils.GithubClientProvider, batch *models.D
1462
1439
"prNumber" , batch .PrNumber ,
1463
1440
)
1464
1441
1465
- prService , err := GetPrServiceFromBatch (batch , gh )
1442
+ prService , err := utils . GetPrServiceFromBatch (batch , gh )
1466
1443
if err != nil {
1467
1444
slog .Error ("Error getting PR service" ,
1468
1445
"batchId" , batch .ID ,
@@ -1554,7 +1531,7 @@ func DeleteOlderPRCommentsIfEnabled(gh utils.GithubClientProvider, batch *models
1554
1531
"prNumber" , batch .PrNumber ,
1555
1532
)
1556
1533
1557
- prService , err := GetPrServiceFromBatch (batch , gh )
1534
+ prService , err := utils . GetPrServiceFromBatch (batch , gh )
1558
1535
if err != nil {
1559
1536
slog .Error ("Error getting PR service" ,
1560
1537
"batchId" , batch .ID ,
0 commit comments