tangled
alpha
login
or
join now
davidpdrsn.tngl.sh
/
jj-sync-prs
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
2
pipelines
Be smarter about picking base branch
davidpdrsn.tngl.sh
3 months ago
a6a190c8
7b94160f
+24
-7
1 changed file
expand all
collapse all
unified
split
src
main.rs
+24
-7
src/main.rs
···
62
62
async fn run_subcommand(subcommand: Subcommand) -> color_eyre::Result<()> {
63
63
match subcommand {
64
64
Subcommand::Sync { github_token } => {
65
65
+
let branch_at_root_of_stack = branch_at_root_of_stack();
66
66
+
65
67
let graph = tokio::task::spawn_blocking(|| {
66
66
-
build_branch_graph().context("failed to build graph")
68
68
+
build_branch_graph(branch_at_root_of_stack).context("failed to build graph")
67
69
});
68
70
69
71
let repo_info = repo_info().context("failed to find repo info")?;
···
86
88
87
89
let graph = graph.await??;
88
90
89
89
-
for stack_root in graph.iter_edges_from("main") {
91
91
+
for stack_root in graph.iter_edges_from(branch_at_root_of_stack) {
90
92
find_or_create_prs(
91
91
-
stack_root, "main", &graph, &repo_info, &octocrab, &mut pulls,
93
93
+
stack_root,
94
94
+
branch_at_root_of_stack,
95
95
+
&graph,
96
96
+
&repo_info,
97
97
+
&octocrab,
98
98
+
&mut pulls,
92
99
)
93
100
.await
94
101
.context("failed to sync prs")?;
···
96
103
97
104
let (tx, mut rx) = tokio::sync::mpsc::channel::<()>(1024);
98
105
99
99
-
for stack_root in graph.iter_edges_from("main") {
106
106
+
for stack_root in graph.iter_edges_from(branch_at_root_of_stack) {
100
107
let mut comment_lines = Vec::new();
101
108
write_pr_comment(&graph, stack_root, 0, &mut comment_lines);
102
109
···
119
126
while rx.recv().await.is_some() {}
120
127
}
121
128
Subcommand::Graph { out } => {
122
122
-
let graph = build_branch_graph().context("failed to build graph")?;
129
129
+
let branch_at_root_of_stack = branch_at_root_of_stack();
130
130
+
let graph =
131
131
+
build_branch_graph(branch_at_root_of_stack).context("failed to build graph")?;
123
132
let dot = graph.to_dot();
124
133
let (read, mut write) = std::io::pipe()?;
125
134
let out = out.as_deref().unwrap_or_else(|| Path::new("branches.png"));
···
139
148
Ok(())
140
149
}
141
150
142
142
-
fn build_branch_graph() -> color_eyre::Result<Graph> {
151
151
+
fn build_branch_graph(branch_at_root_of_stack: &str) -> color_eyre::Result<Graph> {
143
152
fn go(graph: &mut Graph, change: &str, parent_branch: &str) -> color_eyre::Result<()> {
144
153
let output = command(
145
154
"jj",
···
181
190
let mut output = output.lines();
182
191
let common_ancestor = output.next_back().context("no lines")?;
183
192
184
184
-
go(&mut graph, common_ancestor, "main")?;
193
193
+
go(&mut graph, common_ancestor, branch_at_root_of_stack)?;
185
194
186
195
Ok(graph)
187
196
}
···
212
221
owner: output.owner.login,
213
222
name: output.name,
214
223
})
224
224
+
}
225
225
+
226
226
+
fn branch_at_root_of_stack() -> &'static str {
227
227
+
if command("jj", ["show", "dev"]).is_ok() {
228
228
+
"dev"
229
229
+
} else {
230
230
+
"main"
231
231
+
}
215
232
}
216
233
217
234
fn command<I>(command: &str, args: I) -> color_eyre::Result<String>