Skip to content

Commit

Permalink
🎨 (index) pettify the file
Browse files Browse the repository at this point in the history
  • Loading branch information
Spoutnik97 committed Jan 22, 2022
1 parent bdc0c69 commit 080b44a
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
// Provides dev-time type structures for `danger` - doesn't affect runtime.
// @ts-ignore
import * as generateMarkdownTable from "markdown-table"
import { DangerDSLType } from "../node_modules/danger/distribution/dsl/DangerDSL"
import { generateCoverageTable } from "./services/generateCoverageTable"
import * as generateMarkdownTable from "markdown-table";
import { DangerDSLType } from "../node_modules/danger/distribution/dsl/DangerDSL";
import { generateCoverageTable } from "./services/generateCoverageTable";

declare var danger: DangerDSLType
export declare function message(message: string): void
export declare function warn(message: string): void
export declare function fail(message: string): void
export declare function markdown(message: string): void
declare var danger: DangerDSLType;
export declare function message(message: string): void;
export declare function warn(message: string): void;
export declare function fail(message: string): void;
export declare function markdown(message: string): void;

export interface PluginOptions {
title: string
ignoreCoveragePattern: string[]
coverageFilesPath: string
projectRoot?: string
title: string;
ignoreCoveragePattern: string[];
coverageFilesPath: string;
projectRoot?: string;
}

export const defaultPluginOptions: PluginOptions[] = [
{
title: "Coverage",
ignoreCoveragePattern: [".test.", ".snap"],
coverageFilesPath: "coverage/coverage-final.json",
},
]
coverageFilesPath: "coverage/coverage-final.json"
}
];
/**
* Danger.JS plugin to display the code coverage on a pull request by commenting it via the CI
*/
export function codeCoverage(pluginOptions: PluginOptions[] = defaultPluginOptions) {
export function codeCoverage(
pluginOptions: PluginOptions[] = defaultPluginOptions
) {
pluginOptions.forEach(options => {
const filterFiles = (file: string) => {
let isFileDisplayed = true
let isFileDisplayed = true;
options.ignoreCoveragePattern.forEach(pattern => {
if (file.includes(pattern)) {
isFileDisplayed = false
isFileDisplayed = false;
}
})
return isFileDisplayed
}
});
return isFileDisplayed;
};

try {
const coverageTable = [["File", "Branches", "Statements"]]
.concat([[], [":heavy_plus_sign: **NEW FILES**"], []])
.concat(generateCoverageTable(danger.git.created_files.filter(filterFiles), options))
.concat(
generateCoverageTable(
danger.git.created_files.filter(filterFiles),
options
)
)
.concat([[], [":pencil2: **MODIFIED FILES**"], []])
.concat(generateCoverageTable(danger.git.modified_files.filter(filterFiles), options))
.concat(
generateCoverageTable(
danger.git.modified_files.filter(filterFiles),
options
)
);

markdown(`# ${options.title}\n${generateMarkdownTable(coverageTable)}`)
markdown(`# ${options.title}\n${generateMarkdownTable(coverageTable)}`);
} catch (error) {
fail(`An error occurred when getting the code coverage: ${error.message}. Danger exits with code: ${error.code}`)
fail(
`An error occurred when getting the code coverage: ${error.message}. Danger exits with code: ${error.code}`
);
}
})
});
}

0 comments on commit 080b44a

Please sign in to comment.