Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions nixpkgs_review/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import socket
import subprocess
from collections.abc import Callable
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -8,7 +9,7 @@
from typing import Literal

from .nix import Attr
from .utils import System, info, link, skipped, system_order_key, warn
from .utils import System, info, link, skipped, system_order_key, to_link, warn


def print_number(
Expand Down Expand Up @@ -208,6 +209,12 @@ def order_reports(reports: dict[System, SystemReport]) -> dict[System, SystemRep
)


# https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
def to_file_uri(path: Path) -> str:
"""Convert a path to a file URI, including hostname."""
return f"file://{socket.gethostname()}{path.absolute()}"
Copy link
Contributor Author

@booxter booxter May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including hostname gives the desired behavior, e.g. in kitty:

Editing /home/booxter/.cache/nixpkgs-review/pr-405067-2/logs from build05
The command: ssh -o 'ControlPath=~/.ssh/kitty-rf-68330-%C' -o TCPKeepAlive=yes -o ControlPersist=yes -o BatchMode=yes linux-builder cat /home/booxter/.cache/nixpkgs-review/pr-405067-2/logs failed
cat: /home/booxter/.cache/nixpkgs-review/pr-405067-2/logs: Is a directory

Failed to download /home/booxter/.cache/nixpkgs-review/pr-405067-2/logs

Yes, it failed to edit it after all, but the main point is that it correctly detected that the URI is remote and tried to download it for edit. I believe I just need some adjustment to kitty to make this work too.

(In the next PR that will add links to each built package this won't be a problem anyway since these will point to actual files.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have some limit i.e. when too many packages are broken to not show all these links. This is also to keep the length of the report within a reasonable size that still is compatible with Github's limits for displaying comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 The links are seen only on tty and they won't blow up the (visible) size of reports because links are hidden, they are activated by "clicking" them. And they will not go to Github.



class Report:
def __init__(
self,
Expand Down Expand Up @@ -324,11 +331,11 @@ def markdown(self, pr: int | None) -> str:

return msg

def print_console(self, pr: int | None) -> None:
def print_console(self, root: Path, pr: int | None) -> None:
if pr is not None:
pr_url = f"https://github.com/NixOS/nixpkgs/pull/{pr}"
info("\nLink to currently reviewing PR:")
link(pr_url)
link(to_link(pr_url, pr_url))

for system, report in self.system_reports.items():
info(f"--------- Report for '{system}' ---------")
Expand All @@ -342,3 +349,8 @@ def print_console(self, pr: int | None) -> None:
print_number(report.failed, "failed to build")
print_number(report.tests, "built", what="test", log=print)
print_number(report.built, "built", log=print)

logs_dir = root / "logs"
info("Logs can be found under:")
link(to_link(to_file_uri(logs_dir), str(logs_dir)))
info("")
2 changes: 1 addition & 1 deletion nixpkgs_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def start_review(
# is mainly capped by available RAM
max_workers=min(32, os.cpu_count() or 1), # 'None' assumes IO tasks
)
report.print_console(pr)
report.print_console(path, pr)
report.write(path, pr)

success = report.succeeded()
Expand Down
9 changes: 4 additions & 5 deletions nixpkgs_review/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ def wrapper(text: str) -> None:
warn = color_text(31, file=sys.stderr)
info = color_text(32)
skipped = color_text(33)
link = color_text(34)


def link(text: str) -> None:
f = color_text(34)
def to_link(uri: str, text: str) -> str:
if HAS_TTY:
f(f"\u001b]8;;{text}\u001b\\{text}\u001b]8;;\u001b\\\n")
else:
f(text)
return f"\u001b]8;;{uri}\u001b\\{text}\u001b]8;;\u001b\\"
return text


def sh(
Expand Down