pr-sizewise
Version:
A CLI tool that measures and reports pull request sizes for GitHub and GitLab, helping teams maintain manageable code changes.
84 lines • 2.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatJsonOutput = formatJsonOutput;
exports.displayConsoleOutput = displayConsoleOutput;
exports.displayError = displayError;
exports.checkAndDisplaySizeWarning = checkAndDisplaySizeWarning;
const errors_1 = require("../utils/errors");
const logger_1 = require("../utils/logger");
const logger = (0, logger_1.createDefaultLogger)();
/**
* Formats output for JSON display
*/
function formatJsonOutput(result, success, platform, error) {
return {
success,
data: result,
error,
platform,
timestamp: new Date().toISOString(),
version: process.env.npm_package_version ?? '1.0.0',
};
}
/**
* Display analysis results in console format
*/
function displayConsoleOutput(result, platform, verbose) {
const { size, details } = result;
// Header
logger.header('📊 Pull Request Analysis');
// Platform
logger.info(`Platform: ${platform.toUpperCase()}`);
// Size classification
logger.blank();
logger.info('Size Classification:', size.toUpperCase());
// Metrics
logger.subheader('Metrics');
for (const detail of details) {
logger.dim('•', detail);
}
// Verbose output
if (verbose) {
logger.subheader('Thresholds');
for (const [category, threshold] of Object.entries(result.thresholds)) {
logger.dim(`${category}:`);
logger.dim(' Files:', threshold.files);
logger.dim(' Lines:', threshold.lines);
logger.dim(' Directories:', threshold.directories);
}
}
logger.blank();
}
/**
* Display error message in appropriate format
*/
function displayError(error, isJson, platform) {
const { message } = (0, errors_1.handleError)(error);
if (isJson) {
logger.json(formatJsonOutput(null, false, platform, message));
}
else {
logger.logError('Error', error);
}
}
/**
* Check and display size warning
*/
function checkAndDisplaySizeWarning(result, thresholds, platform, isJson) {
const thresholdKeys = Object.keys(thresholds);
const largestThreshold = thresholdKeys[thresholdKeys.length - 1];
if (result.size === largestThreshold) {
const message = `This ${platform === 'github' ? 'pull' : 'merge'} request is ${result.size.toLowerCase()}! Consider breaking it down into smaller chunks.`;
if (isJson) {
logger.json({ warning: message });
}
else {
logger.blank();
logger.warning(message);
logger.blank();
}
return true;
}
return false;
}
//# sourceMappingURL=output.js.map