Using continues to reduce nesting

This commit is contained in:
Auto Rebase
2025-01-09 13:51:47 +01:00
parent f6c17c51a1
commit f61c87e29e
2 changed files with 32 additions and 35 deletions

19
app.ts
View File

@@ -71,10 +71,9 @@ const getCommitsForBranch = async (branch: string): Promise<Set<string>> => {
const removeIgnoredBranches = (branchesWithDependencies: Record<string, any>) => { const removeIgnoredBranches = (branchesWithDependencies: Record<string, any>) => {
let withoutIgnoredBranches = {} let withoutIgnoredBranches = {}
for (const [branch, value] of Object.entries(branchesWithDependencies)) { for (const [branch, value] of Object.entries(branchesWithDependencies)) {
if(!value.ignore) { if(value.ignore) continue;
withoutIgnoredBranches[branch] = value; withoutIgnoredBranches[branch] = value;
} }
}
return withoutIgnoredBranches; return withoutIgnoredBranches;
} }
@@ -90,11 +89,13 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
let finalBranches: Record<string, BranchWithDependencies> = {}; let finalBranches: Record<string, BranchWithDependencies> = {};
for (const branchA of branches) { for (const branchA of branches) {
for (const branchB of branches) { for (const branchB of branches) {
if(branchA !== branchB) { if(branchA !== branchB) continue;
const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]); const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]);
if (!isSuperset) continue;
const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]); const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]);
if (isSuperset) {
if(branchB === mainBranch) { if(branchB === mainBranch) {
// SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED // SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED
finalBranches[branchA] = { finalBranches[branchA] = {
@@ -108,8 +109,7 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
...finalBranches[branchA], ...finalBranches[branchA],
equalBranches: [...prevBranches, branchB] equalBranches: [...prevBranches, branchB]
}; };
} else { } else if (branchA !== mainBranch && (!finalBranches[branchA] || finalBranches[branchA].differenceWithRebase > difference.size)) {
if (branchA !== mainBranch && (!finalBranches[branchA] || finalBranches[branchA].differenceWithRebase > difference.size)) {
finalBranches[branchA] = { finalBranches[branchA] = {
...finalBranches[branchA], ...finalBranches[branchA],
rebaseBranch: branchB, rebaseBranch: branchB,
@@ -118,19 +118,16 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
} }
} }
} }
}
}
}
// Set rebase for branches with no dependencies // Set rebase for branches with no dependencies
for (const branch of branches) { for (const branch of branches) {
if(branch !== mainBranch) { if(branch !== mainBranch) continue;
finalBranches[branch] = finalBranches[branch] ?? { finalBranches[branch] = finalBranches[branch] ?? {
rebaseBranch: mainBranch, rebaseBranch: mainBranch,
differenceWithRebase: 0 differenceWithRebase: 0
} }
} }
}
return removeIgnoredBranches(finalBranches); return removeIgnoredBranches(finalBranches);
}; };

2
dist/app.js vendored

File diff suppressed because one or more lines are too long