@soos-io/api-client
Advanced tools
Comparing version 0.2.9 to 0.2.10-pre.1
@@ -9,3 +9,4 @@ import { ArgumentParser } from "argparse"; | ||
addBaseScanArguments(integrationName: IntegrationName, integrationType: IntegrationType, scriptVersion: string): void; | ||
parseArguments(): any; | ||
} | ||
export default AnalysisArgumentParser; |
@@ -123,3 +123,6 @@ "use strict"; | ||
} | ||
parseArguments() { | ||
return this.argumentParser.parse_args(); | ||
} | ||
} | ||
exports.default = AnalysisArgumentParser; |
@@ -5,2 +5,3 @@ import SOOSAnalysisApiClient, { ICreateScanRequestContributingDeveloperAudit, ICreateScanResponse } from "../api/SOOSAnalysisApiClient"; | ||
import { IntegrationName, IntegrationType, OutputFormat, ScanStatus, ScanType } from "../enums"; | ||
import FormData from "form-data"; | ||
interface IGenerateFormattedOutputParams { | ||
@@ -57,2 +58,6 @@ clientId: string; | ||
} | ||
interface IAnalysisFile { | ||
name: string; | ||
path: string; | ||
} | ||
declare const GeneratedScanTypes: ScanType[]; | ||
@@ -71,4 +76,9 @@ declare class AnalysisService { | ||
updateScanStatus({ clientId, projectHash, branchHash, scanType, analysisId, status, message, scanStatusUrl, }: IUpdateScanStatusParams): Promise<void>; | ||
findAnalysisFiles(path: string, pattern: string, filesToExclude: string[] | null | undefined, directoriesToExclude: string[] | null | undefined, scanType: ScanType): Promise<{ | ||
filePaths: string[]; | ||
hasMoreThanMaximumManifests: boolean; | ||
}>; | ||
getAnalysisFilesAsFormData(analysisFiles: IAnalysisFile[], workingDirectory: string): Promise<FormData>; | ||
} | ||
export { GeneratedScanTypes }; | ||
export default AnalysisService; |
@@ -12,5 +12,7 @@ "use strict"; | ||
const logging_1 = require("../logging"); | ||
const glob_1 = tslib_1.__importDefault(require("glob")); | ||
const utilities_1 = require("../utilities"); | ||
const FileSystem = tslib_1.__importStar(require("fs")); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const form_data_1 = tslib_1.__importDefault(require("form-data")); | ||
const integrationNameToEnvVariable = { | ||
@@ -200,3 +202,37 @@ [enums_1.IntegrationName.AzureDevOps]: "Build.RequestedFor", | ||
} | ||
async findAnalysisFiles(path, pattern, filesToExclude = null, directoriesToExclude = null, scanType) { | ||
process.chdir(path); | ||
logging_1.soosLogger.info(`Searching for ${scanType} files from ${path}...`); | ||
const finalPattern = `${path}/${pattern}`; | ||
const files = glob_1.default.sync(finalPattern, { | ||
ignore: [...(filesToExclude || []), ...(directoriesToExclude || [])], | ||
nocase: true, | ||
}); | ||
const matchingFiles = files.map((x) => Path.resolve(x)); | ||
logging_1.soosLogger.info(`${matchingFiles.length} files found matching pattern '${pattern}'.`); | ||
const hasMoreThanMaximumManifests = matchingFiles.length > constants_1.SOOS_CONSTANTS.FileUploads.MaxManifests; | ||
const filesToUpload = matchingFiles.slice(0, constants_1.SOOS_CONSTANTS.FileUploads.MaxManifests); | ||
if (hasMoreThanMaximumManifests) { | ||
const filesToSkip = matchingFiles.slice(constants_1.SOOS_CONSTANTS.FileUploads.MaxManifests); | ||
const filesDetectedString = StringUtilities_1.default.pluralizeTemplate(matchingFiles.length, "file was", "files were"); | ||
const filesSkippedString = StringUtilities_1.default.pluralizeTemplate(filesToSkip.length, "file", "files"); | ||
logging_1.soosLogger.info(`The maximum number of ${scanType} files per scan is ${constants_1.SOOS_CONSTANTS.FileUploads.MaxManifests}. ${filesDetectedString} detected, and ${filesSkippedString} will be not be uploaded. \n`, `The following manifests will not be included in the scan: \n`, filesToSkip.map((file) => ` "${Path.basename(file)}": "${file}"`).join("\n")); | ||
} | ||
return { filePaths: filesToUpload, hasMoreThanMaximumManifests }; | ||
} | ||
async getAnalysisFilesAsFormData(analysisFiles, workingDirectory) { | ||
const formData = analysisFiles.reduce((formDataAcc, analysisFile, index) => { | ||
const fileParts = analysisFile.path.replace(workingDirectory, "").split(Path.sep); | ||
const parentFolder = fileParts.length >= 2 ? fileParts.slice(0, fileParts.length - 1).join(Path.sep) : ""; | ||
const suffix = index > 0 ? index : ""; | ||
const fileReadStream = FileSystem.createReadStream(analysisFile.path, { | ||
encoding: constants_1.SOOS_CONSTANTS.FileUploads.Encoding, | ||
}); | ||
formDataAcc.append(`file${suffix}`, fileReadStream); | ||
formDataAcc.append(`parentFolder${suffix}`, parentFolder); | ||
return formDataAcc; | ||
}, new form_data_1.default()); | ||
return formData; | ||
} | ||
} | ||
exports.default = AnalysisService; |
@@ -0,0 +0,0 @@ module.exports = { |
{ | ||
"name": "@soos-io/api-client", | ||
"version": "0.2.9", | ||
"version": "0.2.10-pre.1", | ||
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.", | ||
@@ -48,2 +48,3 @@ "main": "dist/index.js", | ||
"@types/argparse": "^2.0.14", | ||
"@types/glob": "^8.1.0", | ||
"@types/jest": "^29.5.11", | ||
@@ -50,0 +51,0 @@ "@types/node": "^20.10.4", |
@@ -0,0 +0,0 @@ # [About SOOS](https://soos.io/) |
Sorry, the diff of this file is not supported yet
74355
1643
8