Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displayName from childReferences #3345

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading