Merge pull request #313 from netmindz/repo-info

Repo info
This commit is contained in:
Will Tatam
2026-01-07 22:48:43 +00:00
committed by GitHub
4 changed files with 73 additions and 14 deletions

54
pio-scripts/set_repo.py Normal file
View File

@@ -0,0 +1,54 @@
Import('env')
import subprocess
import re
def get_github_repo():
"""Extract GitHub repository name from git remote URL.
Returns:
str: Repository name in 'owner/repo' format for GitHub repos,
'unknown' for non-GitHub repos, missing git CLI, or any errors.
"""
try:
# Get the remote URL for origin
result = subprocess.run(['git', 'remote', 'get-url', 'origin'],
capture_output=True, text=True, check=True)
remote_url = result.stdout.strip()
# Check if it's a GitHub URL
if 'github.com' not in remote_url.lower():
return 'unknown'
# Parse GitHub URL patterns:
# https://github.com/owner/repo.git
# git@github.com:owner/repo.git
# https://github.com/owner/repo
# Remove .git suffix if present
if remote_url.endswith('.git'):
remote_url = remote_url[:-4]
# Handle HTTPS URLs
https_match = re.search(r'github\.com/([^/]+/[^/]+)', remote_url, re.IGNORECASE)
if https_match:
return https_match.group(1)
# Handle SSH URLs
ssh_match = re.search(r'github\.com:([^/]+/[^/]+)', remote_url, re.IGNORECASE)
if ssh_match:
return ssh_match.group(1)
return 'unknown'
except FileNotFoundError:
# Git CLI is not installed or not in PATH
return 'unknown'
except subprocess.CalledProcessError:
# Git command failed (e.g., not a git repo, no remote, etc.)
return 'unknown'
except Exception:
# Any other unexpected error
return 'unknown'
repo = get_github_repo()
env.Append(BUILD_FLAGS=[f'-DWLED_REPO=\\"{repo}\\"'])

View File

@@ -222,6 +222,7 @@ extra_scripts =
pre:pio-scripts/set_version.py
pre:pio-scripts/build_ui.py
pre:pio-scripts/conditional_usb_mode.py
pre:pio-scripts/set_repo.py
post:pio-scripts/output_bins.py
post:pio-scripts/strip-floats.py
pre:pio-scripts/user_config_copy.py

View File

@@ -954,7 +954,7 @@ void serializeInfo(JsonObject root)
//root[F("cn")] = F(WLED_CODENAME); //WLEDMM removed
root[F("release")] = FPSTR(releaseString);
root[F("rel")] = FPSTR(releaseString); //WLEDMM to add bin name
//root[F("repo")] = repoString; // WLEDMM not availeable
root[F("repo")] = repoString;
root[F("deviceId")] = getDeviceId();
JsonObject leds = root.createNestedObject("leds");

View File

@@ -296,10 +296,14 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
#ifndef WLED_RELEASE_NAME
#define WLED_RELEASE_NAME mdev_release
#endif
#ifndef WLED_REPO
#define WLED_REPO "unknown"
#endif
// Global Variable definitions
WLED_GLOBAL char versionString[] _INIT(TOSTRING(WLED_VERSION));
WLED_GLOBAL char releaseString[] _INIT_PROGMEM(TOSTRING(WLED_RELEASE_NAME)); //WLEDMM: to show on update page // somehow this will not work if using "const char releaseString[]
WLED_GLOBAL char repoString[] _INIT(WLED_REPO);
#define WLED_CODENAME "Hoshi"
// AP and OTA default passwords (for maximum security change them!)