@@ -4,6 +4,7 @@ use std::process::Command;
44use std:: { env, fs} ;
55
66use anyhow:: { Context , Result , bail} ;
7+ use regex:: Regex ;
78use serde_json:: json;
89
910fn parse_tag ( tag : & str ) -> Result < ( & str , & str ) > {
@@ -72,6 +73,15 @@ fn extract_section(content: &str, package: &str, version: &str) -> Result<String
7273 Ok ( trimmed. to_string ( ) )
7374}
7475
76+ fn changelog_to_release_notes ( body : & str ) -> String {
77+ let author_re = Regex :: new ( r"\[@[^\]]*\]\(https://github\.com/([^)]+)\)" ) . unwrap ( ) ;
78+ let issue_re = Regex :: new ( r"\[(#\d+)\]\([^)]+\)" ) . unwrap ( ) ;
79+
80+ let result = author_re. replace_all ( body, "@$1" ) ;
81+ let result = issue_re. replace_all ( & result, "$1" ) ;
82+ result. into_owned ( )
83+ }
84+
7585fn find_latest_tag ( package : & str ) -> Result < String > {
7686 let output = Command :: new ( "git" )
7787 . args ( [
@@ -171,7 +181,7 @@ fn main() -> Result<()> {
171181 json ! ( {
172182 "tag" : r. tag,
173183 "name" : format!( "{} v{}" , r. package, r. version) ,
174- "body" : r. body,
184+ "body" : changelog_to_release_notes ( & r. body) ,
175185 } )
176186 } )
177187 . collect ( ) ;
@@ -302,6 +312,42 @@ mod tests {
302312 assert ! ( extract_section( content, "yew" , "0.23.0" ) . is_err( ) ) ;
303313 }
304314
315+ #[ test]
316+ fn test_changelog_to_release_notes_single_contributor ( ) {
317+ let input = "### 🛠 Fixes\n \n - No more broken child re-renders while setting parents' \
318+ states. [[@Siyuan Yan](https://github.com/Madoshakalaka), \
319+ [#4060](https://github.com/yewstack/yew/pull/4060)]";
320+ let expected = "### 🛠 Fixes\n \n - No more broken child re-renders while setting parents' \
321+ states. [@Madoshakalaka, #4060]";
322+ assert_eq ! ( changelog_to_release_notes( input) , expected) ;
323+ }
324+
325+ #[ test]
326+ fn test_changelog_to_release_notes_multiple_contributors ( ) {
327+ let input = "- Better ImplicitClone ergonomics. [[@Cecile \
328+ Tonglet](https://github.com/cecton), \
329+ [#3508](https://github.com/yewstack/yew/pull/3508), \
330+ [#3431](https://github.com/yewstack/yew/pull/3431)] [[@Siyuan \
331+ Yan](https://github.com/Madoshakalaka), \
332+ [#3892](https://github.com/yewstack/yew/pull/3878)]";
333+ let expected =
334+ "- Better ImplicitClone ergonomics. [@cecton, #3508, #3431] [@Madoshakalaka, #3892]" ;
335+ assert_eq ! ( changelog_to_release_notes( input) , expected) ;
336+ }
337+
338+ #[ test]
339+ fn test_changelog_to_release_notes_preserves_non_link_text ( ) {
340+ let input = "NOTE: See [the migration guide](https://yew.rs/docs/next/migration-guides) \
341+ for details.";
342+ assert_eq ! ( changelog_to_release_notes( input) , input) ;
343+ }
344+
345+ #[ test]
346+ fn test_changelog_to_release_notes_no_links ( ) {
347+ let input = "- Updated rust dependencies." ;
348+ assert_eq ! ( changelog_to_release_notes( input) , input) ;
349+ }
350+
305351 #[ test]
306352 fn test_yew_has_more_code_than_yew_agent ( ) {
307353 let workspace_root = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
0 commit comments