@leaflink/oast
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "@leaflink/oast", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -60,4 +60,5 @@ "main": "index.js", | ||
"module-alias": "^2.2.2", | ||
"octokit": "^2.0.9", | ||
"yup": "^0.32.11" | ||
} | ||
} |
@@ -6,2 +6,3 @@ const { loadYamlToJsonWithRequest, writeObjectAsYamlToPath } = require('@src/libs/utils/file-io'); | ||
const { performTransformations } = require('@src/transformer/transformer'); | ||
const { fetchGlobalTransforms } = require('@src/libs/utils/global-transform'); | ||
// load env | ||
@@ -11,5 +12,6 @@ require('dotenv').config(); | ||
module.exports.handleCIIngestion = async (args) => { | ||
const { changedFiles, origin, branch, token, outputPath } = this.checkAndSetIngestionCIArgs(args); | ||
// get processed arg values | ||
const { changedFiles, origin, branch, token, outputPath, configFolderName, specFolderName, applyGlobalTransforms } = this.checkAndSetIngestionCIArgs(args); | ||
const configurationUrls = this.processFilesChanged(changedFiles, origin, branch); | ||
const configurationUrls = this.processFilesChanged(changedFiles, origin, branch, configFolderName); | ||
// TODO: implement flow for handling multiple configs | ||
@@ -21,8 +23,17 @@ // processFilesChanged returns an array to support future multiple configs, for now we just pop() | ||
// Get the spec github raw Url using source from the config | ||
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, args.b || args.branch); | ||
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, args.b || args.branch, specFolderName); | ||
// load the spec yaml into JSON | ||
const specObject = await loadYamlToJsonWithRequest(url, token); | ||
const transformedSpec = await performTransformations(configurationObject, specObject); | ||
let transformedSpec = await performTransformations(configurationObject, specObject); | ||
// fetch and apply the global transforms | ||
if (applyGlobalTransforms) { | ||
outputLog.info('Fetching and applying global-transformation files...'); | ||
// fetch the global config files | ||
const globalTransformConfigCollection = await fetchGlobalTransforms('/configurations', token); | ||
// apply them to the spec | ||
transformedSpec = await performTransformations(globalTransformConfigCollection, transformedSpec); | ||
} | ||
// write the output to outputs/ using the filename | ||
await writeObjectAsYamlToPath(transformedSpec, (outputPath + fileName)); | ||
@@ -60,3 +71,11 @@ }; | ||
}; | ||
let applyGlobalTransforms = false; | ||
if (args.g || args.global) { | ||
applyGlobalTransforms = true; | ||
} | ||
// optional spec and config folder override | ||
const specFolderName = args.sf || args.specFolder || 'specfiles'; | ||
const configFolderName = args.cf || args.configFolder || 'configurations'; | ||
const changedFiles = args.f || args.files; | ||
@@ -70,3 +89,3 @@ const origin = args.or || args.origin; | ||
return { changedFiles, origin, branch, token, outputPath }; | ||
return { changedFiles, origin, branch, token, outputPath, specFolderName, configFolderName, applyGlobalTransforms }; | ||
}; | ||
@@ -79,5 +98,6 @@ | ||
* @param {string} branch current branch or tag | ||
* @param {string} configFolderName override the default configFolderName | ||
* @returns Array of github raw URLs | ||
*/ | ||
module.exports.processFilesChanged = (changedFiles, origin, branch = 'main') => { | ||
module.exports.processFilesChanged = (changedFiles, origin, branch = 'main', configFolderName) => { | ||
const changedFilesArr = changedFiles.split(','); | ||
@@ -88,3 +108,3 @@ const configurationURLs = []; | ||
if (filePath.includes('.specfile.')) { | ||
const { path } = buildConfigPathFromSpecPath(filePath); | ||
const { path } = buildConfigPathFromSpecPath(filePath, configFolderName); | ||
filePath = path; | ||
@@ -91,0 +111,0 @@ } |
@@ -14,3 +14,3 @@ const githubRawUrl = 'https://raw.githubusercontent.com'; | ||
const specPathArray = specPath.split('/'); | ||
// change preceding folder to configuration folder | ||
// change preceding folder to the folderName | ||
specPathArray[specPathArray.length - 2] = folderName; | ||
@@ -31,4 +31,4 @@ // change extension to configuration type | ||
*/ | ||
module.exports.buildConfigPathFromSpecPath = (specPath) => { | ||
return replaceFolderAndExtensionOnPath(specPath, 'configurations', 'config', 'specfile'); | ||
module.exports.buildConfigPathFromSpecPath = (specPath, configFolderName) => { | ||
return replaceFolderAndExtensionOnPath(specPath, configFolderName, 'config', 'specfile'); | ||
}; | ||
@@ -41,4 +41,4 @@ | ||
*/ | ||
module.exports.buildSpecPathFromConfigPath = (specPath) => { | ||
return replaceFolderAndExtensionOnPath(specPath, 'specfiles', 'specfile', 'config'); | ||
module.exports.buildSpecPathFromConfigPath = (specPath, specFolderName) => { | ||
return replaceFolderAndExtensionOnPath(specPath, specFolderName, 'specfile', 'config'); | ||
}; | ||
@@ -51,9 +51,11 @@ | ||
* @param {string} branch branch or tag of origin request from github | ||
* @param {string} specFolderName name of the spec folder | ||
* @returns object containing the github url, and fileName used for output | ||
*/ | ||
module.exports.buildSpecUrlFromConfig = (config, configURL, branch) => { | ||
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 | ||
const [rootRawURL, configPath] = configURL.split(branch); | ||
// build spec path from config path conversion | ||
let { path, fileName } = this.buildSpecPathFromConfigPath(configPath); | ||
let { path, fileName } = this.buildSpecPathFromConfigPath(configPath, specFolderName); | ||
// remove extension from filename, this will be the output name | ||
@@ -60,0 +62,0 @@ fileName = fileName.replace('.config', ''); |
@@ -5,5 +5,7 @@ | ||
const transformer = require('@src/transformer/transformer'); | ||
const fetchTransforms = require('@src/libs/utils/global-transform'); | ||
jest.mock('../../libs/utils/file-io'); | ||
jest.mock('../../transformer/transformer'); | ||
jest.mock('../../libs/utils/global-transform'); | ||
describe('Ingest-CI tests', () => { | ||
@@ -13,3 +15,2 @@ const processFilesSpy = jest.spyOn(ingestCI, 'processFilesChanged'); | ||
const writeFileSpy = jest.spyOn(fileIo, 'writeObjectAsYamlToPath'); | ||
test('Changed files results in github raw urls', () => { | ||
@@ -19,3 +20,3 @@ const changedFiles = 'oas/specfiles/spec.specfile.yaml,/configuration/test.configuration.yaml'; | ||
const branch = 'main'; | ||
expect(ingestCI.processFilesChanged(changedFiles, origin, branch)).toStrictEqual(['https://raw.githubusercontent.com/leaflink/main/oas/configurations/spec.config.yaml', 'https://raw.githubusercontent.com/leaflink/main//configuration/test.configuration.yaml']); | ||
expect(ingestCI.processFilesChanged(changedFiles, origin, branch, 'configurations')).toStrictEqual(['https://raw.githubusercontent.com/leaflink/main/oas/configurations/spec.config.yaml', 'https://raw.githubusercontent.com/leaflink/main//configuration/test.configuration.yaml']); | ||
}); | ||
@@ -44,3 +45,6 @@ | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
await ingestCI.handleCIIngestion({ _: ['ingest-ci'], b: 'main', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token' }); | ||
expect(transformer.performTransformations).toHaveBeenCalled(); | ||
expect(processFilesSpy).toHaveBeenCalled(); | ||
@@ -50,2 +54,15 @@ expect(checkArgSpy).toHaveBeenCalled(); | ||
}); | ||
test('HandleCIIngestion processes correctly with global flag', async () => { | ||
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { branch: 'main' } } } }); | ||
transformer.performTransformations.mockResolvedValueOnce({}); | ||
fetchTransforms.fetchGlobalTransforms.mockResolvedValueOnce([{}]); | ||
await ingestCI.handleCIIngestion({ _: ['ingest-ci'], b: 'main', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token', g: true }); | ||
expect(transformer.performTransformations).toHaveBeenCalledTimes(3); | ||
expect(fetchTransforms.fetchGlobalTransforms).toHaveBeenCalled(); | ||
expect(processFilesSpy).toHaveBeenCalled(); | ||
expect(checkArgSpy).toHaveBeenCalled(); | ||
expect(writeFileSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
@@ -9,7 +9,7 @@ const { buildGithubRawPath, buildConfigPathFromSpecPath, buildSpecPathFromConfigPath, buildSpecUrlFromConfig } = require('@src/libs/utils/github-paths'); | ||
test('Converts spec to config path', () => { | ||
expect(buildConfigPathFromSpecPath('/specfiles/spec.specfile.yaml')).toStrictEqual({ fileName: 'spec.specfile.yaml', path: '/configurations/spec.config.yaml' }); | ||
expect(buildConfigPathFromSpecPath('/specfiles/spec.specfile.yaml', 'configurations')).toStrictEqual({ fileName: 'spec.specfile.yaml', path: '/configurations/spec.config.yaml' }); | ||
}); | ||
test('Converts config to spec path', () => { | ||
expect(buildSpecPathFromConfigPath('/configurations/spec.config.yaml')).toStrictEqual({ fileName: 'spec.config.yaml', path: '/specfiles/spec.specfile.yaml' }); | ||
expect(buildSpecPathFromConfigPath('/configurations/spec.config.yaml', 'specfiles')).toStrictEqual({ fileName: 'spec.config.yaml', path: '/specfiles/spec.specfile.yaml' }); | ||
}); | ||
@@ -28,4 +28,4 @@ | ||
const configURL = 'https://raw.githubusercontent.com/leaflink/main/configurations/spec.config.yaml'; | ||
expect(buildSpecUrlFromConfig(config, configURL, 'main')).toStrictEqual({ fileName: 'spec.yaml', url: 'https://raw.githubusercontent.com/leaflink/main/specfiles/spec.specfile.yaml' }); | ||
expect(buildSpecUrlFromConfig(config, configURL, 'main', 'specfiles')).toStrictEqual({ fileName: 'spec.yaml', url: 'https://raw.githubusercontent.com/leaflink/main/specfiles/spec.specfile.yaml' }); | ||
}); | ||
}); |
153066
51
1673
13
+ Addedoctokit@^2.0.9
+ Added@octokit/app@13.1.8(transitive)
+ Added@octokit/auth-app@4.0.13(transitive)
+ Added@octokit/auth-oauth-app@5.0.6(transitive)
+ Added@octokit/auth-oauth-device@4.0.5(transitive)
+ Added@octokit/auth-oauth-user@2.1.2(transitive)
+ Added@octokit/auth-token@3.0.4(transitive)
+ Added@octokit/auth-unauthenticated@3.0.5(transitive)
+ Added@octokit/core@4.2.4(transitive)
+ Added@octokit/endpoint@7.0.6(transitive)
+ Added@octokit/graphql@5.0.6(transitive)
+ Added@octokit/oauth-app@4.2.4(transitive)
+ Added@octokit/oauth-authorization-url@5.0.0(transitive)
+ Added@octokit/oauth-methods@2.0.6(transitive)
+ Added@octokit/openapi-types@18.1.1(transitive)
+ Added@octokit/plugin-paginate-rest@6.1.2(transitive)
+ Added@octokit/plugin-rest-endpoint-methods@7.2.3(transitive)
+ Added@octokit/plugin-retry@4.1.6(transitive)
+ Added@octokit/plugin-throttling@5.2.3(transitive)
+ Added@octokit/request@6.2.8(transitive)
+ Added@octokit/request-error@3.0.3(transitive)
+ Added@octokit/tsconfig@1.0.2(transitive)
+ Added@octokit/types@10.0.09.3.2(transitive)
+ Added@octokit/webhooks@10.9.2(transitive)
+ Added@octokit/webhooks-methods@3.0.3(transitive)
+ Added@octokit/webhooks-types@6.11.0(transitive)
+ Added@types/aws-lambda@8.10.147(transitive)
+ Added@types/btoa-lite@1.0.2(transitive)
+ Added@types/jsonwebtoken@9.0.9(transitive)
+ Added@types/ms@2.1.0(transitive)
+ Added@types/node@22.13.5(transitive)
+ Addedaggregate-error@3.1.0(transitive)
+ Addedbefore-after-hook@2.2.3(transitive)
+ Addedbottleneck@2.19.5(transitive)
+ Addedbtoa-lite@1.0.0(transitive)
+ Addedbuffer-equal-constant-time@1.0.1(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addeddeprecation@2.3.1(transitive)
+ Addedecdsa-sig-formatter@1.0.11(transitive)
+ Addedfromentries@1.3.2(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedis-plain-object@5.0.0(transitive)
+ Addedjsonwebtoken@9.0.2(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addedlru-cache@9.1.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedoctokit@2.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@7.7.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduniversal-github-app-jwt@1.2.0(transitive)
+ Addeduniversal-user-agent@6.0.1(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)