Skip to content

Commit f6f74aa

Browse files
committed
fix: add remote branches to repo graph
1 parent 219de3c commit f6f74aa

File tree

3 files changed

+87
-64
lines changed

3 files changed

+87
-64
lines changed

dist/index.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42837,53 +42837,36 @@ async function main({
4283742837
currentPullRequest,
4283842838
pullRequests,
4283942839
mainBranch,
42840+
remoteBranches,
4284042841
perennialBranches,
4284142842
skipSingleStacks
4284242843
}) {
4284342844
const repoGraph = new import_graphology.MultiDirectedGraph();
42844-
repoGraph.addNode(mainBranch, {
42845+
remoteBranches.forEach((remoteBranch) => {
42846+
repoGraph.mergeNode(remoteBranch, {
42847+
type: "branch",
42848+
ref: remoteBranch
42849+
});
42850+
});
42851+
repoGraph.mergeNode(mainBranch, {
4284542852
type: "perennial",
4284642853
ref: mainBranch
4284742854
});
4284842855
perennialBranches.forEach((perennialBranch) => {
42849-
repoGraph.addNode(perennialBranch, {
42856+
repoGraph.mergeNode(perennialBranch, {
4285042857
type: "perennial",
4285142858
ref: perennialBranch
4285242859
});
4285342860
});
4285442861
pullRequests.forEach((pullRequest) => {
42855-
repoGraph.addNode(pullRequest.headRefName, {
42862+
repoGraph.mergeNode(pullRequest.headRefName, {
4285642863
type: "pull-request",
4285742864
...pullRequest
4285842865
});
4285942866
});
4286042867
pullRequests.forEach((pullRequest) => {
42861-
repoGraph.addDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName);
42868+
repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName);
4286242869
});
42863-
const getStackGraph = (pullRequest) => {
42864-
const stackGraph2 = repoGraph.copy();
42865-
stackGraph2.setNodeAttribute(pullRequest.headRefName, "isCurrent", true);
42866-
(0, import_graphology_traversal.bfsFromNode)(
42867-
stackGraph2,
42868-
pullRequest.headRefName,
42869-
(ref, attributes) => {
42870-
stackGraph2.setNodeAttribute(ref, "shouldPrint", true);
42871-
return attributes.type === "perennial";
42872-
},
42873-
{
42874-
mode: "inbound"
42875-
}
42876-
);
42877-
(0, import_graphology_traversal.dfsFromNode)(
42878-
stackGraph2,
42879-
pullRequest.headRefName,
42880-
(ref) => {
42881-
stackGraph2.setNodeAttribute(ref, "shouldPrint", true);
42882-
},
42883-
{ mode: "outbound" }
42884-
);
42885-
return stackGraph2;
42886-
};
4288742870
const getOutput = (graph) => {
4288842871
const lines = [];
4288942872
const terminatingRefs = [mainBranch, ...perennialBranches];
@@ -42911,7 +42894,7 @@ async function main({
4291142894
return lines.join("\n");
4291242895
};
4291342896
const jobs = [];
42914-
const stackGraph = getStackGraph(currentPullRequest);
42897+
const stackGraph = getStackGraph(repoGraph, currentPullRequest);
4291542898
const shouldSkip = () => {
4291642899
const neighbors = stackGraph.neighbors(currentPullRequest.headRefName);
4291742900
const allPerennialBranches = stackGraph.filterNodes(
@@ -42928,7 +42911,7 @@ async function main({
4292842911
}
4292942912
jobs.push(async () => {
4293042913
core.info(`Updating stack details for PR #${stackNode.number}`);
42931-
const stackGraph2 = getStackGraph(stackNode);
42914+
const stackGraph2 = getStackGraph(repoGraph, stackNode);
4293242915
const output = getOutput(stackGraph2);
4293342916
let description = stackNode.body ?? "";
4293442917
description = updateDescription({
@@ -42944,6 +42927,30 @@ async function main({
4294442927
});
4294542928
await Promise.allSettled(jobs.map((job) => job()));
4294642929
}
42930+
function getStackGraph(repoGraph, pullRequest) {
42931+
const stackGraph = repoGraph.copy();
42932+
stackGraph.setNodeAttribute(pullRequest.headRefName, "isCurrent", true);
42933+
(0, import_graphology_traversal.bfsFromNode)(
42934+
stackGraph,
42935+
pullRequest.headRefName,
42936+
(ref, attributes) => {
42937+
stackGraph.setNodeAttribute(ref, "shouldPrint", true);
42938+
return attributes.type === "perennial";
42939+
},
42940+
{
42941+
mode: "inbound"
42942+
}
42943+
);
42944+
(0, import_graphology_traversal.dfsFromNode)(
42945+
stackGraph,
42946+
pullRequest.headRefName,
42947+
(ref) => {
42948+
stackGraph.setNodeAttribute(ref, "shouldPrint", true);
42949+
},
42950+
{ mode: "outbound" }
42951+
);
42952+
return stackGraph;
42953+
}
4294742954
function updateDescription({
4294842955
description,
4294942956
output

src/main.ts

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,42 @@ export async function main({
1010
currentPullRequest,
1111
pullRequests,
1212
mainBranch,
13+
remoteBranches,
1314
perennialBranches,
1415
skipSingleStacks,
1516
}: Context) {
1617
const repoGraph = new MultiDirectedGraph<StackNodeAttributes>()
1718

18-
repoGraph.addNode(mainBranch, {
19+
remoteBranches.forEach((remoteBranch) => {
20+
repoGraph.mergeNode(remoteBranch, {
21+
type: 'branch',
22+
ref: remoteBranch,
23+
})
24+
})
25+
26+
repoGraph.mergeNode(mainBranch, {
1927
type: 'perennial',
2028
ref: mainBranch,
2129
})
2230

2331
perennialBranches.forEach((perennialBranch) => {
24-
repoGraph.addNode(perennialBranch, {
32+
repoGraph.mergeNode(perennialBranch, {
2533
type: 'perennial',
2634
ref: perennialBranch,
2735
})
2836
})
2937

3038
pullRequests.forEach((pullRequest) => {
31-
repoGraph.addNode(pullRequest.headRefName, {
39+
repoGraph.mergeNode(pullRequest.headRefName, {
3240
type: 'pull-request',
3341
...pullRequest,
3442
})
3543
})
3644

3745
pullRequests.forEach((pullRequest) => {
38-
repoGraph.addDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName)
46+
repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName)
3947
})
4048

41-
const getStackGraph = (pullRequest: PullRequest) => {
42-
const stackGraph = repoGraph.copy() as MultiDirectedGraph<StackNodeAttributes>
43-
stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true)
44-
45-
bfsFromNode(
46-
stackGraph,
47-
pullRequest.headRefName,
48-
(ref, attributes) => {
49-
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
50-
return attributes.type === 'perennial'
51-
},
52-
{
53-
mode: 'inbound',
54-
}
55-
)
56-
57-
dfsFromNode(
58-
stackGraph,
59-
pullRequest.headRefName,
60-
(ref) => {
61-
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
62-
},
63-
{ mode: 'outbound' }
64-
)
65-
66-
return stackGraph
67-
}
68-
6949
const getOutput = (graph: MultiDirectedGraph<StackNodeAttributes>) => {
7050
const lines: string[] = []
7151
const terminatingRefs = [mainBranch, ...perennialBranches]
@@ -102,7 +82,7 @@ export async function main({
10282

10383
const jobs: Array<() => Promise<void>> = []
10484

105-
const stackGraph = getStackGraph(currentPullRequest)
85+
const stackGraph = getStackGraph(repoGraph, currentPullRequest)
10686

10787
const shouldSkip = () => {
10888
const neighbors = stackGraph.neighbors(currentPullRequest.headRefName)
@@ -129,7 +109,7 @@ export async function main({
129109
jobs.push(async () => {
130110
core.info(`Updating stack details for PR #${stackNode.number}`)
131111

132-
const stackGraph = getStackGraph(stackNode)
112+
const stackGraph = getStackGraph(repoGraph, stackNode)
133113
const output = getOutput(stackGraph)
134114

135115
let description = stackNode.body ?? ''
@@ -149,6 +129,37 @@ export async function main({
149129
await Promise.allSettled(jobs.map((job) => job()))
150130
}
151131

132+
function getStackGraph(
133+
repoGraph: MultiDirectedGraph<StackNodeAttributes>,
134+
pullRequest: PullRequest
135+
) {
136+
const stackGraph = repoGraph.copy() as MultiDirectedGraph<StackNodeAttributes>
137+
stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true)
138+
139+
bfsFromNode(
140+
stackGraph,
141+
pullRequest.headRefName,
142+
(ref, attributes) => {
143+
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
144+
return attributes.type === 'perennial'
145+
},
146+
{
147+
mode: 'inbound',
148+
}
149+
)
150+
151+
dfsFromNode(
152+
stackGraph,
153+
pullRequest.headRefName,
154+
(ref) => {
155+
stackGraph.setNodeAttribute(ref, 'shouldPrint', true)
156+
},
157+
{ mode: 'outbound' }
158+
)
159+
160+
return stackGraph
161+
}
162+
152163
export function updateDescription({
153164
description,
154165
output,

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ export type Context = {
1717
mainBranch: string
1818
currentPullRequest: PullRequest
1919
pullRequests: PullRequest[]
20+
remoteBranches: string[]
2021
perennialBranches: string[]
2122
skipSingleStacks: boolean
2223
}
2324

2425
export type StackNode =
26+
| {
27+
type: 'branch'
28+
ref: string
29+
}
2530
| {
2631
type: 'perennial'
2732
ref: string

0 commit comments

Comments
 (0)