Skip to content

Commit a043dae

Browse files
committed
fix(download): correctly parse remote URL
This changes the "zmk download" command to use giturlparse when determining the URL for the GitHub actions page. This correctly handles URLs that end in ".git" as well as SSH "user@host:path" URLS.
1 parent 983818c commit a043dae

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ classifiers = [
1717
dependencies = [
1818
"backports.strenum; python_version < '3.11'",
1919
"dacite >= 1.9.2, < 2.0.0",
20+
"giturlparse >= 0.14.0, < 0.15.0",
2021
"mako >= 1.3.10, < 2.0.0",
2122
"rich >= 14.2.0, < 15.0.0",
2223
"ruamel.yaml >= 0.18.17, < 0.19.0",

zmk/commands/download.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
import webbrowser
66

7+
import giturlparse
78
import typer
89

910
from ..config import get_config
11+
from ..exceptions import FatalError
1012
from ..repo import Repo
1113

1214

@@ -22,7 +24,13 @@ def download(ctx: typer.Context) -> None:
2224

2325

2426
def _get_actions_url(repo: Repo):
25-
remote = repo.git("remote", capture_output=True).strip()
26-
remote_url = repo.git("remote", "get-url", remote, capture_output=True).strip()
27+
remote_url = repo.get_remote_url()
2728

28-
return f"{remote_url}/actions/workflows/build.yml"
29+
p = giturlparse.parse(remote_url)
30+
31+
match p.platform:
32+
case "github":
33+
return f"https://github.com/{p.owner}/{p.repo}/actions/workflows/build.yml"
34+
35+
case _:
36+
raise FatalError(f"Unsupported remote URL: {remote_url}")

zmk/repo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ def get_modules(self) -> Generator[Module, None, None]:
116116
for line in modules.splitlines():
117117
yield Module(self.west_path / line)
118118

119+
def get_remote_url(self) -> str:
120+
"""Get the remote URL for the checked out Git branch."""
121+
remote = self.git("remote", capture_output=True).strip()
122+
return self.git("remote", "get-url", remote, capture_output=True).strip()
123+
119124
@property
120125
def build_matrix_path(self) -> Path:
121126
"""Path to the "build.yaml" file."""

0 commit comments

Comments
 (0)