Skip to content

Commit e5ede82

Browse files
authored
Merge pull request #7 from rust-lang/push-message
Improve commit message of pushes
2 parents 8d36d35 + 8838577 commit e5ede82

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

Cargo.lock

Lines changed: 7 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
@@ -13,6 +13,7 @@ clap = { version = "4", features = ["derive"] }
1313
directories = "6"
1414
toml = "0.8"
1515
serde = { version = "1", features = ["derive"] }
16+
urlencoding = "2"
1617
which = "8"
1718

1819
[profile.release]

src/bin/rustc_josh_sync.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_josh_sync::SyncContext;
44
use rustc_josh_sync::config::{JoshConfig, load_config};
55
use rustc_josh_sync::josh::{JoshProxy, try_install_josh};
66
use rustc_josh_sync::sync::{GitSync, RustcPullError, UPSTREAM_REPO};
7-
use rustc_josh_sync::utils::prompt;
7+
use rustc_josh_sync::utils::{get_current_head_sha, prompt};
88
use std::path::{Path, PathBuf};
99

1010
const DEFAULT_CONFIG_PATH: &str = "josh-sync.toml";
@@ -109,10 +109,24 @@ fn main() -> anyhow::Result<()> {
109109
.context("cannot perform push")?;
110110

111111
// Open PR with `subtree update` title to silence the `no-merges` triagebot check
112+
let title = format!("{} subtree update", ctx.config.repo);
113+
let head = get_current_head_sha()?;
114+
115+
let merge_msg = format!(
116+
r#"Subtree update of `{repo}` to https://github.com/{full_repo}/commit/{head}.
117+
118+
Created using https://github.com/rust-lang/josh-sync.
119+
120+
r? @ghost"#,
121+
repo = ctx.config.repo,
122+
full_repo = ctx.config.full_repo_name(),
123+
);
124+
112125
println!(
113126
r#"You can create the rustc PR using the following URL:
114-
https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}+subtree+update&body=r?+@ghost"#,
115-
ctx.config.repo
127+
https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#,
128+
urlencoding::encode(&title),
129+
urlencoding::encode(&merge_msg)
116130
);
117131
}
118132
}

src/sync.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::SyncContext;
22
use crate::josh::JoshProxy;
3-
use crate::utils::run_command_at;
43
use crate::utils::{ensure_clean_git_state, prompt};
4+
use crate::utils::{get_current_head_sha, run_command_at};
55
use crate::utils::{run_command, stream_command};
66
use anyhow::{Context, Error};
77
use std::path::{Path, PathBuf};
@@ -64,7 +64,7 @@ impl GitSync {
6464
&self.context.config.construct_josh_filter(),
6565
);
6666

67-
let orig_head = run_command(["git", "rev-parse", "HEAD"])?;
67+
let orig_head = get_current_head_sha()?;
6868
println!(
6969
"previous upstream base: {:?}",
7070
self.context.last_upstream_sha
@@ -137,8 +137,7 @@ This updates the rust-version file to {upstream_sha}."#,
137137
};
138138
let num_roots_before = num_roots()?;
139139

140-
let sha =
141-
run_command(&["git", "rev-parse", "HEAD"]).context("failed to get current commit")?;
140+
let sha = get_current_head_sha()?;
142141

143142
// The filtered SHA of upstream
144143
let incoming_ref = run_command(["git", "rev-parse", "FETCH_HEAD"])?;
@@ -170,8 +169,7 @@ This merge was created using https://github.com/rust-lang/josh-sync.
170169
])
171170
.context("FAILED to merge new commits, something went wrong")?;
172171

173-
let current_sha =
174-
run_command(&["git", "rev-parse", "HEAD"]).context("FAILED to get current commit")?;
172+
let current_sha = get_current_head_sha()?;
175173
if current_sha == sha {
176174
eprintln!(
177175
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
@@ -261,7 +259,7 @@ This merge was created using https://github.com/rust-lang/josh-sync.
261259
&["git", "fetch", &josh_url, &branch],
262260
&std::env::current_dir().unwrap(),
263261
)?;
264-
let head = run_command(&["git", "rev-parse", "HEAD"])?;
262+
let head = get_current_head_sha()?;
265263
let fetch_head = run_command(&["git", "rev-parse", "FETCH_HEAD"])?;
266264
if head != fetch_head {
267265
return Err(anyhow::anyhow!(

src/utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use std::path::Path;
23
use std::process::Command;
34

@@ -67,6 +68,10 @@ pub fn ensure_clean_git_state() {
6768
assert!(read.is_empty(), "working directory must be clean");
6869
}
6970

71+
pub fn get_current_head_sha() -> anyhow::Result<String> {
72+
run_command(&["git", "rev-parse", "HEAD"]).context("failed to get current commit")
73+
}
74+
7075
/// Ask a prompt to user and return true if they responded with `y`.
7176
/// Returns `default_response` on CI.
7277
pub fn prompt(prompt: &str, default_response: bool) -> bool {

0 commit comments

Comments
 (0)