@@ -135,6 +135,11 @@ async fn process_logs(
135
135
. await
136
136
. context ( "unable to fetch git tree for the repository" ) ?;
137
137
138
+ // To minimize false positives in paths linked to the GitHub repositories,
139
+ // we restrict matching to only the top-level directories of the repository.
140
+ // We achieve this by retrieving all "tree" objects and concatenating them
141
+ // into a regex OR pattern (e.g., `compiler|tests|src`) which is used in the
142
+ // JS regex.
138
143
let tree_roots = trees
139
144
. tree
140
145
. iter ( )
@@ -238,7 +243,19 @@ async fn process_logs(
238
243
`<span class="warning-marker">##[warning]</span>`
239
244
);
240
245
241
- // 5. Add anchors to GitHub around some paths
246
+ // 5. Add anchors around some paths
247
+ // Detailed examples of what the regex does is at https://regex101.com/r/vCnx9Y/2
248
+ //
249
+ // But simply speaking the regex tries to find absolute (with `/checkout` prefix) and
250
+ // relative paths, the path must start with one of the repository top-level directory.
251
+ // We also try to retrieve the lines and cols if given (`<path>:line:col`).
252
+ //
253
+ // Some examples of paths we want to find:
254
+ // - src/tools/test-float-parse/src/traits.rs:173:11
255
+ // - /checkout/compiler/rustc_macros
256
+ // - /checkout/src/doc/rustdoc/src/advanced-features.md
257
+ //
258
+ // Any other paths, in particular if prefixed by `./` or `obj/` should not taken.
242
259
const pathRegex = /(?<boundary>[^a-zA-Z0-9.\\/])(?<inner>(?:[\\\/]?(?:checkout[\\\/])?(?<path>(?:{tree_roots})[\\\/][a-zA-Z0-9_$\-.\\\/]+))(?::(?<line>[0-9]+):(?<col>[0-9]+))?)/g;
243
260
html = html.replace(pathRegex, (match, boundary, inner, path, line, col) => {{
244
261
const pos = (line !== undefined) ? `#L${{line}}` : "";
0 commit comments