@@ -17090,29 +17090,78 @@ var __importStar = (this && this.__importStar) || function (mod) {
1709017090 __setModuleDefault(result, mod);
1709117091 return result;
1709217092};
17093+ var __importDefault = (this && this.__importDefault) || function (mod) {
17094+ return (mod && mod.__esModule) ? mod : { "default": mod };
17095+ };
1709317096Object.defineProperty(exports, "__esModule", ({ value: true }));
1709417097exports.IgnoredFiles = void 0;
1709517098const fs = __importStar(__nccwpck_require__(5747));
1709617099const yaml = __importStar(__nccwpck_require__(1917));
17097- const minimatch = __importStar (__nccwpck_require__(3973));
17100+ const minimatch_1 = __importDefault (__nccwpck_require__(3973));
1709817101const path = __importStar(__nccwpck_require__(5622));
1709917102const ActionOptions_1 = __nccwpck_require__(3615);
1710017103/**
1710117104 * The ignore files in the analysis_options.yaml
1710217105 */
1710317106class IgnoredFiles {
1710417107 constructor() {
17105- var _a, _b;
1710617108 let patterns;
1710717109 try {
17108- const yamlFile = yaml.load(fs.readFileSync(path.resolve(ActionOptions_1.actionOptions.workingDirectory, 'analysis_options.yaml'), 'utf8'));
17109- patterns = (_b = (_a = yamlFile === null || yamlFile === void 0 ? void 0 : yamlFile.analyzer) === null || _a === void 0 ? void 0 : _a.exclude) !== null && _b !== void 0 ? _b : [];
17110+ const yamlPath = IgnoredFiles.findClosestYamlFile(ActionOptions_1.actionOptions.workingDirectory);
17111+ if (!yamlPath) {
17112+ throw new Error(`Could not find any "analysis_options.yaml" in the parent directories of "${ActionOptions_1.actionOptions.workingDirectory}"`);
17113+ }
17114+ patterns = IgnoredFiles.getIgnoredPatterns(yamlPath);
1711017115 }
1711117116 catch (error) {
17112- console.log ('Could not load analysis_options.yaml:\n', error);
17117+ console.error ('Could not load analysis_options.yaml:\n', error);
1711317118 }
1711417119 patterns !== null && patterns !== void 0 ? patterns : (patterns = []);
17115- this.patterns = patterns.map((pattern) => new minimatch.Minimatch(pattern));
17120+ this.patterns = patterns.map((pattern) => new minimatch_1.default.Minimatch(pattern));
17121+ }
17122+ /**
17123+ *
17124+ * @param path
17125+ */
17126+ static findClosestYamlFile(directoryPath) {
17127+ const yamlPath = path.resolve(directoryPath, 'analysis_options.yaml');
17128+ if (fs.existsSync(yamlPath)) {
17129+ return yamlPath;
17130+ }
17131+ else {
17132+ const parentDirectoryPath = path.resolve(directoryPath, '..');
17133+ if (parentDirectoryPath === directoryPath) {
17134+ return null;
17135+ }
17136+ else {
17137+ return IgnoredFiles.findClosestYamlFile(parentDirectoryPath);
17138+ }
17139+ }
17140+ }
17141+ static getIgnoredPatterns(yamlPath) {
17142+ var _a;
17143+ const yamlFile = yaml.load(fs.readFileSync(yamlPath, 'utf8'));
17144+ const exclude = (_a = yamlFile === null || yamlFile === void 0 ? void 0 : yamlFile.analyzer) === null || _a === void 0 ? void 0 : _a.exclude;
17145+ let patterns;
17146+ if (exclude) {
17147+ if (Array.isArray(exclude)) {
17148+ patterns = exclude;
17149+ }
17150+ else if (typeof exclude === 'string') {
17151+ patterns = [exclude];
17152+ }
17153+ }
17154+ patterns !== null && patterns !== void 0 ? patterns : (patterns = []);
17155+ if (yamlFile === null || yamlFile === void 0 ? void 0 : yamlFile.include) {
17156+ const newPath = path.resolve(path.dirname(yamlPath), yamlFile.include);
17157+ if (fs.existsSync(newPath)) {
17158+ return [
17159+ ...IgnoredFiles.getIgnoredPatterns(newPath),
17160+ ...patterns,
17161+ ];
17162+ }
17163+ }
17164+ return patterns;
1711617165 }
1711717166 /**
1711817167 * Whether a file is ignored
0 commit comments