diff --git a/docs/pipelines.md b/docs/pipelines.md index 249e0ddce..2f90c525c 100644 --- a/docs/pipelines.md +++ b/docs/pipelines.md @@ -228,3 +228,8 @@ spec: ``` e.g. here is [an example](../pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml#L8) which generates this [PipelineRun](../pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml#L154) + +## Override scm status url from pipeline + +If a pipeline has a result named `scm-status-url` the value of that will be used as link target for the pipeline status +set in scm provider (like GitHub or GitLab) instead of the link to the pipeline dashboard. \ No newline at end of file diff --git a/pkg/engines/tekton/activity.go b/pkg/engines/tekton/activity.go index 429780bcf..06bd0fc8c 100644 --- a/pkg/engines/tekton/activity.go +++ b/pkg/engines/tekton/activity.go @@ -15,12 +15,12 @@ import ( ) // ConvertPipelineRun translates a PipelineRun into an ActivityRecord -func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord { +func ConvertPipelineRun(pr *v1beta1.PipelineRun) (record *v1alpha1.ActivityRecord, resultUrl string) { if pr == nil { - return nil + return } - record := new(v1alpha1.ActivityRecord) + record = new(v1alpha1.ActivityRecord) record.Name = pr.Name @@ -41,6 +41,13 @@ func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord { record.Status = convertTektonStatus(cond, record.StartTime, record.CompletionTime) + for i := range pr.Status.PipelineResults { + res := pr.Status.PipelineResults[i] + if res.Name == tektonResultScmStatusUrl { + resultUrl = res.Value.StringVal + } + } + for _, taskName := range sets.StringKeySet(pr.Status.TaskRuns).List() { task := pr.Status.TaskRuns[taskName] cleanedUpTaskName := strings.TrimPrefix(taskName[:len(taskName)-6], pr.Name+"-") @@ -80,7 +87,7 @@ func ConvertPipelineRun(pr *v1beta1.PipelineRun) *v1alpha1.ActivityRecord { } // log URL is definitely gonna wait - return record + return } func convertTektonStatus(cond *apis.Condition, start, finished *metav1.Time) v1alpha1.PipelineState { diff --git a/pkg/engines/tekton/activity_test.go b/pkg/engines/tekton/activity_test.go index 791b22c98..f6259088a 100644 --- a/pkg/engines/tekton/activity_test.go +++ b/pkg/engines/tekton/activity_test.go @@ -40,7 +40,7 @@ func TestConvertPipelineRun(t *testing.T) { testDir := filepath.Join("test_data", "activity", tc.name) pr := loadPipelineRun(t, testDir) - converted := tekton.ConvertPipelineRun(pr) + converted, _ := tekton.ConvertPipelineRun(pr) expected := loadRecord(t, testDir) diff --git a/pkg/engines/tekton/controller.go b/pkg/engines/tekton/controller.go index 73f24499f..d369c925c 100644 --- a/pkg/engines/tekton/controller.go +++ b/pkg/engines/tekton/controller.go @@ -176,10 +176,10 @@ func (r *LighthouseJobReconciler) Reconcile(ctx context.Context, req ctrl.Reques } f := func(job *lighthousev1alpha1.LighthouseJob) error { - if r.dashboardURL != "" { + job.Status.Activity, job.Status.ReportURL = ConvertPipelineRun(&pipelineRun) + if job.Status.ReportURL == "" && r.dashboardURL != "" { job.Status.ReportURL = r.getPipelingetPipelineTargetURLeTargetURL(pipelineRun) } - job.Status.Activity = ConvertPipelineRun(&pipelineRun) if err := r.client.Status().Update(ctx, job); err != nil { return errors.Wrapf(err, "failed to update LighthouseJob status") } diff --git a/pkg/engines/tekton/utils.go b/pkg/engines/tekton/utils.go index dcb0dc52b..5c06efef0 100644 --- a/pkg/engines/tekton/utils.go +++ b/pkg/engines/tekton/utils.go @@ -19,12 +19,13 @@ import ( ) const ( - controllerName = "tekton-controller" - gitCloneCatalogTaskName = "git-clone" - gitCloneURLParam = "url" - gitCloneRevisionParam = "revision" - gitMergeCatalogTaskName = "git-batch-merge" - gitMergeBatchRefsParam = "batchedRefs" + controllerName = "tekton-controller" + gitCloneCatalogTaskName = "git-clone" + gitCloneURLParam = "url" + gitCloneRevisionParam = "revision" + gitMergeCatalogTaskName = "git-batch-merge" + gitMergeBatchRefsParam = "batchedRefs" + tektonResultScmStatusUrl = "scm-status-url" ) type buildIDGenerator interface {