Skip to content

Commit

Permalink
fix(pipelines): Handle invalid response on acs image check table grac…
Browse files Browse the repository at this point in the history
…efully (#22)
  • Loading branch information
karthikjeeyar authored Mar 20, 2024
1 parent 0dc12e3 commit 96cbcd1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-balloons-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aonic-ui/pipelines": patch
---

Handle the invalid input for acs table gracefully
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DeploymentCheckSummary: React.FC = () => {
);

const breakingChangesSummary = React.useMemo(
() => getBreakingChangeCount(acsDeploymentCheckResults?.results[0]?.violatedPolicies),
() => getBreakingChangeCount(acsDeploymentCheckResults?.results?.[0]?.violatedPolicies),
[acsDeploymentCheckResults],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ImageCheckSummary: React.FC = () => {
[acsImageCheckResults],
);
const breakingChangesSummary = React.useMemo(
() => getBreakingChangeCount(acsImageCheckResults?.results[0]?.violatedPolicies),
() => getBreakingChangeCount(acsImageCheckResults?.results?.[0]?.violatedPolicies),
[acsImageCheckResults],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ describe('ImageCheckTable', () => {
screen.getByTestId('image-check-table');
});
});


test('should render the ImageCheckTable even if the results are not available', async () => {
render(
<ACSContextProvider
{...extraProps}
acsImageCheckResults={{ summary: acsImageCheckResults.summary } as ACSCheckResults}
>
<ImageCheckTable />
</ACSContextProvider>,
);

await waitFor(() => {
screen.getByTestId('image-check-table');
});
});
});
12 changes: 6 additions & 6 deletions packages/pipelines/src/components/Output/utils/summary-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ export const getBreakingChangeStatus = (
return (
<>
<ExclamationTriangleIcon title={status} color={redColor.value} />{' '}
<b>{cveSummary?.[status]}</b> violations breaks build
<b>{cveSummary?.[status] ?? 0}</b> violations breaks build
</>
);
case ACS_BREAKING_CHANGES.NotBreaking:
return (
<>
<ExclamationTriangleIcon title={status} color={yellowColor.value} />{' '}
<b>{cveSummary?.[status]}</b> violations not breaking builds
<b>{cveSummary?.[status] ?? 0}</b> violations not breaking builds
</>
);

Expand Down Expand Up @@ -215,8 +215,8 @@ export const SummaryTextAndCount: React.FC<{
);

export const getCheckSeveritySummary = (data: ACSCheckResults) => ({
[ACS_IMAGE_CHECK_SEVERITY.Critical]: data.results?.[0]?.summary?.CRITICAL,
[ACS_IMAGE_CHECK_SEVERITY.High]: data.results?.[0]?.summary?.HIGH,
[ACS_IMAGE_CHECK_SEVERITY.Medium]: data.results?.[0]?.summary?.MEDIUM,
[ACS_IMAGE_CHECK_SEVERITY.Low]: data.results?.[0]?.summary?.LOW,
[ACS_IMAGE_CHECK_SEVERITY.Critical]: data.results?.[0]?.summary?.CRITICAL ?? 0,
[ACS_IMAGE_CHECK_SEVERITY.High]: data.results?.[0]?.summary?.HIGH ?? 0,
[ACS_IMAGE_CHECK_SEVERITY.Medium]: data.results?.[0]?.summary?.MEDIUM ?? 0,
[ACS_IMAGE_CHECK_SEVERITY.Low]: data.results?.[0]?.summary?.LOW ?? 0,
});

0 comments on commit 96cbcd1

Please sign in to comment.