@@ -8,8 +8,13 @@ use xshell::{cmd, Shell};
8
8
impl flags:: PublishReleaseNotes {
9
9
pub ( crate ) fn run ( self , sh : & Shell ) -> Result < ( ) > {
10
10
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) ;
13
18
if self . dry_run {
14
19
println ! ( "{}" , markdown) ;
15
20
} else {
@@ -19,7 +24,7 @@ impl flags::PublishReleaseNotes {
19
24
}
20
25
}
21
26
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 > {
23
28
let file_name = path
24
29
. as_ref ( )
25
30
. file_name ( )
@@ -39,12 +44,23 @@ fn extract_tag_name<P: AsRef<std::path::Path>>(path: P) -> Result<String> {
39
44
&& chars. next ( ) . unwrap ( ) . is_ascii_digit ( )
40
45
&& chars. next ( ) . unwrap ( ) . is_ascii_digit ( )
41
46
{
42
- Ok ( file_name[ 0 .. 10 ] . to_owned ( ) )
47
+ Ok ( file_name. to_string ( ) )
43
48
} else {
44
- bail ! ( "extraction of date from the file name failed " )
49
+ bail ! ( "unexpected file name format; no date information prefixed " )
45
50
}
46
51
}
47
52
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
+
48
64
fn update_release ( sh : & Shell , tag_name : & str , release_notes : & str ) -> Result < ( ) > {
49
65
let token = match env:: var ( "GITHUB_TOKEN" ) {
50
66
Ok ( token) => token,
@@ -78,3 +94,16 @@ fn update_release(sh: &Shell, tag_name: &str, release_notes: &str) -> Result<()>
78
94
79
95
Ok ( ( ) )
80
96
}
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