Skip to content

Commit 753fb9a

Browse files
committed
Add upstream HEAD commit summary to preparation message
1 parent 387b873 commit 753fb9a

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ directories = "6"
1414
toml = "0.8"
1515
serde = { version = "1", features = ["derive"] }
1616
which = "8"
17+
regex = "1"
1718

1819
[profile.release]
1920
debug = "line-tables-only"

src/sync.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::SyncContext;
22
use crate::josh::JoshProxy;
3-
use crate::utils::{StderrMode, ensure_clean_git_state, run_command, run_command_at};
3+
use crate::utils::{
4+
StderrMode, ensure_clean_git_state, replace_references, run_command, run_command_at,
5+
};
46
use anyhow::{Context, Error};
57
use std::path::{Path, PathBuf};
68

@@ -91,9 +93,23 @@ impl GitSync {
9193
)
9294
})?;
9395

96+
// Fetch the latest upstream HEAD so we can get a summary. Use the Josh URL for caching.
97+
run_command([
98+
"git",
99+
"fetch",
100+
&josh.git_url(UPSTREAM_REPO, Some(&upstream_sha), ":/"),
101+
&upstream_sha,
102+
"--depth=1",
103+
])?;
104+
let summary = run_command(["git", "log", "-1", "--format=%h %s", "FETCH_HEAD"])?;
105+
let summary = replace_references(&summary, UPSTREAM_REPO);
106+
94107
let prep_message = format!(
95-
r#"Update the upstream Rust SHA to {upstream_sha}.
96-
To prepare for merging from {UPSTREAM_REPO}."#,
108+
r#"Update the upstream Rust version to `{upstream_sha}`.
109+
110+
To prepare for merging from {UPSTREAM_REPO}, the rust-version file was set to the following commit:
111+
112+
{summary}"#,
97113
);
98114

99115
let config_path = self

src/utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use regex::Regex;
2+
use std::borrow::Cow;
13
use std::path::Path;
24
use std::process::{Command, Stdio};
35

@@ -63,3 +65,10 @@ pub fn read_line() -> String {
6365
.expect("cannot read line from stdin");
6466
line.trim().to_string()
6567
}
68+
69+
/// Replace `#1234`-style issue/PR references with `repo#1234` to ensure links work across
70+
/// repositories.
71+
pub fn replace_references<'a>(text: &'a str, repo: &str) -> Cow<'a, str> {
72+
let regex = Regex::new(r"\B(?P<id>#\d+)\b").unwrap();
73+
regex.replace(text, &format!("{repo}$id"))
74+
}

0 commit comments

Comments
 (0)