Skip to content

Commit

Permalink
[QA][Code Coverage] Coverage teams lookup - LESS UNKNOWNS
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneseymour committed Sep 14, 2020
1 parent f0ce903 commit 6cf390c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* under the License.
*/

import { readdirSync, statSync } from 'fs';
import { readdirSync, statSync, writeFileSync } from 'fs';
import { join } from 'path';
import { REPO_ROOT } from '@kbn/dev-utils';

import {
push,
prokGlob,
Expand All @@ -28,40 +30,44 @@ import {
isDir,
tryPath,
dropEmpty,
notFound,
encoding,
collectAndLogNotFound,
} from './enumeration_helpers';
import { stripLeading } from '../transforms';

export const enumeratePatterns = (rootPath) => (log) => (patterns) => {
export const enumeratePatterns = (notFoundLogPath) => (log) => (patterns) => {
const writeToFile = writeFileSync.bind(null, notFoundLogPath);
writeToFile('', { encoding });

const res = [];
const resPush = push(res);
const logNotFound = notFound(log);

for (const entry of patterns) {
const [pathPattern, teams] = entry;
const cleaned = stripLeading(pathPattern);
const owner = teams[0];
const existsWithOwner = pathExists(owner);

const collect = (x) => existsWithOwner(x).forEach(resPush);
tryPath(cleaned).fold(logNotFound, collect);
const collectNotFound = collectAndLogNotFound(writeToFile);
const collectFound = (x) => existsWithOwner(x).forEach(resPush);
tryPath(cleaned).fold(collectNotFound(log), collectFound);
}

return res;

function pathExists(owner) {
const creeper = (x) => creepFsSync(x, [], rootPath, owner);
const creeper = (x) => creepFsSync(x, [], owner);
return function creepAllAsGlobs(pathPattern) {
return prokGlob(pathPattern).map(creeper).filter(dropEmpty);
};
}
};

function creepFsSync(aPath, xs, rootPath, owner) {
function creepFsSync(aPath, xs, owner) {
xs = xs || [];

const joinRoot = join.bind(null, rootPath);
const trimRoot = trim(rootPath);
const joinRoot = join.bind(null, REPO_ROOT);
const trimRoot = trim(REPO_ROOT);
const joined = joinRoot(aPath);
const isADir = isDir(joined);

Expand All @@ -73,7 +79,7 @@ function creepFsSync(aPath, xs, rootPath, owner) {
const full = isADir ? join(aPath, entry) : entry;
const fullIsDir = statSync(full).isDirectory();

if (fullIsDir && !isBlackListedDir(full)) xs = creepFsSync(full, xs, rootPath, owner);
if (fullIsDir && !isBlackListedDir(full)) xs = creepFsSync(full, xs, owner);
else if (isWhiteListedFile(full)) xs.push(`${trimRoot(full)} ${owner}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { statSync } from 'fs';
import isGlob from 'is-glob';
import glob from 'glob';
import { left, right, tryCatch } from '../either';
import { pipe } from '../utils';

export const push = (xs) => (x) => xs.push(x);
export const pathExists = (x) => tryCatch(() => statSync(x)).fold(left, right);
Expand All @@ -44,3 +45,11 @@ export const tryPath = (x) => {
};
export const dropEmpty = (x) => x.length > 0;
export const notFound = (log) => (err) => log.error(`\n!!! Not Found: \n${err}`);
export const encoding = 'utf8';
const appendUtf8 = { flag: 'a', encoding };
const flushNotFound = (fileWrite) => (nf) => {
fileWrite(`${nf}\n`, appendUtf8);
return nf;
};
export const collectAndLogNotFound = (fileWrite) => (log) =>
pipe(flushNotFound(fileWrite), notFound(log));
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { flush } from './flush';
import { enumeratePatterns } from './enumerate_patterns';
import { push } from './enumeration_helpers';
import { pipe } from '../utils';
import { resolve } from 'path';

const flags = {
string: ['src', 'dest'],
Expand All @@ -47,7 +48,7 @@ export const generateTeamAssignments = () => {
() =>
pipe(
logSuccess(flags.src, log),
enumeratePatterns(REPO_ROOT)(log),
enumeratePatterns(notFoundPath())(log),
flush(flags.dest)(log)
)(new Map(data))
);
Expand All @@ -71,3 +72,7 @@ function logSuccess(src, log) {
return dataObj;
};
}
function notFoundPath() {
const x = 'src/dev/code_coverage/ingest_coverage/team_assignment/not_found_team_assignments.txt';
return resolve(REPO_ROOT, x);
}

0 comments on commit 6cf390c

Please sign in to comment.