@@ -8,8 +8,13 @@ use xshell::{cmd, Shell};
88impl flags:: PublishReleaseNotes {
99 pub ( crate ) fn run ( self , sh : & Shell ) -> Result < ( ) > {
1010 let asciidoc = sh. read_file ( & self . changelog ) ?;
11- let markdown = notes:: convert_asciidoc_to_markdown ( std:: io:: Cursor :: new ( & asciidoc) ) ?;
12- let tag_name = extract_tag_name ( & self . changelog ) ?;
11+ let mut markdown = notes:: convert_asciidoc_to_markdown ( std:: io:: Cursor :: new ( & asciidoc) ) ?;
12+ let file_name = check_file_name ( self . changelog ) ?;
13+ let tag_name = & file_name[ 0 ..10 ] ;
14+ let original_changelog_url = create_original_changelog_url ( & file_name) ;
15+ let additional_paragraph =
16+ format ! ( "\n See also [original changelog]({original_changelog_url})." ) ;
17+ markdown. push_str ( & additional_paragraph) ;
1318 if self . dry_run {
1419 println ! ( "{}" , markdown) ;
1520 } else {
@@ -19,7 +24,7 @@ impl flags::PublishReleaseNotes {
1924 }
2025}
2126
22- fn extract_tag_name < P : AsRef < std:: path:: Path > > ( path : P ) -> Result < String > {
27+ fn check_file_name < P : AsRef < std:: path:: Path > > ( path : P ) -> Result < String > {
2328 let file_name = path
2429 . as_ref ( )
2530 . file_name ( )
@@ -39,12 +44,23 @@ fn extract_tag_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> {
3944 && chars. next ( ) . unwrap ( ) . is_ascii_digit ( )
4045 && chars. next ( ) . unwrap ( ) . is_ascii_digit ( )
4146 {
42- Ok ( file_name[ 0 .. 10 ] . to_owned ( ) )
47+ Ok ( file_name. to_string ( ) )
4348 } else {
44- bail ! ( "extraction of date from the file name failed " )
49+ bail ! ( "unexpected file name format; no date information prefixed " )
4550 }
4651}
4752
53+ fn create_original_changelog_url ( file_name : & str ) -> String {
54+ let year = & file_name[ 0 ..4 ] ;
55+ let month = & file_name[ 5 ..7 ] ;
56+ let day = & file_name[ 8 ..10 ] ;
57+ let mut stem = & file_name[ 11 ..] ;
58+ if let Some ( stripped) = stem. strip_suffix ( ".adoc" ) {
59+ stem = stripped;
60+ }
61+ format ! ( "https://rust-analyzer.github.io/thisweek/{year}/{month}/{day}/{stem}.html" )
62+ }
63+
4864fn update_release ( sh : & Shell , tag_name : & str , release_notes : & str ) -> Result < ( ) > {
4965 let token = match env:: var ( "GITHUB_TOKEN" ) {
5066 Ok ( token) => token,
@@ -78,3 +94,16 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()>
7894
7995 Ok ( ( ) )
8096}
97+
98+ #[ cfg( test) ]
99+ mod tests {
100+ use super :: * ;
101+
102+ #[ test]
103+ fn original_changelog_url_creation ( ) {
104+ let input = "2019-07-24-changelog-0.adoc" ;
105+ let actual = create_original_changelog_url ( & input) ;
106+ let expected = "https://rust-analyzer.github.io/thisweek/2019/07/24/changelog-0.html" ;
107+ assert_eq ! ( actual, expected) ;
108+ }
109+ }
0 commit comments