Skip to content

Commit

Permalink
handle inline taskSpec in pipeline detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik committed Sep 8, 2020
1 parent e7565ea commit c9f7470
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Expand Up @@ -236,6 +236,29 @@ export const mockPipelinesJSON: K8sResourceKind[] = [
],
},
},
{
apiVersion: 'tekton.dev/v1beta1',
kind: 'Pipeline',
metadata: {
name: 'devconsole',
},
spec: {
tasks: [
{
name: 'use-secret',
taskSpec: {
steps: [
{
name: 'greet',
image: 'registry.access.redhat.com/ubi8/ubi',
script: 'echo "Hello world!"\n',
},
],
},
},
],
},
},
];

const specificPipelineData = pipelineTestData[PipelineExampleNames.COMPLEX_PIPELINE];
Expand Down
Expand Up @@ -15,6 +15,7 @@ import {
pipelineRunDuration,
getSecretAnnotations,
calculateRelativeTime,
hasInlineTaskSpec,
} from '../pipeline-utils';
import {
constructPipelineData,
Expand Down Expand Up @@ -155,4 +156,14 @@ describe('pipeline-utils ', () => {
const relativeTime = calculateRelativeTime('2020-05-22T10:57:53Z', '2020-05-22T12:57:57Z');
expect(relativeTime).toBe('about 2 hours');
});

it('expect pipeline with inline task spec to return true', () => {
const hasSpec = hasInlineTaskSpec(mockPipelinesJSON[2]);
expect(hasSpec).toBe(true);
});

it('expect pipeline without inline task spec to return false', () => {
const hasSpec = hasInlineTaskSpec(mockPipelinesJSON[0]);
expect(hasSpec).toBe(false);
});
});
13 changes: 11 additions & 2 deletions frontend/packages/dev-console/src/utils/pipeline-utils.ts
Expand Up @@ -181,7 +181,16 @@ const appendPipelineRunStatus = (pipeline, pipelineRun) => {
return mTask;
});
};

export const hasInlineTaskSpec = (pipeline: K8sResourceKind) => {
const tasks = pipeline?.spec.tasks ?? [];
let hasInlineSpec = false;
tasks.forEach((task) => {
if (!hasInlineSpec) {
hasInlineSpec = !!(task.taskSpec && !task.taskRef);
}
});
return hasInlineSpec;
};
export const getPipelineTasks = (
pipeline: K8sResourceKind,
pipelineRun: K8sResourceKind = {
Expand All @@ -192,7 +201,7 @@ export const getPipelineTasks = (
): PipelineVisualizationTaskItem[][] => {
// Each unit in 'out' array is termed as stage | out = [stage1 = [task1], stage2 = [task2,task3], stage3 = [task4]]
const out = [];
if (!pipeline.spec || !pipeline.spec.tasks) {
if (!pipeline?.spec.tasks || hasInlineTaskSpec(pipeline)) {
return out;
}
const taskList = appendPipelineRunStatus(pipeline, pipelineRun);
Expand Down

0 comments on commit c9f7470

Please sign in to comment.