git-auto-badger
Version:
Add badges to your project markdown in 2 seconds
34 lines (33 loc) • 1.72 kB
JavaScript
const { providerTypes, badgeTypes } = require("../constants/types");
const { detectRepoUrl } = require("../helpers/detectRepoUrl");
const { detectType } = require("../helpers/detectType");
const { parseRepoUrl } = require("../helpers/parseRepoUrl");
const { ciProviders } = require("../constants/provierConstants");
const chalk = require("chalk");
exports.generate = async function ({ exclude }) {
if (exclude.includes(badgeTypes.BUILD)) return "";
const [{ type, ...rest }, repoUrl] = await Promise.all([
detectType(ciProviders, "CI"),
detectRepoUrl(),
]);
const { repoOwner, repoName } = parseRepoUrl(repoUrl);
switch (type) {
case providerTypes.TRAVIS:
return `[](https://travis-ci.org/${repoOwner}/${repoName})`;
case providerTypes.GITHUB:
return `[}?style=flat-square&color=%23007a1f)](https://github.com/${repoOwner}/${repoName}/actions)`;
case providerTypes.APPVEYOR:
return `[](https://ci.appveyor.com/api/projects/status/github/${repoOwner}/${repoName})`;
case providerTypes.CIRCLECI:
return `[](https://circleci.com/gh/${repoOwner}/${repoName})`;
default:
console.warn(
chalk.yellow(
"Could not find any CI related configuration. Skipping it..."
)
);
return "";
}
};