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

Remove unused code #3166

Merged
merged 1 commit into from
Oct 17, 2023
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
57 changes: 12 additions & 45 deletions src/api/customRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,12 @@ function getCustomRunsAPI({ filters, isWebSocket, name, namespace }) {
);
}

export function getCustomRunPayload({
customRunName = `run-${Date.now()}`,
labels,
namespace,
params,
serviceAccount,
timeout
}) {
export function getCustomRunPayload({ namespace }) {
const payload = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'CustomRun',
metadata: {
name: customRunName,
name: `run-${Date.now()}`,
namespace
},
spec: {
Expand All @@ -63,21 +56,6 @@ export function getCustomRunPayload({
}
}
};
if (labels) {
payload.metadata.labels = labels;
}
if (params) {
payload.spec.params = Object.keys(params).map(name => ({
name,
value: params[name]
}));
}
if (serviceAccount) {
payload.spec.serviceAccountName = serviceAccount;
}
if (timeout) {
payload.spec.timeout = timeout;
}

return payload;
}
Expand Down Expand Up @@ -130,27 +108,6 @@ export function cancelCustomRun({ name, namespace }) {
return patch(uri, payload);
}

export function rerunCustomRun(run) {
const { annotations, labels, name, namespace } = run.metadata;

const payload = deepClone(run);
payload.metadata = {
annotations,
generateName: getGenerateNamePrefixForRerun(name),
labels: {
...labels,
'dashboard.tekton.dev/rerunOf': name
},
namespace
};

delete payload.status;
delete payload.spec?.status;

const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
}

export function createCustomRunRaw({ namespace, payload }) {
const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
Expand Down Expand Up @@ -194,3 +151,13 @@ export function generateNewCustomRunPayload({ customRun, rerun }) {
delete payload.spec?.status;
return { namespace, payload };
}

export function rerunCustomRun(customRun) {
const { namespace, payload } = generateNewCustomRunPayload({
customRun,
rerun: true
});

const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
}
28 changes: 2 additions & 26 deletions src/containers/CreateCustomRun/CreateCustomRun.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ limitations under the License.
*/
/* istanbul ignore file */

import React, { Suspense, useState } from 'react';
import React, { Suspense } from 'react';
import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
import yaml from 'js-yaml';
import { ALL_NAMESPACES, urls, useTitleSync } from '@tektoncd/dashboard-utils';
Expand All @@ -28,15 +28,6 @@ import {

const YAMLEditor = React.lazy(() => import('../YAMLEditor'));

const initialState = {
creating: false,
kind: 'CustomRun',
labels: [],
params: {},
validationError: false,
validCustomRunName: true
};

function CreateCustomRun() {
const intl = useIntl();
const location = useLocation();
Expand All @@ -56,13 +47,6 @@ function CreateCustomRun() {
);
}

const [{ kind, labels, namespace, params }] = useState({
...initialState,
customRef: '',
kind: 'Custom',
namespace: getNamespace()
});

useTitleSync({
page: intl.formatMessage({
id: 'dashboard.createCustomRun.title',
Expand Down Expand Up @@ -127,15 +111,7 @@ function CreateCustomRun() {
);
}

const customRun = getCustomRunPayload({
kind,
labels: labels.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {}),
namespace,
params
});
const customRun = getCustomRunPayload({ namespace: getNamespace() });

return (
<Suspense fallback={<Loading />}>
Expand Down
4 changes: 1 addition & 3 deletions src/containers/CreateCustomRun/CreateCustomRun.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ kind: CustomRun
metadata:
name: run-1111111111
namespace: test-namespace
labels: {}
spec:
customRef:
apiVersion: ''
kind: ''
params: []`;
kind: ''`;

const expectedCustomRunOneLine = expectedCustomRun.replace(/\r?\n|\r/g, '');

Expand Down