-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support github links to site-packages
- Loading branch information
Showing
2 changed files
with
23 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import re | ||
from logging import LogRecord | ||
from urllib.parse import urlencode | ||
|
||
from homeassistant.const import __version__ | ||
|
||
RE_PATH = re.compile(r"/(custom_components|site-packages)/(.+)$") | ||
|
||
|
||
def github_get_link(record: LogRecord) -> str | None: | ||
if record.pathname.startswith("/usr/src/homeassistant/"): | ||
base = f"https://github.com/home-assistant/core/blob" | ||
return f"{base}/{__version__}/{record.pathname[23:]}#L{record.lineno}" | ||
|
||
if record.pathname.startswith("/config/custom_components"): | ||
query = urlencode( | ||
{"q": f"path:{record.pathname[8:]} {record.funcName}", "type": "code"} | ||
) | ||
if m := RE_PATH.search(record.pathname): | ||
path = f"{m[1]}/{m[2]}" if m[1] == "custom_components" else m[2] | ||
query = urlencode({"q": f"path:{path} {record.funcName}", "type": "code"}) | ||
return f"https://github.com/search?{query}#L{record.lineno}" | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters