mirror of
https://github.com/tomasriveral/nixpkgs-notifier.git
synced 2026-08-11 18:28:38 +02:00
feat: expand env variables in config at runtime
This commit is contained in:
@@ -59,6 +59,8 @@ The default values are below.
|
|||||||
`ntfy.server` (string url) Ntfy server to use.
|
`ntfy.server` (string url) Ntfy server to use.
|
||||||
`ntfy.topic` (string) Ntfy topic for the notification.
|
`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
|
### Usage
|
||||||
|
|
||||||
* Adding a PR : `nixpkgs-notifier add PR1 PR2 PR3 ...`
|
* Adding a PR : `nixpkgs-notifier add PR1 PR2 PR3 ...`
|
||||||
|
|||||||
+27
-1
@@ -74,6 +74,32 @@ def load_config():
|
|||||||
print("Config file is broken. Using default config.")
|
print("Config file is broken. Using default config.")
|
||||||
return 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):
|
def addTracker(PRnumber):
|
||||||
result = fetchStatus(PRnumber)
|
result = fetchStatus(PRnumber)
|
||||||
if result == "accepted":
|
if result == "accepted":
|
||||||
@@ -237,7 +263,7 @@ def fetchStatus(PRnumber):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# fetch config
|
# fetch config
|
||||||
cfg = load_config()
|
cfg = expand_env_vars(load_config())
|
||||||
|
|
||||||
global configTime
|
global configTime
|
||||||
global configFetchTime
|
global configFetchTime
|
||||||
|
|||||||
Reference in New Issue
Block a user