Skip to content

Commit be37c88

Browse files
committed
fixes
1 parent cb324e8 commit be37c88

File tree

1 file changed

+51
-40
lines changed

1 file changed

+51
-40
lines changed

src/main.ts

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,57 @@ export async function main({
4646
repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref)
4747
})
4848

49+
const terminatingRefs = [mainBranch, ...perennialBranches]
50+
51+
const getStackGraph = (anchorPullRequest: PullRequest) => {
52+
const stackGraph = repoGraph.copy() as MultiDirectedGraph<StackNodeAttributes>
53+
stackGraph.setNodeAttribute(anchorPullRequest.head.ref, 'isCurrent', true)
54+
55+
bfsFromNode(
56+
repoGraph,
57+
anchorPullRequest.head.ref,
58+
(ref, attributes) => {
59+
if (
60+
attributes.type === 'pull-request' &&
61+
!terminatingRefs.includes(attributes.base.ref)
62+
) {
63+
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
64+
stackGraph.setNodeAttribute(attributes.base.ref, 'shouldPrint', true)
65+
66+
return false
67+
}
68+
69+
return attributes.type === 'perennial'
70+
},
71+
{
72+
mode: 'inbound',
73+
}
74+
)
75+
76+
dfsFromNode(
77+
stackGraph,
78+
anchorPullRequest.head.ref,
79+
(ref) => {
80+
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
81+
},
82+
{ mode: 'outbound' }
83+
)
84+
85+
stackGraph.forEachNode((node, attributes) => {
86+
if (!attributes.shouldPrint) {
87+
try {
88+
stackGraph.dropNode(node)
89+
} catch {
90+
// Do nothing
91+
}
92+
}
93+
})
94+
95+
return stackGraph
96+
}
97+
4998
const getOutput = (graph: MultiDirectedGraph<StackNodeAttributes>) => {
5099
const lines: string[] = []
51-
const terminatingRefs = [mainBranch, ...perennialBranches]
52100

53101
dfs(
54102
graph,
@@ -82,7 +130,7 @@ export async function main({
82130

83131
const jobs: Array<() => Promise<void>> = []
84132

85-
const stackGraph = getStackGraph(repoGraph, currentPullRequest)
133+
const stackGraph = getStackGraph(currentPullRequest)
86134

87135
const shouldSkip = () => {
88136
const neighbors = stackGraph.neighbors(currentPullRequest.head.ref)
@@ -109,7 +157,7 @@ export async function main({
109157
jobs.push(async () => {
110158
core.info(`Updating stack details for PR #${stackNode.number}`)
111159

112-
const stackGraph = getStackGraph(repoGraph, stackNode)
160+
const stackGraph = getStackGraph(stackNode)
113161
// const output = getOutput(stackGraph)
114162

115163
console.log(stackGraph.inspect())
@@ -131,43 +179,6 @@ export async function main({
131179
await Promise.allSettled(jobs.map((job) => job()))
132180
}
133181

134-
function getStackGraph(
135-
repoGraph: MultiDirectedGraph<StackNodeAttributes>,
136-
pullRequest: PullRequest
137-
) {
138-
const stackGraph = repoGraph.copy() as MultiDirectedGraph<StackNodeAttributes>
139-
stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true)
140-
141-
bfsFromNode(
142-
repoGraph,
143-
pullRequest.head.ref,
144-
(ref, attributes) => {
145-
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
146-
return attributes.type === 'perennial'
147-
},
148-
{
149-
mode: 'inbound',
150-
}
151-
)
152-
153-
dfsFromNode(
154-
stackGraph,
155-
pullRequest.head.ref,
156-
(ref) => {
157-
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
158-
},
159-
{ mode: 'outbound' }
160-
)
161-
162-
stackGraph.forEachNode((node, attributes) => {
163-
if (!attributes.shouldPrint) {
164-
stackGraph.dropNode(node)
165-
}
166-
})
167-
168-
return stackGraph
169-
}
170-
171182
export function updateDescription({
172183
description,
173184
output,

0 commit comments

Comments
 (0)