From 1e88db8cfe3ae88eb5d1b0633f453cfc72407075 Mon Sep 17 00:00:00 2001 From: Mohamed Habib Date: Sat, 11 Jan 2025 16:36:54 +0000 Subject: [PATCH] fix send correct repo name in setstatus reporting (#1870) * set correct repo in set-status endpoint --- cli/pkg/digger/digger.go | 3 +-- cli/pkg/spec/spec.go | 3 +-- libs/backendapi/diggerapi.go | 6 ++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/pkg/digger/digger.go b/cli/pkg/digger/digger.go index b7c7a1e33..ed3090333 100644 --- a/cli/pkg/digger/digger.go +++ b/cli/pkg/digger/digger.go @@ -131,7 +131,6 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic } currentJob := jobs[0] - repoNameForBackendReporting := strings.ReplaceAll(currentJob.Namespace, "/", "-") projectNameForBackendReporting := currentJob.ProjectName // TODO: handle the apply result summary as well to report it to backend. Possibly reporting changed resources as well // Some kind of generic terraform operation summary might need to be introduced @@ -143,7 +142,7 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic prNumber := *currentJob.PullRequestNumber iacUtils := iac_utils.GetIacUtilsIacType(currentJob.IacType()) - batchResult, err := backendApi.ReportProjectJobStatus(repoNameForBackendReporting, projectNameForBackendReporting, jobId, "succeeded", time.Now(), &summary, "", jobPrCommentUrl, terraformOutput, iacUtils) + batchResult, err := backendApi.ReportProjectJobStatus(currentJob.Namespace, projectNameForBackendReporting, jobId, "succeeded", time.Now(), &summary, "", jobPrCommentUrl, terraformOutput, iacUtils) if err != nil { log.Printf("error reporting Job status: %v.\n", err) return false, false, fmt.Errorf("error while running command: %v", err) diff --git a/cli/pkg/spec/spec.go b/cli/pkg/spec/spec.go index 9647013a6..bfbcf4d77 100644 --- a/cli/pkg/spec/spec.go +++ b/cli/pkg/spec/spec.go @@ -137,8 +137,7 @@ func RunSpec( jobs := []scheduler.Job{job} - fullRepoName := fmt.Sprintf("%v-%v", spec.VCS.RepoOwner, spec.VCS.RepoName) - _, err = backendApi.ReportProjectJobStatus(fullRepoName, spec.Job.ProjectName, spec.JobId, "started", time.Now(), nil, "", "", "", nil) + _, err = backendApi.ReportProjectJobStatus(spec.VCS.RepoName, spec.Job.ProjectName, spec.JobId, "started", time.Now(), nil, "", "", "", nil) if err != nil { message := fmt.Sprintf("Failed to report jobSpec status to backend. Exiting. %v", err) reportError(spec, backendApi, message, err) diff --git a/libs/backendapi/diggerapi.go b/libs/backendapi/diggerapi.go index 145a13e2f..fadd2ef53 100644 --- a/libs/backendapi/diggerapi.go +++ b/libs/backendapi/diggerapi.go @@ -15,6 +15,7 @@ import ( "os" "path" "path/filepath" + "strings" "time" ) @@ -129,7 +130,8 @@ func (d DiggerApi) ReportProjectRun(namespace string, projectName string, starte return nil } -func (d DiggerApi) ReportProjectJobStatus(repo string, projectName string, jobId string, status string, timestamp time.Time, summary *iac_utils.IacSummary, planJson string, PrCommentUrl string, terraformOutput string, iacUtils iac_utils.IacUtils) (*scheduler.SerializedBatch, error) { +func (d DiggerApi) ReportProjectJobStatus(repoFullName string, projectName string, jobId string, status string, timestamp time.Time, summary *iac_utils.IacSummary, planJson string, PrCommentUrl string, terraformOutput string, iacUtils iac_utils.IacUtils) (*scheduler.SerializedBatch, error) { + repoNameForBackendReporting := strings.ReplaceAll(repoFullName, "/", "-") u, err := url.Parse(d.DiggerHost) if err != nil { log.Fatalf("Not able to parse digger cloud url: %v", err) @@ -152,7 +154,7 @@ func (d DiggerApi) ReportProjectJobStatus(repo string, projectName string, jobId } } - u.Path = filepath.Join(u.Path, "repos", repo, "projects", projectName, "jobs", jobId, "set-status") + u.Path = filepath.Join(u.Path, "repos", repoNameForBackendReporting, "projects", projectName, "jobs", jobId, "set-status") request := map[string]interface{}{ "status": status, "timestamp": timestamp,