❄️ Dotfiles and NixOS configurations
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkgs/channel-notifier: logging

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>

+21 -4
+21 -4
pkgs/channel-notifier/channel_notifier.py
··· 1 + from argparse import ArgumentParser 1 2 from datetime import datetime, timezone 2 3 from json import dump, dumps, load 3 4 from os import environ ··· 6 7 from typing import Tuple 7 8 from sys import exit 8 9 from urllib.request import Request, urlopen 10 + import logging 11 + 12 + logger = logging.getLogger(__name__) 9 13 10 14 11 15 def commit_url(rev: str): ··· 52 56 ) 53 57 req.add_header("Content-Type", "application/json; charset=utf-8") 54 58 55 - print(webhook_url) 56 - 57 59 urlopen(req) 58 60 59 61 60 62 def main(): 63 + parser = ArgumentParser() 64 + parser.add_argument("-v", "--verbose", action="store_true") 65 + args = parser.parse_args() 66 + 67 + logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) 68 + 61 69 data_path = Path(environ.get("STATE_DIRECTORY", ".")) / "cached.json" 62 70 webhook_url = environ.get("WEBHOOK_URL", "") 63 71 channel = environ.get("NIXOS_CHANNEL", "nixos-unstable") 64 72 73 + logger.debug(f"Data path resolved to {data_path}") 74 + 65 75 latest_revision = fetch_latest_revision("https://prometheus.nixos.org", channel) 66 76 now = datetime.now(tz=timezone.utc) 77 + 78 + logger.info(f"Fetched latest revision {latest_revision} for {channel} at {now}") 67 79 68 80 if not latest_revision: 81 + logger.error("Fetched data does not contain revision") 69 82 return 1 70 83 71 84 cached = read_cached_revision(data_path) 72 85 73 86 if cached: 74 - cached_revision, _ = cached 87 + cached_revision, cached_datetime = cached 88 + logger.info( 89 + f"Read cached revision {cached_revision} for {channel} from {cached_datetime}" 90 + ) 75 91 76 92 if cached_revision != latest_revision: 93 + logger.info("Cached and fetched revisions differ") 94 + 77 95 rev_url = commit_url(latest_revision) 78 96 79 - print(f"Sending webhook for new {channel} revision {latest_revision}") 80 97 send_webhook( 81 98 webhook_url, 82 99 f"# Nixpkgs `{channel}` Channel Update\nThe channel {channel} has been updated to revision [{latest_revision}](<{rev_url}>).\n[**NixOS Status**](https://status.nixos.org/)",