@leaflink/oast
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "@leaflink/oast", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const { loadYamlToJsonWithRequest, writeObjectAsYamlToPath } = require('@src/libs/utils/file-io'); | ||
const { InvalidArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const { MissingArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const outputLog = require('@src/output-log'); | ||
@@ -46,7 +46,7 @@ const { buildGithubRawPath, buildConfigPathFromSpecPath, buildSpecUrlFromConfig } = require('@src/libs/utils/github-paths'); | ||
if (args.f === undefined && args.files === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'files'); | ||
}; | ||
// required path to config file | ||
if (args.or === undefined && args.origin === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'origin'); | ||
}; | ||
@@ -57,3 +57,3 @@ | ||
if (args.t === undefined && args.token === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'github token'); | ||
} | ||
@@ -63,3 +63,3 @@ } | ||
if (args.b === undefined && args.branch === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'branch'); | ||
} | ||
@@ -66,0 +66,0 @@ |
const { performTransformations } = require('@src/transformer/transformer'); | ||
const outputLog = require('@src/output-log'); | ||
const path = require('path'); | ||
const { InvalidArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const { MissingArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const errorHandler = require('@src/libs/exceptions/error-handler'); | ||
@@ -56,7 +56,7 @@ const { loadYamlToJsonWithPath, writeObjectAsYamlToPath, loadYamlToJsonWithRequest, readAndProcessFilesInDir } = require('@src/libs/utils/file-io'); | ||
if (args.i === undefined && args.input === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'input'); | ||
}; | ||
// required path to config file | ||
if (args.c === undefined && args.config === undefined) { | ||
throw new InvalidArgumentError(args._); | ||
throw new MissingArgumentError(args._, 'config'); | ||
}; | ||
@@ -63,0 +63,0 @@ |
const outputLog = require('@src/output-log'); | ||
const { GlobalErrorHandler } = require('global-error-handler'); | ||
const { InvalidCommandError, InvalidConfigurationType, InvalidConfigurationFile, TransformFunctionError, InvalidArgumentError, IOCliError } = require('./frosting-ingest-errors'); | ||
const { InvalidConfigurationType, InvalidConfigurationFile, TransformFunctionError, IOCliError, InvalidCommandError, MissingArgumentError } = require('./frosting-ingest-errors'); | ||
/** | ||
@@ -18,3 +18,3 @@ * Global Error Handler, catches all uncaught exceptions | ||
this.globalErrorHandler.register({ key: TransformFunctionError, handler: this.dumpErrorStackToLog }); | ||
this.globalErrorHandler.register({ key: InvalidArgumentError, handler: this.dumpErrorStackToLog }); | ||
this.globalErrorHandler.register({ key: MissingArgumentError, handler: this.dumpErrorStackToLog }); | ||
this.globalErrorHandler.register({ key: IOCliError, handler: this.dumpErrorStackToLog }); | ||
@@ -21,0 +21,0 @@ this.globalErrorHandler.register({ key: Error, handler: this.uncaughtExceptionHandler }); |
@@ -23,14 +23,3 @@ | ||
} | ||
/** | ||
* Invalid arguments supplied to cli command | ||
*/ | ||
class InvalidArgumentError extends BaseIngestError { | ||
constructor (command) { | ||
super(`Invalid arguments supplied to: ${command}`); | ||
this.exitCode = 9; | ||
} | ||
} | ||
/** | ||
* Invalid configuration for transform function | ||
@@ -83,3 +72,11 @@ * Usually thrown when invalid schema is found. | ||
} | ||
module.exports = { InvalidCommandError, InvalidConfigurationType, InvalidConfigurationFile, InvalidJsonPathError, TransformFunctionError, InvalidArgumentError, IOCliError }; | ||
/** | ||
* Command is missing required arguments error. | ||
*/ | ||
class MissingArgumentError extends BaseIngestError { | ||
constructor (command, argument) { | ||
super(`Args: ${argument} required for command ${command}`); | ||
this.exitCode = 9; | ||
} | ||
} | ||
module.exports = { InvalidCommandError, InvalidConfigurationType, InvalidConfigurationFile, InvalidJsonPathError, TransformFunctionError, MissingArgumentError, IOCliError }; |
@@ -0,1 +1,4 @@ | ||
const outputLog = require('@src/output-log'); | ||
const { InvalidConfigurationFile } = require('../exceptions/frosting-ingest-errors'); | ||
const githubRawUrl = 'https://raw.githubusercontent.com'; | ||
@@ -59,5 +62,19 @@ /** | ||
fileName = fileName.replace('.config', ''); | ||
const specBranch = config.source.location.git.branch; | ||
const specTag = config.source.location.git.tag; | ||
return { url: `${rootRawURL}${specBranch || specTag}${path}`, fileName }; | ||
// check the git-source | ||
const gitSource = config.source.location.git['git-source']; | ||
const gitSourceValue = config.source.location.git['source-value']; | ||
// change the fetch URL based on how we need to use the source value.. | ||
switch (gitSource.toLowerCase()) { | ||
case 'branch': | ||
case 'tag': | ||
outputLog.info(`pulling ${path} from ${gitSource} :: ${gitSourceValue}`); | ||
return { url: `${rootRawURL}${gitSourceValue}${path}`, fileName }; | ||
case 'pr': | ||
outputLog.info(`pulling ${path} from ${gitSource} :: ${branch}`); | ||
return { url: `${rootRawURL}${branch}${path}`, fileName }; | ||
default: | ||
throw new InvalidConfigurationFile({ gitSource, gitSourceValue }, new Error('invalid git-source type must be oneof: pr,branch,tag')); | ||
} | ||
}; |
@@ -5,3 +5,3 @@ /* eslint-disable no-unused-vars */ | ||
const ingestCI = require('@src/commands/ingest-ci'); | ||
const { InvalidArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const { MissingArgumentError } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const outputLog = require('@src/output-log'); | ||
@@ -57,33 +57,33 @@ | ||
test('Ingestion with no args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'] })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion with no args throws MissingArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'] })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion with no -c arg throws InvalidArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'], i: mockInputPath })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion with no -c arg throws MissingArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'], i: mockInputPath })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion with no -i arg throws InvalidArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'], c: mockConfigPath })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion with no -i arg throws MissingArgumentError', async () => { | ||
await expect(async () => ingest.checkIngestionArgs({ _: ['ingest'], c: mockConfigPath })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
// Ingestion-CI cli args test | ||
test('Ingestion-CI with no args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'] })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion-CI with no args throws MissingArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'] })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion-CI with no -t args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], or: 'origin', f: 'files', b: 'branch' })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion-CI with no -t args throws MissingArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], or: 'origin', f: 'files', b: 'branch' })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion-CI with no -f args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], or: 'origin', t: 'token', b: 'branch' })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion-CI with no -f args throws MissingArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], or: 'origin', t: 'token', b: 'branch' })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion-CI with no -or args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], files: 'files', t: 'token', b: 'branch' })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion-CI with no -or args throws MissingArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], files: 'files', t: 'token', b: 'branch' })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
test('Ingestion-CI with no -b args throws InvalidArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], f: 'files', token: 'token', or: 'origin' })).rejects.toBeInstanceOf(InvalidArgumentError); | ||
test('Ingestion-CI with no -b args throws MissingArgumentError', async () => { | ||
await expect(async () => ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], f: 'files', token: 'token', or: 'origin' })).rejects.toBeInstanceOf(MissingArgumentError); | ||
}); | ||
@@ -90,0 +90,0 @@ |
@@ -40,3 +40,3 @@ | ||
test('HandleCIIngestion processes correctly', async () => { | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { branch: 'main' } } } }); | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { 'git-source': 'branch', 'source-value': 'main' } } } }); | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
@@ -53,3 +53,3 @@ | ||
test('HandleCIIngestion processes correctly with global flag', async () => { | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { branch: 'main' } } } }); | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { 'git-source': 'branch', 'source-value': 'main' } } } }); | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
@@ -56,0 +56,0 @@ fetchTransforms.fetchGlobalTransforms.mockResolvedValueOnce([{}]); |
@@ -21,3 +21,4 @@ const { buildGithubRawPath, buildConfigPathFromSpecPath, buildSpecPathFromConfigPath, buildSpecUrlFromConfig } = require('@src/libs/utils/github-paths'); | ||
git: { | ||
branch: 'main' | ||
'git-source': 'branch', | ||
'source-value': 'main' | ||
} | ||
@@ -24,0 +25,0 @@ } |
Sorry, the diff of this file is not supported yet
154006
1688