@@ -621,6 +621,7 @@ type SetJobStatusRequest struct {
621621 PrCommentUrl string `json:"pr_comment_url"`
622622 PrCommentId string `json:"pr_comment_id"`
623623 TerraformOutput string `json:"terraform_output"`
624+ WorkflowUrl string `json:"workflow_url,omitempty"`
624625}
625626
626627func (d DiggerController ) SetJobStatusForProject (c * gin.Context ) {
@@ -664,6 +665,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
664665 switch request .Status {
665666 case "started" :
666667 job .Status = orchestrator_scheduler .DiggerJobStarted
668+ if request .WorkflowUrl != "" {
669+ slog .Debug ("Adding workflow url to job" , "jobId" , jobId , "workflowUrl" , request .WorkflowUrl )
670+ job .WorkflowRunUrl = & request .WorkflowUrl
671+ }
667672 err := models .DB .UpdateDiggerJob (job )
668673 if err != nil {
669674 slog .Error ("Error updating job status" ,
@@ -862,44 +867,13 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
862867 return
863868 }
864869
865- // attempt to update workflow run url
870+ // attempt to update workflow run url, note we only have this for backwards compatibility with
871+ // older digger cli versions, newer cli versions after v0.6.110 will send the workflow url so
872+ // we don't need to pull API, saving us rate limit exceeded errors
866873 slog .Debug ("Attempting to update workflow run URL" , "jobId" , jobId )
867-
868- client , _ , err := utils .GetGithubClient (d .GithubClientProvider , job .Batch .GithubInstallationId , job .Batch .RepoFullName )
874+ err = updateWorkflowUrlForJob (d .GithubClientProvider , job )
869875 if err != nil {
870- slog .Warn ("Error creating GitHub client for workflow URL update" ,
871- "jobId" , jobId ,
872- "repoFullName" , job .Batch .RepoFullName ,
873- "error" , err ,
874- )
875- } else {
876- _ , workflowRunUrl , err := utils .GetWorkflowIdAndUrlFromDiggerJobId (
877- client ,
878- job .Batch .RepoOwner ,
879- job .Batch .RepoName ,
880- job .DiggerJobID ,
881- )
882- if err != nil {
883- slog .Warn ("Error getting workflow ID from job" ,
884- "jobId" , jobId ,
885- "error" , err ,
886- )
887- } else if workflowRunUrl != "#" && workflowRunUrl != "" {
888- job .WorkflowRunUrl = & workflowRunUrl
889- err = models .DB .UpdateDiggerJob (job )
890- if err != nil {
891- slog .Error ("Error updating job with workflow URL" ,
892- "jobId" , jobId ,
893- "workflowUrl" , workflowRunUrl ,
894- "error" , err ,
895- )
896- } else {
897- slog .Debug ("Updated job with workflow URL" ,
898- "jobId" , jobId ,
899- "workflowUrl" , workflowRunUrl ,
900- )
901- }
902- }
876+ slog .Warn ("Failed to update workflow run URL" , "jobId" , jobId , "error" , err )
903877 }
904878
905879 job .StatusUpdatedAt = request .Timestamp
@@ -991,6 +965,63 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
991965 c .JSON (http .StatusOK , res )
992966}
993967
968+ func updateWorkflowUrlForJob (githubClientProvider utils.GithubClientProvider , job * models.DiggerJob ) error {
969+ if job == nil {
970+ return fmt .Errorf ("job is nil" )
971+ }
972+ if job .WorkflowRunUrl != nil && * job .WorkflowRunUrl != "#" && * job .WorkflowRunUrl != "" {
973+ slog .Debug ("Workflow URL already exists" , "jobId" , job .DiggerJobID )
974+ return nil
975+ }
976+ jobId := job .DiggerJobID
977+ client , _ , err := utils .GetGithubClient (githubClientProvider , job .Batch .GithubInstallationId , job .Batch .RepoFullName )
978+ if err != nil {
979+ slog .Warn ("Error creating GitHub client for workflow URL update" ,
980+ "jobId" , jobId ,
981+ "repoFullName" , job .Batch .RepoFullName ,
982+ "error" , err ,
983+ )
984+ return fmt .Errorf ("error creating GitHub client for workflow URL update: %v" , err )
985+ }
986+
987+ _ , workflowRunUrl , err := utils .GetWorkflowIdAndUrlFromDiggerJobId (
988+ client ,
989+ job .Batch .RepoOwner ,
990+ job .Batch .RepoName ,
991+ job .DiggerJobID ,
992+ )
993+ if err != nil {
994+ slog .Warn ("Error getting workflow ID from job" ,
995+ "jobId" , jobId ,
996+ "error" , err ,
997+ )
998+ return fmt .Errorf ("error getting workflow ID from job: %v" , err )
999+ }
1000+
1001+ if workflowRunUrl != "#" && workflowRunUrl != "" {
1002+ job .WorkflowRunUrl = & workflowRunUrl
1003+ err = models .DB .UpdateDiggerJob (job )
1004+ if err != nil {
1005+ slog .Error ("Error updating job with workflow URL" ,
1006+ "jobId" , jobId ,
1007+ "workflowUrl" , workflowRunUrl ,
1008+ "error" , err ,
1009+ )
1010+ return fmt .Errorf ("error updating job with workflow URL: %v" , err )
1011+ } else {
1012+ slog .Debug ("Updated job with workflow URL" ,
1013+ "jobId" , jobId ,
1014+ "workflowUrl" , workflowRunUrl ,
1015+ )
1016+ }
1017+ } else {
1018+ slog .Debug ("Workflow URL not found for job" ,
1019+ "jobId" , jobId )
1020+ return fmt .Errorf ("workflow URL not found for job (workflowUrl returned: %v)" , workflowRunUrl )
1021+ }
1022+ return nil
1023+ }
1024+
9941025type CreateProjectRunRequest struct {
9951026 StartedAt time.Time `json:"startedAt"`
9961027 EndedAt time.Time `json:"endedAt"`
0 commit comments