Skip to content

Commit

Permalink
Merge pull request #77 from Tridentinus/backup-correctness
Browse files Browse the repository at this point in the history
Reduced correctness latency
  • Loading branch information
Tridentinus authored Sep 23, 2024
2 parents 5d62de9 + d96aaaa commit ec440a9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
22 changes: 13 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export default [
'@typescript-eslint': typescriptPlugin,
},
rules: {
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/consistent-type-definitions': 'warn',
'prefer-const': 'warn',
'no-console': 'off'
// Core TypeScript rules
'@typescript-eslint/no-unused-vars': 'warn', // Quick scan for unused variables
'no-undef': 'warn', // Prevent use of undefined variables
'@typescript-eslint/no-redeclare': 'warn', // Prevent variable redeclaration
'no-extra-semi': 'warn', // Check for unnecessary semicolons
'no-constant-condition': 'warn', // Warn about constant conditions in control statements
'no-console': 'off', // Allow console.log
},
},
{
Expand All @@ -32,10 +34,12 @@ export default [
},
},
rules: {
'no-unused-vars': 'warn',
'consistent-return': 'warn',
'prefer-const': 'warn',
'no-console': 'off',
'no-unused-vars': 'warn', // Warn about unused variables
'no-undef': 'warn', // Prevent use of undefined variables
'no-redeclare': 'warn', // Prevent variable redeclaration
'no-extra-semi': 'warn', // Check for unnecessary semicolons
'no-constant-condition': 'warn', // Warn about constant conditions in control statements
'no-console': 'off', // Allow console.log
},
},
];
8 changes: 4 additions & 4 deletions src/busFactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ export function calculateBusFactor(contributors: CommitNode[]): number {
});

// Log the number of commits per contributor
logMessage('INFO', 'Commit count by author:');
logMessage('DEBUG', 'Commit count by author:');
Object.entries(commitCountByAuthor).forEach(([author, count]) => {
logMessage('INFO', `${author}: ${count} commits`);
logMessage('DEBUG', `${author}: ${count} commits`);
});

// Sort contributors by commit count
const sortedContributors = Object.entries(commitCountByAuthor).sort((a, b) => b[1] - a[1]);

// Log the sorted contributors
logMessage('INFO', 'Sorted contributors by commit count:');
logMessage('DEBUG', 'Sorted contributors by commit count:');
sortedContributors.forEach(([author, count]) => {
logMessage('INFO', `${author}: ${count} commits`);
logMessage('DEBUG', `${author}: ${count} commits`);
});

// Calculate the bus factor (e.g., contributors covering 50% of the total commits)
Expand Down
27 changes: 25 additions & 2 deletions src/correctness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,36 @@ export async function cleanUp(repoDir: string): Promise<void> {
logMessage('INFO', `Cleaning up ${repoDir}`);
try {
await fs.rm(repoDir, { recursive: true, force: true });
await new Promise(resolve => setTimeout(resolve, 5000));
logMessage('INFO', 'Repository contents cleaned up successfully');

// Retry logic: Check if directory is truly deleted
const maxRetries = 5;
const delayBetweenRetries = 500; // 0.5 seconds between retries
let retries = 0;
let dirExists = true;

while (retries < maxRetries && dirExists) {
try {
await fs.access(repoDir);
logMessage('INFO', `Directory still exists after removal attempt. Retrying...`);
await new Promise(resolve => setTimeout(resolve, delayBetweenRetries));
} catch {
// Directory doesn't exist anymore
dirExists = false;
}
retries++;
}

if (dirExists) {
logMessage('ERROR', `Failed to fully clean up ${repoDir} after ${maxRetries} retries`);
} else {
logMessage('INFO', 'Repository contents cleaned up successfully');
}
} catch (error) {
logMessage('ERROR', `Error cleaning up repository contents: ${error instanceof Error ? error.message : String(error)}`);
}
}


export async function ensureRepoDir(repoDir: string): Promise<void> {
try {
await fs.access(repoDir);
Expand Down
4 changes: 2 additions & 2 deletions src/irmMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function calculateIRM(issues: IssueNode[]) {

const averageResponseTime = issueCount > 0 ? totalResponseTime / issueCount : 0;

logMessage('INFO', `Calculated IRM (Average Issue Response Time): ${averageResponseTime} minutes`);
logMessage('DEBUG', `Calculated IRM (Average Issue Response Time): ${averageResponseTime} minutes`);

// Normalize IRM to a score between 0 and 1
return normalizeIRM(averageResponseTime, maxResponseTime);
Expand Down Expand Up @@ -178,7 +178,7 @@ export function calculateIRM(issues: IssueNode[]) {
export function normalizeIRM (averageResponseTime: number, maxResponseTime: number) {
// Clamp response time to maxResponseTime and normalize between 0 and 1
const clampedResponseTime = Math.min(averageResponseTime, maxResponseTime);
logMessage('INFO', `Clamped Response Time: ${clampedResponseTime} minutes`);
logMessage('DEBUG', `Clamped Response Time: ${clampedResponseTime} minutes`);
logMessage('INFO', `Normalized IRM Score: ${1 - clampedResponseTime / maxResponseTime}`);
return 1 - clampedResponseTime / maxResponseTime;

Expand Down

0 comments on commit ec440a9

Please sign in to comment.