feat: expand env variables in config at runtime

This commit is contained in:
2026-07-26 16:44:23 +02:00
parent 2427e5e426
commit 39a89ffbdc
2 changed files with 29 additions and 1 deletions
+2
View File
@@ -59,6 +59,8 @@ The default values are below.
`ntfy.server` (string url) Ntfy server to use.
`ntfy.topic` (string) Ntfy topic for the notification.
Note : `$` will be expanded into the environment variables at runtime. Don't forget to escape it with `\`.
### Usage
* Adding a PR : `nixpkgs-notifier add PR1 PR2 PR3 ...`
+27 -1
View File
@@ -74,6 +74,32 @@ def load_config():
print("Config file is broken. Using default config.")
return DEFAULT_CONFIG
import re
def expand_env_vars(obj):
if isinstance(obj, dict):
return {
key: expand_env_vars(value)
for key, value in obj.items()
}
elif isinstance(obj, list):
return [
expand_env_vars(item)
for item in obj
]
elif isinstance(obj, str):
pattern = r"(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)"
def replace(match):
var = match.group(1)
return os.environ.get(var, match.group(0))
return re.sub(pattern, replace, obj)
return obj
def addTracker(PRnumber):
result = fetchStatus(PRnumber)
if result == "accepted":
@@ -237,7 +263,7 @@ def fetchStatus(PRnumber):
def main():
# fetch config
cfg = load_config()
cfg = expand_env_vars(load_config())
global configTime
global configFetchTime