Skip to content

Commit

Permalink
update trailer msg for onError continue
Browse files Browse the repository at this point in the history
  • Loading branch information
LyndseyBu authored and tekton-robot committed Nov 4, 2021
1 parent cdfb448 commit f9b410a
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 17 deletions.
21 changes: 15 additions & 6 deletions packages/components/src/components/Log/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,30 @@ export class LogContainer extends Component {
);
};

getTrailerMessage = trailer => {
getTrailerMessage = ({ exitCode, reason }) => {
const { forcePolling, intl } = this.props;

if (trailer && forcePolling) {
if (reason && forcePolling) {
return intl.formatMessage({
id: 'dashboard.logs.pending',
defaultMessage: 'Final logs pending'
});
}

switch (trailer) {
switch (reason) {
case 'Completed':
if (exitCode !== 0) {
return intl.formatMessage(
{
id: 'dashboard.pipelineRun.stepCompleted.withError',
defaultMessage: 'Step completed with exit code {exitCode}'
},
{ exitCode }
);
}
return intl.formatMessage({
id: 'dashboard.pipelineRun.stepCompleted',
defaultMessage: 'Step completed'
defaultMessage: 'Step completed successfully'
});
case 'Error':
return intl.formatMessage({
Expand Down Expand Up @@ -383,8 +392,8 @@ export class LogContainer extends Component {

logTrailer = () => {
const { forcePolling, stepStatus } = this.props;
const { reason } = (stepStatus && stepStatus.terminated) || {};
const trailer = this.getTrailerMessage(reason);
const { exitCode, reason } = (stepStatus && stepStatus.terminated) || {};
const trailer = this.getTrailerMessage({ exitCode, reason });
if (!trailer) {
return null;
}
Expand Down
18 changes: 13 additions & 5 deletions packages/components/src/components/Log/Log.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ export const Loading = () => <Log loading />;

export const Completed = () => (
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() => 'A log message'}
/>
);

export const CompletedNonZero = () => (
<Log
stepStatus={{ terminated: { reason: 'Completed', exitCode: 1 } }}
fetchLogs={() => 'A log message'}
/>
);
CompletedNonZero.storyName = 'Completed: non-zero exit code';

export const Failed = () => (
<Log
stepStatus={{ terminated: { reason: 'Error' } }}
Expand All @@ -60,21 +68,21 @@ export const Failed = () => (

export const ANSICodes = () => (
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() => ansiLog}
/>
);

export const Windowed = () => (
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() => long}
/>
);

export const Performance = () => (
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() => performanceTest}
/>
);
Expand All @@ -86,7 +94,7 @@ export const Toolbar = () => {
return (
<Log
fetchLogs={() => 'A log message'}
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
toolbar={<LogsToolbar name={name} url={url} />}
/>
);
Expand Down
41 changes: 37 additions & 4 deletions packages/components/src/components/Log/Log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ describe('Log', () => {
it('renders trailer', async () => {
const { getByText } = render(
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() => 'testing'}
/>
);
await waitFor(() => getByText(/step completed successfully/i));
});

it('renders warning trailer', async () => {
const { getByText } = render(
<Log
stepStatus={{ terminated: { reason: 'Completed', exitCode: 1 } }}
fetchLogs={() => 'testing'}
/>
);
await waitFor(() => getByText(/step completed/i));
await waitFor(() => getByText(/step completed with exit code 1/i));
});

it('renders error trailer', async () => {
Expand Down Expand Up @@ -256,7 +266,30 @@ describe('Log', () => {
it('renders trailer when streaming logs', async () => {
const { getByText } = render(
<Log
stepStatus={{ terminated: { reason: 'Completed' } }}
stepStatus={{ terminated: { reason: 'Completed', exitCode: 0 } }}
fetchLogs={() =>
Promise.resolve({
getReader() {
return {
read() {
return Promise.resolve({
done: true,
value: new TextEncoder().encode('testing')
});
}
};
}
})
}
/>
);
await waitFor(() => getByText(/Step completed successfully/i));
});

it('renders warning trailer when streaming logs', async () => {
const { getByText } = render(
<Log
stepStatus={{ terminated: { reason: 'Completed', exitCode: 1 } }}
fetchLogs={() =>
Promise.resolve({
getReader() {
Expand All @@ -273,7 +306,7 @@ describe('Log', () => {
}
/>
);
await waitFor(() => getByText(/step completed/i));
await waitFor(() => getByText(/Step completed with exit code 1/i));
});

it('renders error trailer when streaming logs', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function getStepStatusReason(step) {

let status;
let reason;
const exitCode = step?.terminated?.exitCode;
if (step.terminated) {
status = 'terminated';
reason = step.terminated.reason;
Expand All @@ -103,7 +104,7 @@ export function getStepStatusReason(step) {
} else if (step.waiting) {
status = 'waiting';
}
return { reason, status };
return { exitCode, reason, status };
}

export function isPending(reason, status) {
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "PipelineRun nicht gefunden",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "Schritt abgeschlossen",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "Schritt fehlgeschlagen",
"dashboard.pipelineRuns.error": "Fehler beim Laden von PipelineRuns",
"dashboard.pipelines.errorLoading": "",
Expand Down
3 changes: 2 additions & 1 deletion src/nls/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"dashboard.pipelineRun.logFailed": "Unable to fetch log",
"dashboard.pipelineRun.notFound": "PipelineRun not found",
"dashboard.pipelineRun.pipelineTaskName.retry": "{pipelineTaskName} (retry {retryNumber, number})",
"dashboard.pipelineRun.stepCompleted": "Step completed",
"dashboard.pipelineRun.stepCompleted": "Step completed successfully",
"dashboard.pipelineRun.stepCompleted.withError": "Step completed with exit code {exitCode}",
"dashboard.pipelineRun.stepFailed": "Step failed",
"dashboard.pipelineRuns.error": "Error loading PipelineRuns",
"dashboard.pipelines.errorLoading": "Error loading Pipelines",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "No se ha encontrado PipelineRun",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "Paso completado",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "Paso fallido",
"dashboard.pipelineRuns.error": "Error al cargar PipelineRuns",
"dashboard.pipelines.errorLoading": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "PipelineRun introuvable",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "Etape terminée",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "Echec de l'étape",
"dashboard.pipelineRuns.error": "Une erreur s'est produite lors du chargement des ressources PipelineRun",
"dashboard.pipelines.errorLoading": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "Esecuzione pipeline non trovata",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "Passo completato",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "Passo non riuscito",
"dashboard.pipelineRuns.error": "Errore nel caricamento delle esecuzioni pipeline",
"dashboard.pipelines.errorLoading": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "PipelineRunが見つかりません",
"dashboard.pipelineRun.pipelineTaskName.retry": "{pipelineTaskName}(retry{retryNumber,number})",
"dashboard.pipelineRun.stepCompleted": "ステップが完了しました",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "ステップが失敗しました",
"dashboard.pipelineRuns.error": "PipelineRunのロード中にエラーが発生しました",
"dashboard.pipelines.errorLoading": "Pipelineのロード中にエラーが発生しました",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "PipelineRun을 찾을 수 없음",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "단계 완료",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "단계 실패",
"dashboard.pipelineRuns.error": "PipelineRun 로드 중 오류 발생",
"dashboard.pipelines.errorLoading": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "PipelineRun não localizado",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "Etapa concluída",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "Etapa com falha",
"dashboard.pipelineRuns.error": "Erro ao carregar os PipelineRuns",
"dashboard.pipelines.errorLoading": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "未找到 PipelineRun",
"dashboard.pipelineRun.pipelineTaskName.retry": "{pipelineTaskName}(重试 {retryNumber, number})",
"dashboard.pipelineRun.stepCompleted": "步骤已完成",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "步骤失败",
"dashboard.pipelineRuns.error": "加载 PipelineRun 时出错",
"dashboard.pipelines.errorLoading": "加载 Pipelines 时出错",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"dashboard.pipelineRun.notFound": "找不到 PipelineRun",
"dashboard.pipelineRun.pipelineTaskName.retry": "",
"dashboard.pipelineRun.stepCompleted": "步驟已完成",
"dashboard.pipelineRun.stepCompleted.withError": "",
"dashboard.pipelineRun.stepFailed": "步驟失敗",
"dashboard.pipelineRuns.error": "載入 PipelineRuns 時發生錯誤",
"dashboard.pipelines.errorLoading": "",
Expand Down

0 comments on commit f9b410a

Please sign in to comment.