Skip to content

Commit e29fa01

Browse files
committed
Add comments around the regex paths and tree_roots
1 parent f2b5154 commit e29fa01

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/gha_logs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ async fn process_logs(
135135
.await
136136
.context("unable to fetch git tree for the repository")?;
137137

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.
138143
let tree_roots = trees
139144
.tree
140145
.iter()
@@ -238,7 +243,19 @@ async fn process_logs(
238243
`<span class="warning-marker">##[warning]</span>`
239244
);
240245
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.
242259
const pathRegex = /(?<boundary>[^a-zA-Z0-9.\\/])(?<inner>(?:[\\\/]?(?:checkout[\\\/])?(?<path>(?:{tree_roots})[\\\/][a-zA-Z0-9_$\-.\\\/]+))(?::(?<line>[0-9]+):(?<col>[0-9]+))?)/g;
243260
html = html.replace(pathRegex, (match, boundary, inner, path, line, col) => {{
244261
const pos = (line !== undefined) ? `#L${{line}}` : "";

0 commit comments

Comments
 (0)