|
| 1 | +use std::borrow::Cow; |
1 | 2 | use std::net::{SocketAddr, TcpStream};
|
2 | 3 | use std::process::{Command, Stdio, exit};
|
3 | 4 | use std::time::Duration;
|
4 | 5 | use std::{env, fs, process, thread};
|
5 | 6 |
|
| 7 | +use regex_lite::Regex; |
| 8 | + |
6 | 9 | const JOSH_PORT: u16 = 42042;
|
7 | 10 | const DEFAULT_PR_BRANCH: &str = "update-builtins";
|
8 | 11 |
|
@@ -77,6 +80,7 @@ impl GitSync {
|
77 | 80 | "--depth=1",
|
78 | 81 | ]);
|
79 | 82 | let new_summary = check_output(["git", "log", "-1", "--format=%h %s", &new_upstream_base]);
|
| 83 | + let new_summary = replace_references(&new_summary, &self.upstream_repo); |
80 | 84 |
|
81 | 85 | // Update rust-version file. As a separate commit, since making it part of
|
82 | 86 | // the merge has confused the heck out of josh in the past.
|
@@ -297,6 +301,13 @@ fn check_output_cfg(prog: &str, f: impl FnOnce(&mut Command) -> &mut Command) ->
|
297 | 301 | String::from_utf8(out.stdout.trim_ascii().to_vec()).expect("non-UTF8 output")
|
298 | 302 | }
|
299 | 303 |
|
| 304 | +/// Replace `#1234`-style issue/PR references with `prefix#1234` to ensure links work across |
| 305 | +/// repositories. |
| 306 | +fn replace_references<'a>(s: &'a str, repo: &str) -> Cow<'a, str> { |
| 307 | + let re = Regex::new(r"\B(?P<id>#\d+)\b").unwrap(); |
| 308 | + re.replace(s, &format!("{repo}$id")) |
| 309 | +} |
| 310 | + |
300 | 311 | /// Create a wrapper that stops Josh on drop.
|
301 | 312 | pub struct Josh(process::Child);
|
302 | 313 |
|
@@ -369,3 +380,22 @@ impl Drop for Josh {
|
369 | 380 | self.0.kill().expect("failed to SIGKILL josh-proxy");
|
370 | 381 | }
|
371 | 382 | }
|
| 383 | + |
| 384 | +#[cfg(test)] |
| 385 | +mod tests { |
| 386 | + use super::*; |
| 387 | + |
| 388 | + #[test] |
| 389 | + fn test_replace() { |
| 390 | + assert_eq!(replace_references("#1234", "r-l/rust"), "r-l/rust#1234"); |
| 391 | + assert_eq!(replace_references("#1234x", "r-l/rust"), "#1234x"); |
| 392 | + assert_eq!( |
| 393 | + replace_references("merge #1234", "r-l/rust"), |
| 394 | + "merge r-l/rust#1234" |
| 395 | + ); |
| 396 | + assert_eq!( |
| 397 | + replace_references("foo/bar#1234", "r-l/rust"), |
| 398 | + "foo/bar#1234" |
| 399 | + ); |
| 400 | + } |
| 401 | +} |
0 commit comments