about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoritada Kobayashi <noritada.kobayashi@gmail.com>2022-12-14 14:14:55 +0900
committerNoritada Kobayashi <noritada.kobayashi@gmail.com>2022-12-14 14:14:55 +0900
commitc78d759ab3f201e29f5fcd9ec06e05744e4f6dd4 (patch)
treef91217e1c524216f1de73cca41c1791d48d863f3
parentfd5be91d944f07b8eae8729a20d69d086bd12a94 (diff)
downloadrust-c78d759ab3f201e29f5fcd9ec06e05744e4f6dd4.tar.gz
rust-c78d759ab3f201e29f5fcd9ec06e05744e4f6dd4.zip
Add a link to the original changelog from release notes on GitHub Releases
-rw-r--r--xtask/src/publish.rs39
1 files changed, 34 insertions, 5 deletions
diff --git a/xtask/src/publish.rs b/xtask/src/publish.rs
index 2decd85c18a..c8249929bdc 100644
--- a/xtask/src/publish.rs
+++ b/xtask/src/publish.rs
@@ -8,8 +8,13 @@ use xshell::{cmd, Shell};
 impl flags::PublishReleaseNotes {
     pub(crate) fn run(self, sh: &Shell) -> Result<()> {
         let asciidoc = sh.read_file(&self.changelog)?;
-        let markdown = notes::convert_asciidoc_to_markdown(std::io::Cursor::new(&asciidoc))?;
-        let tag_name = extract_tag_name(&self.changelog)?;
+        let mut markdown = notes::convert_asciidoc_to_markdown(std::io::Cursor::new(&asciidoc))?;
+        let file_name = check_file_name(self.changelog)?;
+        let tag_name = &file_name[0..10];
+        let original_changelog_url = create_original_changelog_url(&file_name);
+        let additional_paragraph =
+            format!("\nSee also [original changelog]({original_changelog_url}).");
+        markdown.push_str(&additional_paragraph);
         if self.dry_run {
             println!("{}", markdown);
         } else {
@@ -19,7 +24,7 @@ impl flags::PublishReleaseNotes {
     }
 }
 
-fn extract_tag_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> {
+fn check_file_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> {
     let file_name = path
         .as_ref()
         .file_name()
@@ -39,12 +44,23 @@ fn extract_tag_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> {
         && chars.next().unwrap().is_ascii_digit()
         && chars.next().unwrap().is_ascii_digit()
     {
-        Ok(file_name[0..10].to_owned())
+        Ok(file_name.to_string())
     } else {
-        bail!("extraction of date from the file name failed")
+        bail!("unexpected file name format; no date information prefixed")
     }
 }
 
+fn create_original_changelog_url(file_name: &str) -> String {
+    let year = &file_name[0..4];
+    let month = &file_name[5..7];
+    let day = &file_name[8..10];
+    let mut stem = &file_name[11..];
+    if let Some(stripped) = stem.strip_suffix(".adoc") {
+        stem = stripped;
+    }
+    format!("https://rust-analyzer.github.io/thisweek/{year}/{month}/{day}/{stem}.html")
+}
+
 fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()> {
     let token = match env::var("GITHUB_TOKEN") {
         Ok(token) => token,
@@ -78,3 +94,16 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()>
 
     Ok(())
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn original_changelog_url_creation() {
+        let input = "2019-07-24-changelog-0.adoc";
+        let actual = create_original_changelog_url(&input);
+        let expected = "https://rust-analyzer.github.io/thisweek/2019/07/24/changelog-0.html";
+        assert_eq!(actual, expected);
+    }
+}