Skip to content

Commit 70f6598

Browse files
committed
always refresh workflow url
1 parent 9dcd64a commit 70f6598

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

backend/controllers/projects.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,6 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
364364
return
365365
}
366366

367-
client, _, err := utils.GetGithubClient(d.GithubClientProvider, job.Batch.GithubInstallationId, job.Batch.RepoFullName)
368-
if err != nil {
369-
log.Printf("Error Creating github client: %v", err)
370-
} else {
371-
_, workflowRunUrl, err := utils.GetWorkflowIdAndUrlFromDiggerJobId(client, job.Batch.RepoOwner, job.Batch.RepoName, job.DiggerJobID)
372-
if err != nil {
373-
log.Printf("Error getting workflow ID from job: %v", err)
374-
} else {
375-
job.WorkflowRunUrl = &workflowRunUrl
376-
err = models.DB.UpdateDiggerJob(job)
377-
if err != nil {
378-
log.Printf("Error updating digger job: %v", err)
379-
}
380-
}
381-
}
382367
case "succeeded":
383368
job.Status = orchestrator_scheduler.DiggerJobSucceeded
384369
job.TerraformOutput = request.TerraformOutput
@@ -463,6 +448,24 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
463448
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error saving job"})
464449
return
465450
}
451+
452+
// attempt to update workflow run url
453+
client, _, err := utils.GetGithubClient(d.GithubClientProvider, job.Batch.GithubInstallationId, job.Batch.RepoFullName)
454+
if err != nil {
455+
log.Printf("Error Creating github client: %v", err)
456+
} else {
457+
_, workflowRunUrl, err := utils.GetWorkflowIdAndUrlFromDiggerJobId(client, job.Batch.RepoOwner, job.Batch.RepoName, job.DiggerJobID)
458+
if err != nil {
459+
log.Printf("Error getting workflow ID from job: %v", err)
460+
} else if workflowRunUrl != "#" && workflowRunUrl != "" {
461+
job.WorkflowRunUrl = &workflowRunUrl
462+
err = models.DB.UpdateDiggerJob(job)
463+
if err != nil {
464+
log.Printf("Error updating digger job: %v", err)
465+
}
466+
}
467+
}
468+
466469
job.StatusUpdatedAt = request.Timestamp
467470
err = models.DB.GormDB.Save(&job).Error
468471
if err != nil {

backend/services/scheduler.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/diggerhq/digger/backend/config"
77
"github.com/diggerhq/digger/backend/models"
88
"github.com/diggerhq/digger/backend/utils"
9-
comment_updater "github.com/diggerhq/digger/libs/comment_utils/summary"
109
orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
1110
"github.com/diggerhq/digger/libs/spec"
1211
"github.com/google/go-github/v61/github"
@@ -135,14 +134,13 @@ func TriggerJob(gh utils.GithubClientProvider, ciBackend ci_backends.CiBackend,
135134
return err
136135
}
137136

138-
go UpdateWorkflowUrlForJob(job, ciBackend, spec, gh)
137+
go UpdateWorkflowUrlForJob(job, ciBackend, spec)
139138

140139
return nil
141140
}
142141

143142
// This is meant to run asyncronously since it queries for job url
144-
// in case of github we don't get it immediately but with some delay
145-
func UpdateWorkflowUrlForJob(job *models.DiggerJob, ciBackend ci_backends.CiBackend, spec *spec.Spec, gh utils.GithubClientProvider) {
143+
func UpdateWorkflowUrlForJob(job *models.DiggerJob, ciBackend ci_backends.CiBackend, spec *spec.Spec) {
146144
defer func() {
147145
if r := recover(); r != nil {
148146
log.Printf("Recovered from panic in UpdateWorkflowUrlForJob handler: %v", r)
@@ -176,27 +174,10 @@ func UpdateWorkflowUrlForJob(job *models.DiggerJob, ciBackend ci_backends.CiBack
176174
log.Printf("DiggerJobId %v: successfully updated workflow run url to: %v for DiggerJobID: %v", job.DiggerJobID, workflowUrl, job.DiggerJobID)
177175
}
178176

179-
// refresh the batch from DB to get accurate results
180-
batch, err = models.DB.GetDiggerBatch(&job.Batch.ID)
181-
if err != nil {
182-
log.Printf("DiggerJobId %v: Error getting batch: %v", job.DiggerJobID, err)
183-
continue
184-
}
185-
res, err := batch.MapToJsonStruct()
186-
if err != nil {
187-
log.Printf("DiggerJobId %v: Error getting batch details: %v", job.DiggerJobID, err)
188-
continue
189-
}
190-
// TODO: make this abstract and extracting the right "prService" based on VCS
191-
client, _, err := utils.GetGithubService(gh, batch.GithubInstallationId, spec.VCS.RepoFullname, spec.VCS.RepoOwner, spec.VCS.RepoName)
192-
err = comment_updater.BasicCommentUpdater{}.UpdateComment(res.Jobs, *spec.Job.PullRequestNumber, client, spec.CommentId)
193-
if err != nil {
194-
log.Printf("diggerJobId: %v error whilst updating comment %v", job.DiggerJobID, err)
195-
continue
196-
}
197177
return
198178
}
199179
}
200180
}
201181

182+
// if we get to here its highly likely that the workflow job entirely failed to start for some reason
202183
}

0 commit comments

Comments
 (0)