tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

notify.py (1502B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 from taskgraph.transforms.base import TransformSequence
      6 from taskgraph.util.schema import resolve_keyed_by
      7 
      8 transforms = TransformSequence()
      9 
     10 
     11 @transforms.add
     12 def resolve_keys(config, tasks):
     13    for task in tasks:
     14        for key in ("notifications.message", "notifications.emails"):
     15            resolve_keyed_by(
     16                task,
     17                key,
     18                item_name=task["name"],
     19                **{
     20                    "level": config.params["level"],
     21                },
     22            )
     23        yield task
     24 
     25 
     26 @transforms.add
     27 def add_notify_email(config, tasks):
     28    for task in tasks:
     29        notify = task.pop("notify", {})
     30        email_config = notify.get("email")
     31        if email_config:
     32            extra = task.setdefault("extra", {})
     33            notify = extra.setdefault("notify", {})
     34            notify["email"] = {
     35                "content": email_config["content"],
     36                "subject": email_config["subject"],
     37                "link": email_config.get("link", None),
     38            }
     39 
     40            routes = task.setdefault("routes", [])
     41            routes.extend([
     42                f"notify.email.{address}.on-{reason}"
     43                for address in email_config["to-addresses"]
     44                for reason in email_config["on-reasons"]
     45            ])
     46 
     47        yield task