Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhl committed Nov 27, 2024
1 parent 7858509 commit 5982c04
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 47 deletions.
60 changes: 40 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42841,15 +42841,12 @@ async function main({
skipSingleStacks
}) {
const repoGraph = new import_graphology.MultiDirectedGraph();
repoGraph.addNode(mainBranch, {
repoGraph.mergeNode(mainBranch, {
type: "perennial",
ref: mainBranch
});
perennialBranches.forEach((perennialBranch) => {
if (repoGraph.hasNode(perennialBranch)) {
return;
}
repoGraph.addNode(perennialBranch, {
repoGraph.mergeNode(perennialBranch, {
type: "perennial",
ref: perennialBranch
});
Expand All @@ -42858,58 +42855,81 @@ async function main({
(pullRequest) => pullRequest.state === "open"
);
openPullRequests.forEach((openPullRequest) => {
if (repoGraph.hasNode(openPullRequest.head.ref)) {
return;
}
repoGraph.addNode(openPullRequest.head.ref, {
repoGraph.mergeNode(openPullRequest.head.ref, {
type: "pull-request",
...openPullRequest
});
});
openPullRequests.forEach((openPullRequest) => {
const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref);
if (hasExistingBasePullRequest) {
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
return;
}
const basePullRequest = pullRequests.find(
(basePullRequest2) => basePullRequest2.head.ref === openPullRequest.base.ref
);
if (basePullRequest?.state === "closed") {
repoGraph.addNode(openPullRequest.base.ref, {
repoGraph.mergeNode(openPullRequest.base.ref, {
type: "pull-request",
...basePullRequest
});
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
return;
}
repoGraph.addNode(openPullRequest.base.ref, {
repoGraph.mergeNode(openPullRequest.base.ref, {
type: "orphan-branch",
ref: openPullRequest.base.ref
});
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref);
});
const terminatingRefs = [mainBranch, ...perennialBranches];
const getStackGraph = (pullRequest) => {
const stackGraph2 = repoGraph.copy();
stackGraph2.setNodeAttribute(pullRequest.head.ref, "isCurrent", true);
const stackGraph2 = new import_graphology.MultiDirectedGraph();
stackGraph2.addNode(pullRequest.head.ref, {
type: "pull-request",
isCurrent: true,
...pullRequest
});
(0, import_graphology_traversal.bfsFromNode)(
stackGraph2,
repoGraph,
pullRequest.head.ref,
(ref, attributes) => {
stackGraph2.setNodeAttribute(ref, "shouldPrint", true);
if (attributes.type === "pull-request") {
stackGraph2.addNode(attributes.head.ref, {
...attributes,
shouldPrint: true
});
} else {
stackGraph2.addNode(ref, {
...attributes,
shouldPrint: true
});
}
return attributes.type === "perennial" || attributes.type === "orphan-branch";
},
{ mode: "inbound" }
);
(0, import_graphology_traversal.dfsFromNode)(
stackGraph2,
pullRequest.head.ref,
(ref) => {
stackGraph2.setNodeAttribute(ref, "shouldPrint", true);
(_, attributes) => {
if (attributes.type !== "pull-request") {
return false;
}
stackGraph2.addNode(attributes.head.ref, {
...attributes,
shouldPrint: true
});
return true;
},
{ mode: "outbound" }
);
stackGraph2.forEachNode((ref, stackNode) => {
if (!stackNode.shouldPrint) {
stackGraph2.dropNode(ref);
}
});
return stackGraph2;
};
const getOutput = (graph) => {
Expand Down
70 changes: 43 additions & 27 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ export async function main({
}: Context) {
const repoGraph = new MultiDirectedGraph<StackNodeAttributes>()

repoGraph.addNode(mainBranch, {
repoGraph.mergeNode(mainBranch, {
type: 'perennial',
ref: mainBranch,
})

perennialBranches.forEach((perennialBranch) => {
if (repoGraph.hasNode(perennialBranch)) {
return
}

repoGraph.addNode(perennialBranch, {
repoGraph.mergeNode(perennialBranch, {
type: 'perennial',
ref: perennialBranch,
})
Expand All @@ -36,11 +32,7 @@ export async function main({
)

openPullRequests.forEach((openPullRequest) => {
if (repoGraph.hasNode(openPullRequest.head.ref)) {
return
}

repoGraph.addNode(openPullRequest.head.ref, {
repoGraph.mergeNode(openPullRequest.head.ref, {
type: 'pull-request',
...openPullRequest,
})
Expand All @@ -49,7 +41,7 @@ export async function main({
openPullRequests.forEach((openPullRequest) => {
const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref)
if (hasExistingBasePullRequest) {
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)

return
}
Expand All @@ -58,33 +50,48 @@ export async function main({
(basePullRequest) => basePullRequest.head.ref === openPullRequest.base.ref
)
if (basePullRequest?.state === 'closed') {
repoGraph.addNode(openPullRequest.base.ref, {
repoGraph.mergeNode(openPullRequest.base.ref, {
type: 'pull-request',
...basePullRequest,
})
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)

return
}

repoGraph.addNode(openPullRequest.base.ref, {
repoGraph.mergeNode(openPullRequest.base.ref, {
type: 'orphan-branch',
ref: openPullRequest.base.ref,
})
repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)
repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref)
})

const terminatingRefs = [mainBranch, ...perennialBranches]

const getStackGraph = (pullRequest: PullRequest) => {
const stackGraph = repoGraph.copy() as MultiDirectedGraph<StackNodeAttributes>
stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true)
const stackGraph = new MultiDirectedGraph<StackNodeAttributes>()
stackGraph.addNode(pullRequest.head.ref, {
type: 'pull-request',
isCurrent: true,
...pullRequest,
})

bfsFromNode(
stackGraph,
repoGraph,
pullRequest.head.ref,
(ref, attributes) => {
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
if (attributes.type === 'pull-request') {
stackGraph.addNode(attributes.head.ref, {
...attributes,
shouldPrint: true,
})
} else {
stackGraph.addNode(ref, {
...attributes,
shouldPrint: true,
})
}

return attributes.type === 'perennial' || attributes.type === 'orphan-branch'
},
{ mode: 'inbound' }
Expand All @@ -93,17 +100,26 @@ export async function main({
dfsFromNode(
stackGraph,
pullRequest.head.ref,
(ref) => {
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
(_, attributes) => {
if (attributes.type !== 'pull-request') {
return false
}

stackGraph.addNode(attributes.head.ref, {
...attributes,
shouldPrint: true,
})

return true
},
{ mode: 'outbound' }
)

// stackGraph.forEachNode((ref, stackNode) => {
// if (!stackNode.shouldPrint) {
// stackGraph.dropNode(ref)
// }
// })
stackGraph.forEachNode((ref, stackNode) => {
if (!stackNode.shouldPrint) {
stackGraph.dropNode(ref)
}
})

return stackGraph
}
Expand Down

0 comments on commit 5982c04

Please sign in to comment.