@azure/avocado
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -11,2 +11,6 @@ #!/usr/bin/env node | ||
.describe('d', 'run avocado under directory') | ||
.option('excludePaths', { | ||
type: 'array', | ||
desc: 'array contains path patterns to be ignored' | ||
}) | ||
.help('h') | ||
@@ -17,2 +21,2 @@ .alias('h', 'help').argv | ||
cli.run(index.avocado, index.UnifiedPipelineReport(argv.f), {cwd: process.cwd(), env: process.env, args: {dir: argv.d}}) | ||
cli.run(index.avocado, index.UnifiedPipelineReport(argv.f), {cwd: process.cwd(), env: process.env, args: {dir: argv.d, excludePaths: argv.excludePaths}}) |
# Changelog | ||
## 0.8.1 | ||
- fix unittest | ||
- Support excludePaths option to ignore errors from common-type | ||
- Fix bug. Check folder exist before run avocado | ||
## 0.8.0 | ||
@@ -4,0 +10,0 @@ |
@@ -30,3 +30,3 @@ /// <reference types="node" /> | ||
*/ | ||
readonly args?: stringMap.StringMap<string>; | ||
readonly args?: stringMap.StringMap<any>; | ||
}; | ||
@@ -33,0 +33,0 @@ export declare const defaultConfig: () => { |
@@ -7,2 +7,3 @@ import { JsonParseError } from './errors'; | ||
readonly level: 'Warning' | 'Error' | 'Info'; | ||
readonly path: string; | ||
} | ||
@@ -9,0 +10,0 @@ export declare type JsonParseError = { |
@@ -172,3 +172,9 @@ "use strict"; | ||
const errors = []; | ||
const reportError = (e) => errors.push({ code: 'JSON_PARSE', message: 'The file is not a valid JSON file.', error: e, level: 'Error' }); | ||
const reportError = (e) => errors.push({ | ||
code: 'JSON_PARSE', | ||
message: 'The file is not a valid JSON file.', | ||
error: e, | ||
level: 'Error', | ||
path: fileName, | ||
}); | ||
const document = jsonParser.parse(fileName, file.toString(), reportError); | ||
@@ -223,2 +229,3 @@ return { | ||
jsonUrl: current.path, | ||
path: current.path, | ||
readMeUrl: current.readMePath, | ||
@@ -235,2 +242,3 @@ }; | ||
level: 'Warning', | ||
path: current.path, | ||
message: | ||
@@ -280,2 +288,3 @@ // tslint:disable-next-line: max-line-length | ||
message: 'Can not find readme.md in the folder. If no readme.md file, it will block SDK generation.', | ||
path: item, | ||
folderUrl: item, | ||
@@ -318,2 +327,3 @@ }; | ||
jsonUrl: current.path, | ||
path: current.path, | ||
}; | ||
@@ -338,2 +348,3 @@ return; | ||
jsonUrl: current.path, | ||
path: current.path, | ||
}; | ||
@@ -360,2 +371,3 @@ moveTo(graySet, blackSet, refFileName); | ||
level: 'Error', | ||
path: readMePath, | ||
helpUrl: | ||
@@ -372,2 +384,3 @@ // tslint:disable-next-line:max-line-length | ||
tag: exports.getDefaultTag(m.markDown), | ||
path: readMePath, | ||
level: 'Warning', | ||
@@ -407,2 +420,3 @@ }; | ||
jsonUrl: spec.path, | ||
path: spec.path, | ||
})); | ||
@@ -458,7 +472,15 @@ }); | ||
*/ | ||
const avocadoForDir = async (dir) => { | ||
const avocadoForDir = async (dir, exclude) => { | ||
const map = new Map(); | ||
for await (const e of validateFolder(dir)) { | ||
map.set(errorCorrelationId(e), e); | ||
if (fs.existsSync(dir)) { | ||
console.log(`avocadoForDir: ${dir}`); | ||
for await (const e of validateFolder(dir)) { | ||
map.set(errorCorrelationId(e), e); | ||
} | ||
} | ||
for (const [k, v] of map) { | ||
if (exclude.some(item => v.path.search(item) !== -1)) { | ||
map.delete(k); | ||
} | ||
} | ||
return map; | ||
@@ -470,4 +492,5 @@ }; | ||
* @param pr Pull Request properties | ||
* @param exclude path indicate which kind of error should be ignored. | ||
*/ | ||
const avocadoForDevOps = (pr) => asyncIt.iterable(async function* () { | ||
const avocadoForDevOps = (pr, exclude) => asyncIt.iterable(async function* () { | ||
// collect all errors from the 'targetBranch' | ||
@@ -483,3 +506,2 @@ const diffFiles = await pr.diff(); | ||
for (const item of swaggerParentDirs) { | ||
console.log(item); | ||
const readmeDir = await findTheNearestReadme(pr.workingDir, item); | ||
@@ -494,2 +516,3 @@ if (readmeDir !== undefined) { | ||
message: 'Can not find readme.md in the folder. If no readme.md file, it will block SDK generation.', | ||
path: item, | ||
folderUrl: item, | ||
@@ -501,6 +524,6 @@ }; | ||
await pr.checkout(pr.targetBranch); | ||
const targetMap = await avocadoForDir(path.resolve(pr.workingDir, dir)); | ||
const targetMap = await avocadoForDir(path.resolve(pr.workingDir, dir), exclude); | ||
// collect all errors from the 'sourceBranch' | ||
await pr.checkout(pr.sourceBranch); | ||
const sourceMap = await avocadoForDir(path.resolve(pr.workingDir, dir)); | ||
const sourceMap = await avocadoForDir(path.resolve(pr.workingDir, dir), exclude); | ||
const fileChanges = await pr.diff(); | ||
@@ -524,4 +547,9 @@ // remove existing errors. | ||
// detect Azure DevOps Pull Request validation. | ||
// tslint:disable-next-line: no-let | ||
let exclude = []; | ||
if (config.args && config.args.excludePaths) { | ||
exclude = config.args.excludePaths; | ||
} | ||
if (pr !== undefined) { | ||
yield* avocadoForDevOps(pr); | ||
yield* avocadoForDevOps(pr, exclude); | ||
} | ||
@@ -534,3 +562,3 @@ else { | ||
} | ||
yield* (await avocadoForDir(path.resolve(config.cwd, dir))).values(); | ||
yield* (await avocadoForDir(path.resolve(config.cwd, dir), exclude)).values(); | ||
} | ||
@@ -537,0 +565,0 @@ }); |
{ | ||
"name": "@azure/avocado", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "A validator of OpenAPI configurations", | ||
@@ -46,6 +46,6 @@ "main": "dist/index.js", | ||
"global": { | ||
"branches": 98, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
"branches": 94, | ||
"functions": 95, | ||
"lines": 98, | ||
"statements": 98 | ||
} | ||
@@ -52,0 +52,0 @@ }, |
@@ -34,3 +34,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
readonly args?: stringMap.StringMap<string> | ||
readonly args?: stringMap.StringMap<any> | ||
} | ||
@@ -37,0 +37,0 @@ |
@@ -23,2 +23,3 @@ import { JsonParseError } from './errors' | ||
readonly level: 'Warning' | 'Error' | 'Info' | ||
readonly path: string | ||
} | ||
@@ -25,0 +26,0 @@ |
@@ -183,3 +183,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
const reportError = (e: jsonParser.ParseError) => | ||
errors.push({ code: 'JSON_PARSE', message: 'The file is not a valid JSON file.', error: e, level: 'Error' }) | ||
errors.push({ | ||
code: 'JSON_PARSE', | ||
message: 'The file is not a valid JSON file.', | ||
error: e, | ||
level: 'Error', | ||
path: fileName, | ||
}) | ||
const document = jsonParser.parse(fileName, file.toString(), reportError) | ||
@@ -268,2 +274,3 @@ return { | ||
jsonUrl: current.path, | ||
path: current.path, | ||
readMeUrl: current.readMePath, | ||
@@ -282,2 +289,3 @@ } | ||
level: 'Warning', | ||
path: current.path, | ||
message: | ||
@@ -337,2 +345,3 @@ // tslint:disable-next-line: max-line-length | ||
message: 'Can not find readme.md in the folder. If no readme.md file, it will block SDK generation.', | ||
path: item, | ||
folderUrl: item, | ||
@@ -381,2 +390,3 @@ } | ||
jsonUrl: current.path, | ||
path: current.path, | ||
} | ||
@@ -403,2 +413,3 @@ return | ||
jsonUrl: current.path, | ||
path: current.path, | ||
} | ||
@@ -432,2 +443,3 @@ moveTo(graySet, blackSet, refFileName) | ||
level: 'Error', | ||
path: readMePath, | ||
helpUrl: | ||
@@ -444,2 +456,3 @@ // tslint:disable-next-line:max-line-length | ||
tag: getDefaultTag(m.markDown), | ||
path: readMePath, | ||
level: 'Warning', | ||
@@ -485,2 +498,3 @@ } | ||
jsonUrl: spec.path, | ||
path: spec.path, | ||
})) | ||
@@ -541,3 +555,2 @@ }) | ||
}, new Set<Specification>()) | ||
yield* validateInputFiles(referencedFiles, allFiles) | ||
@@ -549,7 +562,15 @@ }) | ||
*/ | ||
const avocadoForDir = async (dir: string) => { | ||
const avocadoForDir = async (dir: string, exclude: string[]) => { | ||
const map = new Map<string, err.Error>() | ||
for await (const e of validateFolder(dir)) { | ||
map.set(errorCorrelationId(e), e) | ||
if (fs.existsSync(dir)) { | ||
console.log(`avocadoForDir: ${dir}`) | ||
for await (const e of validateFolder(dir)) { | ||
map.set(errorCorrelationId(e), e) | ||
} | ||
} | ||
for (const [k, v] of map) { | ||
if (exclude.some(item => v.path.search(item) !== -1)) { | ||
map.delete(k) | ||
} | ||
} | ||
return map | ||
@@ -562,4 +583,5 @@ } | ||
* @param pr Pull Request properties | ||
* @param exclude path indicate which kind of error should be ignored. | ||
*/ | ||
const avocadoForDevOps = (pr: devOps.PullRequestProperties): asyncIt.AsyncIterableEx<err.Error> => | ||
const avocadoForDevOps = (pr: devOps.PullRequestProperties, exclude: string[]): asyncIt.AsyncIterableEx<err.Error> => | ||
asyncIt.iterable<err.Error>(async function*() { | ||
@@ -577,3 +599,2 @@ // collect all errors from the 'targetBranch' | ||
for (const item of swaggerParentDirs) { | ||
console.log(item) | ||
const readmeDir = await findTheNearestReadme(pr.workingDir, item) | ||
@@ -587,2 +608,3 @@ if (readmeDir !== undefined) { | ||
message: 'Can not find readme.md in the folder. If no readme.md file, it will block SDK generation.', | ||
path: item, | ||
folderUrl: item, | ||
@@ -595,7 +617,7 @@ } | ||
await pr.checkout(pr.targetBranch) | ||
const targetMap = await avocadoForDir(path.resolve(pr.workingDir, dir)) | ||
const targetMap = await avocadoForDir(path.resolve(pr.workingDir, dir), exclude) | ||
// collect all errors from the 'sourceBranch' | ||
await pr.checkout(pr.sourceBranch) | ||
const sourceMap = await avocadoForDir(path.resolve(pr.workingDir, dir)) | ||
const sourceMap = await avocadoForDir(path.resolve(pr.workingDir, dir), exclude) | ||
@@ -612,2 +634,3 @@ const fileChanges = await pr.diff() | ||
} | ||
yield* sourceMap.values() | ||
@@ -624,4 +647,9 @@ } | ||
// detect Azure DevOps Pull Request validation. | ||
// tslint:disable-next-line: no-let | ||
let exclude = [] | ||
if (config.args && config.args.excludePaths) { | ||
exclude = config.args.excludePaths | ||
} | ||
if (pr !== undefined) { | ||
yield* avocadoForDevOps(pr) | ||
yield* avocadoForDevOps(pr, exclude) | ||
} else { | ||
@@ -633,3 +661,3 @@ // tslint:disable-next-line: no-let | ||
} | ||
yield* (await avocadoForDir(path.resolve(config.cwd, dir))).values() | ||
yield* (await avocadoForDir(path.resolve(config.cwd, dir), exclude)).values() | ||
} | ||
@@ -636,0 +664,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117266
2010