pr-sizewise
Version:
A CLI tool that measures and reports pull request sizes for GitHub and GitLab, helping teams maintain manageable code changes.
131 lines • 4.62 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_CONFIG = void 0;
exports.loadConfigFromFile = loadConfigFromFile;
exports.createUniversalAnalyzer = createUniversalAnalyzer;
exports.analyzePullRequest = analyzePullRequest;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
// Legacy GitLab-only analyzer is available in src/legacy/ but not exported by default
const analyzer_1 = require("./analyzer");
__exportStar(require("./types"), exports);
__exportStar(require("./analyzer"), exports);
__exportStar(require("./providers"), exports);
__exportStar(require("./utils/diff-parser"), exports);
/**
* Default configuration values
*/
exports.DEFAULT_CONFIG = {
thresholds: {
small: {
files: 5,
lines: 50,
directories: 2,
},
medium: {
files: 10,
lines: 200,
directories: 4,
},
large: {
files: 20,
lines: 500,
directories: 8,
},
},
excludePatterns: [
'**/*.lock',
'**/package-lock.json',
'**/yarn.lock',
'**/pnpm-lock.yaml',
],
comment: {
enabled: false,
template: '🔍 **Pull Request Size:** {size}',
updateExisting: true,
},
label: {
enabled: false,
prefix: 'size:',
},
logging: {
verbose: true,
},
};
/**
* Utility function to load configuration from file
*/
function loadConfigFromFile(configPath) {
let config = { ...exports.DEFAULT_CONFIG };
// Check for config files in both .gitlab and .github directories
const gitlabConfigPath = path_1.default.resolve(process.cwd(), '.gitlab/sizewise.config.json');
const githubConfigPath = path_1.default.resolve(process.cwd(), '.github/sizewise.config.json');
const finalConfigPath = configPath ??
(fs_1.default.existsSync(gitlabConfigPath) ? gitlabConfigPath :
(fs_1.default.existsSync(githubConfigPath) ? githubConfigPath : undefined));
if (finalConfigPath !== undefined) {
try {
const userConfig = JSON.parse(fs_1.default.readFileSync(finalConfigPath, 'utf8'));
config = {
...exports.DEFAULT_CONFIG,
...userConfig,
thresholds: {
...exports.DEFAULT_CONFIG.thresholds,
...userConfig.thresholds,
},
comment: {
...exports.DEFAULT_CONFIG.comment,
...userConfig.comment,
},
label: {
...exports.DEFAULT_CONFIG.label,
...userConfig.label,
},
logging: {
...exports.DEFAULT_CONFIG.logging,
...userConfig.logging,
},
};
}
catch (error) {
throw new Error(`Failed to load config file: ${finalConfigPath}. ${error}`);
}
}
return config;
}
/**
* Convenience function to create a platform-agnostic analyzer
*/
function createUniversalAnalyzer(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config) {
return analyzer_1.UniversalSizeWiseAnalyzer;
}
/**
* Platform-agnostic analysis function with auto-detection
* @param prId Pull/Merge request ID
* @param config Optional configuration override
*/
async function analyzePullRequest(prId, config) {
const finalConfig = config ? { ...exports.DEFAULT_CONFIG, ...config } : exports.DEFAULT_CONFIG;
const analyzer = await analyzer_1.UniversalSizeWiseAnalyzer.createWithAutoDetect(finalConfig);
return analyzer.analyzePullRequest(prId);
}
//# sourceMappingURL=index.js.map