@@ -46,9 +46,57 @@ export async function main({
46
46
repoGraph . mergeDirectedEdge ( pullRequest . base . ref , pullRequest . head . ref )
47
47
} )
48
48
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
+
49
98
const getOutput = ( graph : MultiDirectedGraph < StackNodeAttributes > ) => {
50
99
const lines : string [ ] = [ ]
51
- const terminatingRefs = [ mainBranch , ...perennialBranches ]
52
100
53
101
dfs (
54
102
graph ,
@@ -82,7 +130,7 @@ export async function main({
82
130
83
131
const jobs : Array < ( ) => Promise < void > > = [ ]
84
132
85
- const stackGraph = getStackGraph ( repoGraph , currentPullRequest )
133
+ const stackGraph = getStackGraph ( currentPullRequest )
86
134
87
135
const shouldSkip = ( ) => {
88
136
const neighbors = stackGraph . neighbors ( currentPullRequest . head . ref )
@@ -109,7 +157,7 @@ export async function main({
109
157
jobs . push ( async ( ) => {
110
158
core . info ( `Updating stack details for PR #${ stackNode . number } ` )
111
159
112
- const stackGraph = getStackGraph ( repoGraph , stackNode )
160
+ const stackGraph = getStackGraph ( stackNode )
113
161
// const output = getOutput(stackGraph)
114
162
115
163
console . log ( stackGraph . inspect ( ) )
@@ -131,43 +179,6 @@ export async function main({
131
179
await Promise . allSettled ( jobs . map ( ( job ) => job ( ) ) )
132
180
}
133
181
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
-
171
182
export function updateDescription ( {
172
183
description,
173
184
output,
0 commit comments