diff options
| author | Trevor Gross <tmgross@umich.edu> | 2025-06-14 08:44:37 +0000 |
|---|---|---|
| committer | Trevor Gross <t.gross35@gmail.com> | 2025-06-30 09:01:21 -0500 |
| commit | a4d584e7a6d2bb4ce08b72faec0c35206dd6e4b7 (patch) | |
| tree | 7fa4f607ca7246961947a39149a75b59330b4ee3 /library/compiler-builtins/crates | |
| parent | 76b9fbf5b2641c77c1d6ae8b3d86ce087c99ab9e (diff) | |
| download | rust-a4d584e7a6d2bb4ce08b72faec0c35206dd6e4b7.tar.gz rust-a4d584e7a6d2bb4ce08b72faec0c35206dd6e4b7.zip | |
josh-sync: Replace `#xxxx`-style links in messages
Often our short summaries will pick up a Bors "Auto merge of #xxxx ...` commit message. Replace these with something like `rust-lang/rust#1234` to avoid broken links when going between repositories.
Diffstat (limited to 'library/compiler-builtins/crates')
| -rw-r--r-- | library/compiler-builtins/crates/josh-sync/Cargo.toml | 1 | ||||
| -rw-r--r-- | library/compiler-builtins/crates/josh-sync/src/sync.rs | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/library/compiler-builtins/crates/josh-sync/Cargo.toml b/library/compiler-builtins/crates/josh-sync/Cargo.toml index 1f3bb376d6d..8e2e891db54 100644 --- a/library/compiler-builtins/crates/josh-sync/Cargo.toml +++ b/library/compiler-builtins/crates/josh-sync/Cargo.toml @@ -5,3 +5,4 @@ publish = false [dependencies] directories = "6.0.0" +regex-lite = "0.1.6" diff --git a/library/compiler-builtins/crates/josh-sync/src/sync.rs b/library/compiler-builtins/crates/josh-sync/src/sync.rs index 003cf187d83..2d89d2d1cea 100644 --- a/library/compiler-builtins/crates/josh-sync/src/sync.rs +++ b/library/compiler-builtins/crates/josh-sync/src/sync.rs @@ -1,8 +1,11 @@ +use std::borrow::Cow; use std::net::{SocketAddr, TcpStream}; use std::process::{Command, Stdio, exit}; use std::time::Duration; use std::{env, fs, process, thread}; +use regex_lite::Regex; + const JOSH_PORT: u16 = 42042; const DEFAULT_PR_BRANCH: &str = "update-builtins"; @@ -77,6 +80,7 @@ impl GitSync { "--depth=1", ]); let new_summary = check_output(["git", "log", "-1", "--format=%h %s", &new_upstream_base]); + let new_summary = replace_references(&new_summary, &self.upstream_repo); // Update rust-version file. As a separate commit, since making it part of // 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) -> String::from_utf8(out.stdout.trim_ascii().to_vec()).expect("non-UTF8 output") } +/// Replace `#1234`-style issue/PR references with `repo#1234` to ensure links work across +/// repositories. +fn replace_references<'a>(s: &'a str, repo: &str) -> Cow<'a, str> { + let re = Regex::new(r"\B(?P<id>#\d+)\b").unwrap(); + re.replace(s, &format!("{repo}$id")) +} + /// Create a wrapper that stops Josh on drop. pub struct Josh(process::Child); @@ -369,3 +380,22 @@ impl Drop for Josh { self.0.kill().expect("failed to SIGKILL josh-proxy"); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_replace() { + assert_eq!(replace_references("#1234", "r-l/rust"), "r-l/rust#1234"); + assert_eq!(replace_references("#1234x", "r-l/rust"), "#1234x"); + assert_eq!( + replace_references("merge #1234", "r-l/rust"), + "merge r-l/rust#1234" + ); + assert_eq!( + replace_references("foo/bar#1234", "r-l/rust"), + "foo/bar#1234" + ); + } +} |
