-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-comment-edits.ts
More file actions
110 lines (89 loc) · 3.65 KB
/
remove-comment-edits.ts
File metadata and controls
110 lines (89 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import fs from 'fs';
interface Bug {
repo: string;
prNumber: number;
diffHunk: string;
commentLink: string;
commentBody: string;
filePath: string;
[key: string]: any;
}
// Helper function to check if a line is a comment based on common comment syntaxes
function isCommentLine(line: string): boolean {
// Trim whitespace
line = line.trim();
// Common comment patterns across languages
const commentPatterns = [
/^\/\//, // C-style single line comments
/^\/\*/, // C-style multi-line comments start
/^\*/, // C-style multi-line comment continuation
/^\#/, // Python/Ruby/Shell style comments
/^--/, // SQL/Haskell style comments
/^;/, // Lisp/Assembly style comments
/^<!--/, // HTML/XML style comments
/^%/, // LaTeX/Matlab style comments
/^\/\/\//, // Triple slash comments (e.g., TypeScript)
/^'''/, // Python triple quotes
/^"""/, // Python triple double quotes
/^<!--/, // HTML comments
];
return commentPatterns.some(pattern => pattern.test(line));
}
// Function to check if diff only changes comments
function isCommentOnlyChange(diffHunk: string): boolean {
// Split diff into lines
const lines = diffHunk.split('\n');
// Track if we've seen any non-comment changes
let hasNonCommentChanges = false;
for (const line of lines) {
// Skip diff metadata lines (starting with @@)
if (line.startsWith('@@')) continue;
// Only look at added/removed lines
if (!line.startsWith('+') && !line.startsWith('-')) continue;
// Remove the +/- prefix
const codeLine = line.slice(1);
// If this changed line is not a comment, we found a non-comment change
if (!isCommentLine(codeLine)) {
hasNonCommentChanges = true;
break;
}
}
return !hasNonCommentChanges;
}
async function main() {
console.log('Starting to process bugs.json...');
// Read bugs.json
const bugsData = JSON.parse(fs.readFileSync('bugs.json', 'utf8'));
const bugs: Bug[] = Array.isArray(bugsData) ? bugsData : Object.values(bugsData);
console.log(`Total bugs before filtering: ${bugs.length}`);
const filteredBugs: Bug[] = [];
let commentEditCount = 0;
// Process each bug
for (const bug of bugs) {
if (!isCommentOnlyChange(bug.diffHunk)) {
filteredBugs.push(bug);
} else {
commentEditCount++;
console.log(`Found comment-only change in ${bug.repo}#${bug.prNumber}:`);
console.log(` File: ${bug.filePath}`);
console.log(` Comment: ${bug.commentBody.slice(0, 100)}...`);
console.log(` Link: ${bug.commentLink}`);
console.log(` Diff:\n${bug.diffHunk}\n`);
}
}
console.log('\nSummary:');
console.log(`Total bugs: ${bugs.length}`);
console.log(`Comment-only changes found: ${commentEditCount}`);
console.log(`Remaining bugs: ${filteredBugs.length}`);
// Backup original file
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
fs.copyFileSync('bugs.json', `bugs.backup.${timestamp}.json`);
console.log(`\nCreated backup at bugs.backup.${timestamp}.json`);
// Write filtered data back to bugs.json
const outputData = Array.isArray(bugsData)
? filteredBugs
: Object.fromEntries(filteredBugs.map((bug, index) => [index.toString(), bug]));
fs.writeFileSync('bugs.json', JSON.stringify(outputData, null, 2));
console.log('Updated bugs.json with comment-only changes removed');
}
main().catch(console.error);