@leaflink/oast
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -1,1 +0,21 @@ | ||
module.exports = { extends: ['@commitlint/config-conventional'] }; | ||
module.exports = { | ||
rules: { | ||
'body-leading-blank': [1, 'always'], | ||
'body-max-line-length': [2, 'always', 100], | ||
'footer-leading-blank': [1, 'always'], | ||
'footer-max-line-length': [2, 'always', 100], | ||
'header-max-length': [2, 'always', 100], | ||
'scope-empty': [0, 'never'], | ||
'scope-case': [2, 'always', 'lower-case'], | ||
'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], | ||
'subject-empty': [2, 'never'], | ||
'subject-full-stop': [2, 'never', '.'], | ||
'type-case': [2, 'always', 'lower-case'], | ||
'type-empty': [2, 'never'], | ||
'type-enum': [ | ||
2, | ||
'always', | ||
['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'] | ||
] | ||
} | ||
}; |
{ | ||
"name": "@leaflink/oast", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"lint:fix": "eslint --cache --fix \"./src/**/*.js\"", | ||
"lint:commit": "commitlint", | ||
"lint:commits": "commitlint", | ||
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls" | ||
@@ -36,4 +36,3 @@ }, | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.1.2", | ||
"@commitlint/config-conventional": "^17.1.0", | ||
"@commitlint/cli": "^17.2.0", | ||
"coveralls": "^3.1.1", | ||
@@ -40,0 +39,0 @@ "eslint": "^8.22.0", |
@@ -21,3 +21,3 @@ const { loadYamlToJsonWithRequest, writeObjectAsYamlToPath } = require('@src/libs/utils/file-io'); | ||
// Get the spec github raw Url using source from the config | ||
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, args.b || args.branch, specFolderName); | ||
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, branch, specFolderName); | ||
@@ -77,6 +77,12 @@ // load the spec yaml into JSON | ||
const configFolderName = args.cf || args.configFolder || 'configurations'; | ||
const changedFiles = args.f || args.files; | ||
const origin = args.or || args.origin; | ||
const branch = args.b || args.branch; | ||
let branch; | ||
// override branch name with pr commit sha if it is passed in. | ||
// if these values are set to something | ||
if (args.pr && args.pr !== -1) { | ||
branch = args.pr; | ||
} else { | ||
branch = args.b || args.branch; | ||
} | ||
const token = args.t || args.token || process.env.GITHUB_TOKEN; | ||
@@ -83,0 +89,0 @@ // CI command does not allow output path to be specified |
const outputLog = require('@src/output-log'); | ||
const { AxiosError } = require('axios'); | ||
const { GlobalErrorHandler } = require('global-error-handler'); | ||
@@ -21,2 +22,3 @@ const { InvalidConfigurationType, InvalidConfigurationFile, TransformFunctionError, IOCliError, InvalidCommandError, MissingArgumentError } = require('./frosting-ingest-errors'); | ||
this.globalErrorHandler.register({ key: Error, handler: this.uncaughtExceptionHandler }); | ||
this.globalErrorHandler.register({ key: AxiosError, handler: this.dumpErrorStackToLog }); | ||
} | ||
@@ -23,0 +25,0 @@ |
@@ -71,2 +71,3 @@ | ||
} | ||
/** | ||
@@ -73,0 +74,0 @@ * Command is missing required arguments error. |
@@ -36,3 +36,4 @@ const yaml = require('js-yaml'); | ||
} catch (error) { | ||
throw new Error(error); | ||
const axiosError = error.toJSON(); | ||
throw new Error(`${axiosError.message}: ${axiosError.config.method} on ${axiosError.config.url}`); | ||
} | ||
@@ -39,0 +40,0 @@ }; |
@@ -55,3 +55,2 @@ const outputLog = require('@src/output-log'); | ||
module.exports.buildSpecUrlFromConfig = (config, configURL, branch, specFolderName) => { | ||
console.log(specFolderName); | ||
// split off branch, and take last half of url, this is the path for config | ||
@@ -64,18 +63,17 @@ const [rootRawURL, configPath] = configURL.split(branch); | ||
// check the git-source | ||
const gitSource = config.source.location.git['git-source']; | ||
const gitSourceValue = config.source.location.git['source-value']; | ||
// get the git target has type, and value | ||
const gitSourceTarget = config.source.location.git.target; | ||
// change the fetch URL based on how we need to use the source value.. | ||
switch (gitSource.toLowerCase()) { | ||
switch (gitSourceTarget.type.toLowerCase()) { | ||
case 'branch': | ||
case 'tag': | ||
outputLog.info(`pulling ${path} from ${gitSource} :: ${gitSourceValue}`); | ||
return { url: `${rootRawURL}${gitSourceValue}${path}`, fileName }; | ||
outputLog.info(`pulling ${path} from ${gitSourceTarget.type} :: ${gitSourceTarget.value}`); | ||
return { url: `${rootRawURL}${gitSourceTarget.value}${path}`, fileName }; | ||
case 'pr': | ||
outputLog.info(`pulling ${path} from ${gitSource} :: ${branch}`); | ||
outputLog.info(`pulling ${path} from ${gitSourceTarget.type} :: ${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')); | ||
throw new InvalidConfigurationFile({ gitSourceTarget }, new Error('invalid git-source type must be oneof: pr,branch,tag')); | ||
} | ||
}; |
@@ -30,2 +30,20 @@ | ||
test('Branch gets overrided correctly when pr is set', () => { | ||
const { branch, origin, changedFiles, token, outputPath } = ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], b: 'branch', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token', pr: 'pr' }); | ||
expect(changedFiles).toStrictEqual('specfiles/spec.specfile.yaml'); | ||
expect(origin).toStrictEqual('leaflink'); | ||
expect(branch).toStrictEqual('pr'); | ||
expect(token).toStrictEqual('token'); | ||
expect(outputPath).toStrictEqual(process.cwd() + '/outputs/'); | ||
}); | ||
test('Branch gets set correctly when pr is set to -1', () => { | ||
const { branch, origin, changedFiles, token, outputPath } = ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], b: 'branch', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token', pr: -1 }); | ||
expect(changedFiles).toStrictEqual('specfiles/spec.specfile.yaml'); | ||
expect(origin).toStrictEqual('leaflink'); | ||
expect(branch).toStrictEqual('branch'); | ||
expect(token).toStrictEqual('token'); | ||
expect(outputPath).toStrictEqual(process.cwd() + '/outputs/'); | ||
}); | ||
test('Args long name get set and checked properly', () => { | ||
@@ -41,3 +59,3 @@ const { branch, origin, changedFiles, token, outputPath } = ingestCI.checkAndSetIngestionCIArgs({ _: ['ingest-ci'], branch: 'branch', files: 'specfiles/spec.specfile.yaml', origin: 'leaflink', token: 'token' }); | ||
test('HandleCIIngestion processes correctly', async () => { | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { 'git-source': 'branch', 'source-value': 'main' } } } }); | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { target: { type: 'branch', value: 'main' } } } } }); | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
@@ -54,3 +72,3 @@ | ||
test('HandleCIIngestion processes correctly with global flag', async () => { | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { 'git-source': 'branch', 'source-value': 'main' } } } }); | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { target: { type: 'branch', value: 'main' } } } } }); | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
@@ -57,0 +75,0 @@ fetchTransforms.fetchGlobalTransforms.mockResolvedValueOnce([{}]); |
@@ -0,1 +1,2 @@ | ||
const { InvalidConfigurationFile } = require('@src/libs/exceptions/frosting-ingest-errors'); | ||
const { buildGithubRawPath, buildConfigPathFromSpecPath, buildSpecPathFromConfigPath, buildSpecUrlFromConfig } = require('@src/libs/utils/github-paths'); | ||
@@ -21,4 +22,6 @@ | ||
git: { | ||
'git-source': 'branch', | ||
'source-value': 'main' | ||
target: { | ||
type: 'branch', | ||
value: 'main' | ||
} | ||
} | ||
@@ -31,2 +34,34 @@ } | ||
}); | ||
test('Builds spec url from config and pr', () => { | ||
const config = { | ||
source: { | ||
location: { | ||
git: { | ||
target: { | ||
type: 'pr' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const configURL = 'https://raw.githubusercontent.com/leaflink/main/configurations/spec.config.yaml'; | ||
expect(buildSpecUrlFromConfig(config, configURL, 'main', 'specfiles')).toStrictEqual({ fileName: 'spec.yaml', url: 'https://raw.githubusercontent.com/leaflink/main/specfiles/spec.specfile.yaml' }); | ||
}); | ||
test('Throws InvalidConfig error on invalid target type', () => { | ||
const config = { | ||
source: { | ||
location: { | ||
git: { | ||
target: { | ||
type: 'foo' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const configURL = 'https://raw.githubusercontent.com/leaflink/main/configurations/spec.config.yaml'; | ||
expect(() => buildSpecUrlFromConfig(config, configURL, 'main', 'specfiles')).toThrow(InvalidConfigurationFile); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
158335
11
52
1765