Skip to content

Commit

Permalink
Add support for displayName from childReferences
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlanGreene authored and tekton-robot committed Mar 19, 2024
1 parent 16013dd commit a7dc50e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
29 changes: 23 additions & 6 deletions packages/utils/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
};
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
47 changes: 46 additions & 1 deletion packages/utils/src/utils/index.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -844,6 +844,51 @@ describe('getTaskRunsWithPlaceholders', () => {
const runs = getTaskRunsWithPlaceholders({ pipelineRun, taskRuns });
expect(runs).toEqual([taskRun, finallyTaskRun]);
});

it('handles displayName in childReferences', () => {
const displayName = 'aDisplayName';
const pipelineTaskName = 'aPipelineTaskName';
const taskRunName = 'aTaskRunName';

const pipelineRun = {
spec: {
pipelineRef: {
name: 'dummy-pipeline'
}
},
status: {
childReferences: [
{
displayName,
name: taskRunName,
pipelineTaskName
}
],
pipelineSpec: {
tasks: [
{
name: pipelineTaskName
}
]
}
}
};
const taskRun = {
metadata: {
labels: {
[labels.PIPELINE_TASK]: pipelineTaskName
},
name: taskRunName
}
};
const runs = getTaskRunsWithPlaceholders({
pipelineRun,
taskRuns: [taskRun]
});
expect(runs[0].metadata.labels[labels.DASHBOARD_DISPLAY_NAME]).toEqual(
displayName
);
});
});

describe('taskRunHasWarning', () => {
Expand Down

0 comments on commit a7dc50e

Please sign in to comment.