From 17043bc881dd079a871b89cabc7f52dd47950de0 Mon Sep 17 00:00:00 2001 From: Alan Greene Date: Tue, 20 Feb 2024 17:55:54 +0000 Subject: [PATCH] Add support for displayName from childReferences Update utils to support pulling the pipeline task `displayName` from the run's `status.childReferences`. This adds support for dynamic matrix display names, and provides a consistent location to retrieve the resolve display name value after param substitution etc. has taken place. --- packages/utils/src/utils/index.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/utils/index.js b/packages/utils/src/utils/index.js index 6c72b02f47..cd68517fab 100644 --- a/packages/utils/src/utils/index.js +++ b/packages/utils/src/utils/index.js @@ -1,5 +1,5 @@ /* -Copyright 2019-2023 The Tekton Authors +Copyright 2019-2024 The Tekton Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -448,8 +448,9 @@ export function getPlaceholderTaskRun({ clusterTasks, pipelineTask, tasks }) { }; } -function addDashboardLabels({ pipelineTask, taskRun }) { - const { description, displayName } = pipelineTask; +function addDashboardLabels({ displayName, pipelineTask, taskRun }) { + const { description, displayName: pipelineTaskDisplayName } = pipelineTask; + const displayNameToUse = displayName || pipelineTaskDisplayName; // eslint-disable-next-line no-param-reassign taskRun.metadata.labels = { ...taskRun.metadata.labels, @@ -458,9 +459,9 @@ function addDashboardLabels({ pipelineTask, taskRun }) { [labelConstants.DASHBOARD_DESCRIPTION]: description } : null), - ...(displayName + ...(displayNameToUse ? { - [labelConstants.DASHBOARD_DISPLAY_NAME]: displayName + [labelConstants.DASHBOARD_DISPLAY_NAME]: displayNameToUse } : null) }; @@ -475,6 +476,7 @@ export function getTaskRunsWithPlaceholders({ tasks }) { let pipelineTasks = []; + const childReferences = pipelineRun?.status?.childReferences || []; if (pipelineRun?.status?.pipelineSpec?.tasks) { pipelineTasks = pipelineTasks.concat(pipelineRun.status.pipelineSpec.tasks); @@ -502,8 +504,23 @@ export function getTaskRunsWithPlaceholders({ pipelineTask.name ); + const displayNames = childReferences.reduce((acc, childReference) => { + if ( + childReference.displayName && + childReference.pipelineTaskName === pipelineTask.name + ) { + acc[childReference.name] = childReference.displayName; + } + return acc; + }, {}); realTaskRuns.forEach(taskRun => { - taskRunsToDisplay.push(addDashboardLabels({ pipelineTask, taskRun })); + taskRunsToDisplay.push( + addDashboardLabels({ + displayName: displayNames[taskRun.metadata.name], + pipelineTask, + taskRun + }) + ); }); if (!realTaskRuns.length) {