@@ -3,6 +3,7 @@ use crate::handlers::Context;
3
3
use anyhow:: Context as _;
4
4
use hyper:: header:: { CACHE_CONTROL , CONTENT_SECURITY_POLICY , CONTENT_TYPE } ;
5
5
use hyper:: { Body , Response , StatusCode } ;
6
+ use itertools:: Itertools ;
6
7
use std:: collections:: VecDeque ;
7
8
use std:: str:: FromStr ;
8
9
use std:: sync:: Arc ;
@@ -134,13 +135,11 @@ async fn process_logs(
134
135
. await
135
136
. context ( "unable to fetch git tree for the repository" ) ?;
136
137
137
- let tree_roots: Vec < _ > = trees
138
+ let tree_roots = trees
138
139
. tree
139
140
. iter ( )
140
141
. filter_map ( |t| ( t. object_type == "tree" ) . then_some ( & t. path ) )
141
- . collect ( ) ;
142
- let tree_roots =
143
- serde_json:: to_string ( & tree_roots) . context ( "unable to serialize tree roots" ) ?;
142
+ . join ( "|" ) ;
144
143
145
144
anyhow:: Result :: < _ > :: Ok ( ( job, tree_roots) )
146
145
} ;
@@ -212,8 +211,6 @@ async fn process_logs(
212
211
import {{ AnsiUp }} from '{ANSI_UP_URL}'
213
212
214
213
var logs = {logs};
215
- var tree_roots = {tree_roots};
216
-
217
214
var ansi_up = new AnsiUp();
218
215
219
216
// 1. Tranform the ANSI escape codes to HTML
@@ -242,20 +239,10 @@ async fn process_logs(
242
239
);
243
240
244
241
// 5. Add anchors to GitHub around some paths
245
- const pathRegex = /((?:[A-Za-z]:)?[a-zA-Z0-9_.$-]*(?:[\\/][a-zA-Z0-9_$.-]+)+)(?::([0-9]*):([0-9]*))?/g;
246
- html = html.replace(pathRegex, (match, path, line, col) => {{
247
- const removePrefix = (value, prefix) =>
248
- value.startsWith(prefix) ? value.slice(prefix.length) : value;
249
-
250
- var path = removePrefix(removePrefix(path, "/checkout"), "/");
251
- var root = path.substring(0, path.indexOf("/"));
252
-
253
- if (tree_roots.includes(root)) {{
254
- const pos = (line !== undefined) ? `#L${{line}}` : "";
255
- return `<a href="https://github.com/{owner}/{repo}/blob/{sha}/${{path}}${{pos}}" class="path-marker">${{match}}</a>`;
256
- }}
257
-
258
- return match;
242
+ const pathRegex = /(?<boundary>[^a-zA-Z0-9.\\/])(?<inner>(?:[\\\/]?(?:checkout[\\\/])?(?<path>(?:{tree_roots})[\\\/][a-zA-Z0-9_$\-.\\\/]+))(?::(?<line>[0-9]+):(?<col>[0-9]+))?)/g;
243
+ html = html.replace(pathRegex, (match, boundary, inner, path, line, col) => {{
244
+ const pos = (line !== undefined) ? `#L${{line}}` : "";
245
+ return `${{boundary}}<a href="https://github.com/{owner}/{repo}/blob/{sha}/${{path}}${{pos}}" class="path-marker">${{inner}}</a>`;
259
246
}});
260
247
261
248
// 6. Add the html to the DOM
0 commit comments