Skip to content

Commit

Permalink
logging for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Panayil <[email protected]>
  • Loading branch information
sachin-panayil committed Jan 23, 2025
1 parent 97642df commit 582ff74
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
33 changes: 29 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,26 +476,51 @@ const fs = __importStar(__nccwpck_require__(35747));
function getFileChanges(jsonResult) {
var _a, _b, _c;
try {
console.log('\n🚀 === DEBUG START ===');
const data = JSON.parse(jsonResult);
const files = {};
console.log('\n📚 === Reading Existing Files ===');
for (const result of data.results) {
const fileName = result.ruleInfo.ruleConfig['file-name'];
console.log(`\n🔍 Checking file: ${fileName}`);
if (fs.existsSync(fileName)) {
files[fileName] = fs.readFileSync(fileName, 'utf-8');
const existingContent = fs.readFileSync(fileName, 'utf-8');
console.log(`📄 Existing content in ${fileName}:`, existingContent);
files[fileName] = existingContent;
}
else {
console.log(`❌ ${fileName} does not exist - will be created`);
files[fileName] = '';
}
}
console.log('\n⚙️ === Processing Rules and Adding Missing Content ===');
for (const result of data.results) {
const fileName = result.ruleInfo.ruleConfig['file-name'];
console.log(`\n🎯 Processing rules for: ${fileName}`);
console.log('📊 Rule status:', result.status);
console.log('🔎 Lint result:', result.lintResult);
if (((_b = (_a = result.lintResult) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.startsWith("Did not find")) ||
(result.status === "NOT_PASSED_ERROR" && ((_c = result.lintResult) === null || _c === void 0 ? void 0 : _c.passed) === false)) {
const fileName = result.ruleInfo.ruleConfig['file-name'];
const newContent = result.ruleInfo.ruleConfig['file-content'] || '';
files[fileName] += `\n ${newContent}`;
console.log('📝 Current file content:', files[fileName]);
console.log('➕ Content to be added:', newContent);
if (!files[fileName].includes(newContent)) {
files[fileName] = (files[fileName] || '') + `\n${newContent}`;
console.log('✨ Updated content:', files[fileName]);
}
else {
console.log('⏩ Content already exists - skipping');
}
}
}
console.log('\n🎉 === Final File Contents ===');
Object.entries(files).forEach(([filename, content]) => {
console.log(`\n📋 ${filename}:`, content);
});
return files;
}
catch (error) {
console.error('Error parsing repolinter results:', error);
console.error('Error in getFileChanges:', error);
return {};
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

37 changes: 32 additions & 5 deletions src/getFileChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,57 @@ interface RepolinterResult {

export function getFileChanges(jsonResult: string): { [key: string]: string } {
try {
console.log('\n🚀 === DEBUG START ===');

const data: RepolinterResult = JSON.parse(jsonResult);
const files: { [key: string]: string } = {};


console.log('\n📚 === Reading Existing Files ===');
for (const result of data.results) {
const fileName = result.ruleInfo.ruleConfig['file-name'];
console.log(`\n🔍 Checking file: ${fileName}`);

if (fs.existsSync(fileName)) {
files[fileName] = fs.readFileSync(fileName, 'utf-8');
const existingContent = fs.readFileSync(fileName, 'utf-8');
console.log(`📄 Existing content in ${fileName}:`, existingContent);
files[fileName] = existingContent;
} else {
console.log(`❌ ${fileName} does not exist - will be created`);
files[fileName] = '';
}
}

console.log('\n⚙️ === Processing Rules and Adding Missing Content ===');
for (const result of data.results) {
const fileName = result.ruleInfo.ruleConfig['file-name'];
console.log(`\n🎯 Processing rules for: ${fileName}`);
console.log('📊 Rule status:', result.status);
console.log('🔎 Lint result:', result.lintResult);

if (result.lintResult?.message?.startsWith("Did not find") ||
(result.status === "NOT_PASSED_ERROR" && result.lintResult?.passed === false)) {

const fileName = result.ruleInfo.ruleConfig['file-name'];
const newContent = result.ruleInfo.ruleConfig['file-content'] || '';
console.log('📝 Current file content:', files[fileName]);
console.log('➕ Content to be added:', newContent);

files[fileName] += `\n ${newContent}`
if (!files[fileName].includes(newContent)) {
files[fileName] = (files[fileName] || '') + `\n${newContent}`;
console.log('✨ Updated content:', files[fileName]);
} else {
console.log('⏩ Content already exists - skipping');
}
}
}

console.log('\n🎉 === Final File Contents ===');
Object.entries(files).forEach(([filename, content]) => {
console.log(`\n📋 ${filename}:`, content);
});

return files;
} catch (error) {
console.error('Error parsing repolinter results:', error);
console.error('Error in getFileChanges:', error);
return {};
}
}

0 comments on commit 582ff74

Please sign in to comment.