Compare commits

...

1 commit

Author SHA1 Message Date
464edc9cf7 feat: sapling scm support
Some checks failed
CI / Lint (pull_request) Failing after 51s
CI / Test Node (pull_request) Failing after 14s
Conventional Tools Commitlint / Commitlint (pull_request) Successful in 5s
Now you can run this inside a sapling repo. It will automatically pick what
source control you are using by checking for the root repo.
2024-09-16 20:09:41 +01:00
2 changed files with 39 additions and 5 deletions

View file

@ -48,6 +48,40 @@ export const validate = async (argv: Argv) => {
}
};
async function isGitRepo() {
const isGit = await exec(`git rev-parse --is-inside-work-tree`);
return isGit.code === 0;
}
async function isSaplingRepo() {
const isSapling = await exec(`sl root`);
return isSapling.code === 0;
}
async function getDiff(): Promise<string | undefined> {
if (await isGitRepo()) {
const diffText = await exec(`git diff origin/HEAD...HEAD`);
if (diffText.code > 0) {
error("Error loading the diff\n\n" + diffText.stderr);
return undefined;
}
return diffText.stdout;
}
if (await isSaplingRepo()) {
const diffText = await exec(`sl diff -g -r '. % public()'`);
if (diffText.code > 0) {
error("Error loading the diff\n\n" + diffText.stderr);
return undefined;
}
return diffText.stdout;
}
error("Unable to get a diff no repo was found\n");
}
export const run = async (argv = process.argv) => {
const parsed: Argv = await yargs(hideBin(argv)).options(options).argv;
const validationError = await validate(parsed);
@ -62,12 +96,12 @@ export const run = async (argv = process.argv) => {
return lcovDiff(baseCoverage, compareCoverage);
}
const diffText = await exec(`git diff origin/HEAD...HEAD`);
if (diffText.code > 0) {
return error("Error loading the diff\n\n" + diffText.stderr);
const diffText = await getDiff();
if (!diffText) {
return;
}
const diff = parseDiff.default(diffText.stdout);
const diff = parseDiff.default(diffText);
const { percentage } = report(diff, baseCoverage);
process.exit(percentage > 90 ? 0 : 1);

View file

@ -1,7 +1,7 @@
const getCoverageForFile = (file: any, coverage: any) => {
for (const cov of coverage) {
const report: { [k: number]: number } = {};
if (cov.file === file.to) {
if (cov.file.replace("./", "") === file.to) {
for (const detail of cov.lines.details) {
report[detail.line] = detail.hit;
}