-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassess-difficulty.ts
More file actions
83 lines (66 loc) · 2.68 KB
/
assess-difficulty.ts
File metadata and controls
83 lines (66 loc) · 2.68 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
import fs from "fs";
import { promisify } from "util";
import { assessBugDifficulty, DifficultyLevel } from "./review-utils-difficulty";
const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
// Define a type for the bug object
interface Bug {
prNumber: number;
repo: string;
difficultyLevel?: DifficultyLevel;
difficultyAssessedAt?: string;
// Add other properties that might be needed
[key: string]: any;
}
async function main() {
try {
// Clear previous prompts file
await fs.promises.writeFile("review-difficulty-prompts.txt", "");
// Read existing bugs
const bugsJson = await readFileAsync("bugs.json", "utf8");
const bugs: Bug[] = JSON.parse(bugsJson);
// Filter out bugs that already have a difficulty assessment
const bugsToAssess = bugs.filter(bug => !bug.difficultyLevel);
const totalBugs = bugsToAssess.length;
console.log(`Total bugs to assess difficulty: ${totalBugs} (${bugs.length - totalBugs} already have difficulty)`);
const batchSize = 5;
for (let i = 0; i < bugsToAssess.length; i += batchSize) {
const batch = bugsToAssess.slice(i, i + batchSize);
await Promise.all(
batch.map(async (bug: Bug, index: number) => {
console.log(
`Assessing difficulty for bug ${i + index + 1}/${totalBugs} in PR #${bug.prNumber} from ${bug.repo}`
);
// Assess the bug difficulty
const difficulty = await assessBugDifficulty(bug);
// Update bug object
if (difficulty !== null) {
bug.difficultyLevel = difficulty;
bug.difficultyAssessedAt = new Date().toISOString();
}
console.log(
`Difficulty assessment for PR #${bug.prNumber} (${i + index + 1}/${totalBugs}): ${
difficulty || "FAILED"
}`
);
})
);
// Need to update the original bugs array with our changes
for (const assessedBug of batch) {
const originalBug = bugs.find(b => b.prNumber === assessedBug.prNumber && b.repo === assessedBug.repo);
if (originalBug && assessedBug.difficultyLevel !== null) {
originalBug.difficultyLevel = assessedBug.difficultyLevel;
originalBug.difficultyAssessedAt = assessedBug.difficultyAssessedAt;
}
}
// Save after each batch in case of interruption
await writeFileAsync("bugs.json", JSON.stringify(bugs, null, 2));
// Add a small delay to avoid rate limits
await new Promise((resolve) => setTimeout(resolve, 1000));
}
console.log("Difficulty assessment completed!");
} catch (error) {
console.error("Error:", error);
}
}
main();