@@ -10,6 +10,9 @@ use std::sync::Arc;
10
10
use uuid:: Uuid ;
11
11
12
12
pub const ANSI_UP_URL : & str =
"/gha_logs/[email protected] " ;
13
+ pub const SUCCESS_URL : & str =
"/gha_logs/[email protected] " ;
14
+ pub const FAILURE_URL : & str =
"/gha_logs/[email protected] " ;
15
+
13
16
const MAX_CACHE_CAPACITY_BYTES : u64 = 50 * 1024 * 1024 ; // 50 Mb
14
17
15
18
#[ derive( Default ) ]
@@ -177,16 +180,30 @@ async fn process_logs(
177
180
} ;
178
181
179
182
let nonce = Uuid :: new_v4 ( ) . to_hyphenated ( ) . to_string ( ) ;
183
+ let job_name = & * job. name ;
180
184
let sha = & * job. head_sha ;
185
+ let short_sha = & job. head_sha [ ..7 ] ;
186
+
187
+ let icon_status = match job. conclusion {
188
+ Some ( github:: JobConclusion :: Failure | github:: JobConclusion :: TimedOut ) => {
189
+ format ! ( r#"<link rel="icon" sizes="any" type="image/svg+xml" href="{FAILURE_URL}">"# )
190
+ }
191
+ Some ( github:: JobConclusion :: Success ) => {
192
+ format ! ( r#"<link rel="icon" sizes="any" type="image/svg+xml" href="{SUCCESS_URL}">"# )
193
+ }
194
+ _ => {
195
+ r#"<link rel="icon" sizes="32x32" type="image/png" href="https://www.rust-lang.org/static/images/favicon-32x32.png">"# . to_string ( )
196
+ }
197
+ } ;
181
198
182
199
let html = format ! (
183
200
r###"<!DOCTYPE html>
184
201
<html lang="en" translate="no">
185
202
<head>
186
203
<meta charset="UTF-8">
187
204
<meta name="viewport" content="width=device-width, initial-scale=1.0">
188
- <title>{log_id } - {owner}/{repo}</title>
189
- <link rel="icon" sizes="32x32" type="image/png" href="https://www.rust-lang.org/static/images/favicon-32x32.png">
205
+ <title>{job_name } - {owner}/{repo}@{short_sha }</title>
206
+ {icon_status}
190
207
<style>
191
208
body {{
192
209
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
@@ -290,7 +307,7 @@ async fn process_logs(
290
307
. header (
291
308
CONTENT_SECURITY_POLICY ,
292
309
format ! (
293
- "default-src 'none'; script-src 'nonce-{nonce}' 'self'; style-src 'unsafe-inline'; img-src www.rust-lang.org"
310
+ "default-src 'none'; script-src 'nonce-{nonce}' 'self'; style-src 'unsafe-inline'; img-src 'self' www.rust-lang.org"
294
311
) ,
295
312
)
296
313
. body ( Body :: from ( html) ) ?) ;
@@ -306,3 +323,25 @@ pub fn ansi_up_min_js() -> anyhow::Result<Response<Body>, hyper::Error> {
306
323
. body ( Body :: from ( ANSI_UP_MIN_JS ) )
307
324
. unwrap ( ) )
308
325
}
326
+
327
+ pub fn success_svg ( ) -> anyhow:: Result < Response < Body > , hyper:: Error > {
328
+ const SUCCESS_SVG : & str = include_str ! ( "gha_logs/success.svg" ) ;
329
+
330
+ Ok ( Response :: builder ( )
331
+ . status ( StatusCode :: OK )
332
+ . header ( CACHE_CONTROL , "public, max-age=15552000, immutable" )
333
+ . header ( CONTENT_TYPE , "image/svg+xml; charset=utf-8" )
334
+ . body ( Body :: from ( SUCCESS_SVG ) )
335
+ . unwrap ( ) )
336
+ }
337
+
338
+ pub fn failure_svg ( ) -> anyhow:: Result < Response < Body > , hyper:: Error > {
339
+ const FAILURE_SVG : & str = include_str ! ( "gha_logs/failure.svg" ) ;
340
+
341
+ Ok ( Response :: builder ( )
342
+ . status ( StatusCode :: OK )
343
+ . header ( CACHE_CONTROL , "public, max-age=15552000, immutable" )
344
+ . header ( CONTENT_TYPE , "image/svg+xml; charset=utf-8" )
345
+ . body ( Body :: from ( FAILURE_SVG ) )
346
+ . unwrap ( ) )
347
+ }
0 commit comments