@@ -51,12 +51,16 @@ fn print_warnings(title: &str, warnings: &[LintJson]) {
51
51
return ;
52
52
}
53
53
54
- println ! ( "### {title}" ) ;
54
+ //We have to use HTML here to be able to manually add an id.
55
+ println ! ( r#"<h3 id="{title}">{title}</h3>"# ) ;
56
+ println ! ( ) ;
55
57
for warning in warnings {
56
58
println ! ( "{title} `{}` at {}" , warning. lint, warning. file_link) ;
59
+ println ! ( ) ;
57
60
println ! ( "```" ) ;
58
61
print ! ( "{}" , warning. rendered) ;
59
62
println ! ( "```" ) ;
63
+ println ! ( ) ;
60
64
}
61
65
}
62
66
@@ -65,9 +69,12 @@ fn print_changed_diff(changed: &[(LintJson, LintJson)]) {
65
69
return ;
66
70
}
67
71
68
- println ! ( "### Changed" ) ;
72
+ //We have to use HTML here to be able to manually add an id.
73
+ println ! ( r#"<h3 id="changed">Changed</h3>"# ) ;
74
+ println ! ( ) ;
69
75
for ( old, new) in changed {
70
76
println ! ( "Changed `{}` at {}" , new. lint, new. file_link) ;
77
+ println ! ( ) ;
71
78
println ! ( "```diff" ) ;
72
79
for change in diff:: lines ( & old. rendered , & new. rendered ) {
73
80
use diff:: Result :: { Both , Left , Right } ;
@@ -109,13 +116,30 @@ pub(crate) fn diff(old_path: &Path, new_path: &Path) {
109
116
}
110
117
111
118
print ! (
112
- "{} added , {} removed , {} changed \n \n " ,
113
- added. len( ) ,
114
- removed. len( ) ,
115
- changed. len( )
119
+ r## "{}, {}, {}"## ,
120
+ count_string ( " added" , added . len( ) ) ,
121
+ count_string ( " removed" , removed . len( ) ) ,
122
+ count_string ( " changed" , changed . len( ) ) ,
116
123
) ;
124
+ println ! ( ) ;
125
+ println ! ( ) ;
117
126
118
127
print_warnings ( "Added" , & added) ;
119
128
print_warnings ( "Removed" , & removed) ;
120
129
print_changed_diff ( & changed) ;
121
130
}
131
+
132
+ /// This generates the `x added` string for the start of the job summery.
133
+ /// It linkifies them if possible to jump to the respective heading.
134
+ fn count_string ( label : & str , count : usize ) -> String {
135
+ // Headlines are only added, if anything will be displayed under the headline.
136
+ // We therefore only want to add links to them if they exist
137
+ if count == 0 {
138
+ format ! ( "0 {label}" )
139
+ } else {
140
+ // GitHub's job summaries don't add HTML ids to headings. That's why we
141
+ // manually have to add them. GitHub prefixes these manual ids with
142
+ // `user-content-` and that's how we end up with these awesome links :D
143
+ format ! ( "[{count} {label}](#user-content-{label})" )
144
+ }
145
+ }
0 commit comments