From 51b89f0337930cd6228a117848f6589626076e4b Mon Sep 17 00:00:00 2001 From: SOOS-JAlvarez Date: Wed, 6 Dec 2023 11:43:26 -0300 Subject: [PATCH 1/3] added verifyScanStatus util --- package-lock.json | 4 ++-- package.json | 2 +- src/utilities.ts | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index afca1d4..a79e0db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@soos-io/api-client", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@soos-io/api-client", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "dependencies": { "axios": "^1.6.2", diff --git a/package.json b/package.json index 18ac90e..bb31465 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@soos-io/api-client", - "version": "0.2.1", + "version": "0.2.2", "description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.", "main": "dist/index.js", "scripts": { diff --git a/src/utilities.ts b/src/utilities.ts index 4421780..04f3c28 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -1,6 +1,7 @@ import axios, { AxiosError } from "axios"; import { soosLogger } from "./logging/SOOSLogger"; import StringUtilities from "./StringUtilities"; +import { ScanStatus } from "./enums"; const isNil = (value: unknown): value is null | undefined => value === null || value === undefined; @@ -113,6 +114,25 @@ const formatBytes = (bytes: number, decimals = 2) => { return `${count} ${unit}`; }; +const verifyScanStatus = (scanStatus: ScanStatus): boolean => { + if (scanStatus === ScanStatus.FailedWithIssues) { + soosLogger.info("Analysis complete - Failures reported"); + soosLogger.info("Failing the build."); + return true; + } else if (scanStatus === ScanStatus.Incomplete) { + soosLogger.info( + "Analysis Incomplete. It may have been cancelled or superseded by another scan.", + ); + soosLogger.info("Failing the build."); + return true; + } else if (scanStatus === ScanStatus.Error) { + soosLogger.info("Analysis Error."); + soosLogger.info("Failing the build."); + return true; + } + return false; +}; + export { isNil, ensureValue, @@ -124,4 +144,5 @@ export { convertStringToBase64, getEnvVariable, formatBytes, + verifyScanStatus, }; From 629ae4ac9f34cea43bc97b712e597b73e584a3a8 Mon Sep 17 00:00:00 2001 From: SOOS-JAlvarez <92373106+SOOS-JAlvarez@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:48:26 -0300 Subject: [PATCH 2/3] Update src/utilities.ts Co-authored-by: SOOS-GSteen --- src/utilities.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utilities.ts b/src/utilities.ts index 04f3c28..80fe2a5 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -115,22 +115,25 @@ const formatBytes = (bytes: number, decimals = 2) => { }; const verifyScanStatus = (scanStatus: ScanStatus): boolean => { + let fail = false; if (scanStatus === ScanStatus.FailedWithIssues) { - soosLogger.info("Analysis complete - Failures reported"); - soosLogger.info("Failing the build."); - return true; + soosLogger.warn("Analysis complete - Failures reported"); + fail = true; } else if (scanStatus === ScanStatus.Incomplete) { - soosLogger.info( + soosLogger.warn( "Analysis Incomplete. It may have been cancelled or superseded by another scan.", ); - soosLogger.info("Failing the build."); - return true; + fail = true; } else if (scanStatus === ScanStatus.Error) { - soosLogger.info("Analysis Error."); - soosLogger.info("Failing the build."); - return true; + soosLogger.warn("Analysis Error."); + fail = true; } - return false; + + if (fail) { + soosLogger.warn("Failing the build."); + } + + return fail; }; export { From 8fce1dfeb757c7c0ab1b4f249f0b6f36b88c54bf Mon Sep 17 00:00:00 2001 From: SOOS-JAlvarez Date: Wed, 6 Dec 2023 12:56:40 -0300 Subject: [PATCH 3/3] code review, tests --- src/utilities.test.ts | 27 ++++++++++++++++++++++++++- src/utilities.ts | 6 +++--- tsconfig.json | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/utilities.test.ts b/src/utilities.test.ts index e3471df..5e5a6d6 100644 --- a/src/utilities.test.ts +++ b/src/utilities.test.ts @@ -1,4 +1,11 @@ -import { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue } from "./utilities"; +import { ScanStatus } from "./enums"; +import { + isNil, + ensureValue, + ensureEnumValue, + ensureNonEmptyValue, + verifyScanStatus, +} from "./utilities"; describe("isNil", () => { test("should return true for null", () => { @@ -73,3 +80,21 @@ describe("ensureEnumValue", () => { expect(ensureEnumValue({ value: "value" }, "VALUE")).toBe("value"); }); }); + +describe("verifyScanStatus", () => { + test("should return false for Finished", () => { + expect(verifyScanStatus(ScanStatus.Finished)).toBe(false); + }); + + test("should return true for an Incomplete status", () => { + expect(verifyScanStatus(ScanStatus.Incomplete)).toBe(true); + }); + + test("should return true for an Error status", () => { + expect(verifyScanStatus(ScanStatus.Error)).toBe(true); + }); + + test("should return true for a FailedWithIssues status", () => { + expect(verifyScanStatus(ScanStatus.FailedWithIssues)).toBe(true); + }); +}); diff --git a/src/utilities.ts b/src/utilities.ts index 80fe2a5..496d5b4 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -128,11 +128,11 @@ const verifyScanStatus = (scanStatus: ScanStatus): boolean => { soosLogger.warn("Analysis Error."); fail = true; } - + if (fail) { - soosLogger.warn("Failing the build."); + soosLogger.warn("Failing the build."); } - + return fail; }; diff --git a/tsconfig.json b/tsconfig.json index 2dbde95..263d93c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ /* Visit https://aka.ms/tsconfig.json to read more about this file */ { "compilerOptions": { - "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "target": "ES2021", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ "outDir": "./dist", /* Redirect output structure to the directory. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */