Skip to content

Commit e55e881

Browse files
authored
Merge pull request #2096 from Urgau/gha-logs-last-error-scroll
Automatically scroll to the latest error in our GHA logs viewer
2 parents 6c91314 + 251c6db commit e55e881

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/gha_logs.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn process_logs(
129129
let nonce = Uuid::new_v4().to_hyphenated().to_string();
130130

131131
let html = format!(
132-
r##"<!DOCTYPE html>
132+
r###"<!DOCTYPE html>
133133
<html>
134134
<head>
135135
<title>{log_uuid} - triagebot</title>
@@ -171,13 +171,28 @@ async fn process_logs(
171171
`<a id="${{ts}}" href="#${{ts}}" class="timestamp">${{ts}}</a>`
172172
);
173173
174+
// 4. Add a anchor around every "##[error]" string
175+
let errorCounter = -1;
176+
html = html.replace(/##\[error\]/g, () =>
177+
`<a id="error-${{++errorCounter}}">##[error]</a>`
178+
);
179+
180+
// 5. Add the html to the DOM
174181
var cdiv = document.getElementById("console");
175182
cdiv.innerHTML = html;
183+
184+
// 6. If no anchor is given, scroll to the last error
185+
if (location.hash === "" && errorCounter >= 0) {{
186+
document.getElementById(`error-${{errorCounter}}`).scrollIntoView({{
187+
behavior: 'smooth',
188+
block: 'center'
189+
}});
190+
}}
176191
</script>
177192
</head>
178193
<body id="console">
179194
</body>
180-
</html>"##,
195+
</html>"###,
181196
);
182197

183198
tracing::info!("gha_logs: serving logs for {log_uuid}");

0 commit comments

Comments
 (0)