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 updated resourceTemplates field in future Triggers release #3310

Merged
merged 1 commit into from
Feb 16, 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
34 changes: 32 additions & 2 deletions packages/components/src/components/Trigger/Trigger.test.jsx
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 @@ -284,7 +284,7 @@ describe('Trigger', () => {
expect(queryByText(/TriggerBindings/i)).toBeFalsy();
});

it('handles embedded template spec', () => {
it('handles embedded template spec - resourcetemplates', () => {
const props = {
namespace: 'tekton-pipelines',
trigger: {
Expand Down Expand Up @@ -314,6 +314,36 @@ describe('Trigger', () => {
expect(getByText(/hello there/)).toBeTruthy();
});

it('handles embedded template spec - resourceTemplates', () => {
const props = {
namespace: 'tekton-pipelines',
trigger: {
...fakeTrigger,
template: {
spec: {
params: [{ name: 'foo' }],
resourceTemplates: [
{
apiVersion: 'tekton.dev/v1beta1',
kind: 'TaskRun',
metadata: {
generateName: 'pr-run-'
},
spec: {
taskSpec: {
steps: [{ image: 'ubuntu', script: 'echo "hello there"' }]
}
}
}
]
}
}
}
};
const { getByText } = renderWithRouter(<Trigger {...props} />);
expect(getByText(/hello there/)).toBeTruthy();
});

it('handles ClusterInterceptor', () => {
const clusterInterceptorName = 'fake_clusterInterceptorName';
const props = {
Expand Down
17 changes: 10 additions & 7 deletions src/containers/TriggerTemplate/TriggerTemplate.jsx
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 @@ -73,7 +73,12 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() {
return null;
}

const { params, resourcetemplates } = triggerTemplate.spec;
const {
params,
resourceTemplates: newResourceTemplates,
resourcetemplates: oldResourceTemplates
} = triggerTemplate.spec;
const resourceTemplates = oldResourceTemplates || newResourceTemplates;

const headersForParameters = [
{
Expand Down Expand Up @@ -130,12 +135,12 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() {
emptyTextAllNamespaces={emptyTextMessage}
emptyTextSelectedNamespace={emptyTextMessage}
/>
{resourcetemplates && (
{resourceTemplates && (
// This is a very customised expandable table so intentionally not the one used elsewhere
// although it should look the same
<div className="tkn--table">
<DataTable
rows={resourcetemplates.map((item, index) => ({
rows={resourceTemplates.map((item, index) => ({
id: `${index}|${
item.metadata.name || item.metadata.generateName
}`,
Expand Down Expand Up @@ -191,9 +196,7 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() {
{row.isExpanded && (
<TableExpandedRow colSpan={headers.length + 1}>
<ViewYAML
resource={
triggerTemplate.spec.resourcetemplates[index]
}
resource={resourceTemplates[index]}
dark
/>
</TableExpandedRow>
Expand Down
4 changes: 2 additions & 2 deletions src/containers/TriggerTemplate/TriggerTemplate.test.jsx
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 @@ -115,7 +115,7 @@ const fakeTriggerTemplateWithLabels = {
},
{ description: 'The Content-Type of the event', name: 'contenttype' }
],
resourcetemplates: [
resourceTemplates: [
resourceTemplate1Details,
{
apiVersion: 'tekton.dev/v1alpha1',
Expand Down
Loading