@codechecks/client
Version:
Open source platform for code review automation
41 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Local_1 = require("./Local");
const Circle_1 = require("./Circle");
const Travis_1 = require("./Travis");
const Semaphore_1 = require("./Semaphore");
const BuildKite_1 = require("./BuildKite");
const GithubActions_1 = require("./GithubActions");
const errors_1 = require("../utils/errors");
const logger_1 = require("../logger");
const providers = [
Circle_1.Circle,
Travis_1.Travis,
Semaphore_1.Semaphore,
BuildKite_1.BuildKite,
Local_1.LocalProvider,
GithubActions_1.GithubActions,
];
// @todo refactor passing CLI options
function findProvider(env, localProject) {
const providerInstances = providers.map(Provider => new Provider(env, localProject));
let currentlyRunningProviders = providerInstances.filter(p => p.isCurrentlyRunning());
if (currentlyRunningProviders.length === 0) {
throw errors_1.crash("Could not find running CI.");
}
if (currentlyRunningProviders.length > 1) {
logger_1.logger.debug("Detected more than 1 CI providers, ignoring local provider");
// if there is more than one CI provider ignore local provider
// this is done because it's hard to realize if we ran on ANY CI
currentlyRunningProviders = currentlyRunningProviders.filter(ci => !Local_1.checkIfIsLocalMode(ci));
}
if (currentlyRunningProviders.length > 1) {
throw errors_1.crash(`Found more than 1 running CI! Found CIs: ${currentlyRunningProviders.map(ci => getClassName(ci)).join(", ")}`);
}
return currentlyRunningProviders[0];
}
exports.findProvider = findProvider;
function getClassName(instance) {
return instance.constructor.name || "unnamed class";
}
//# sourceMappingURL=index.js.map