File: util.py

package info (click to toggle)
glean-parser 15.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: python: 7,033; ruby: 100; makefile: 87
file content (52 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-

# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

from glean_parser import parser


def add_required(chunk):
    DEFAULTS = {
        "type": "string",
        "bugs": ["http://bugzilla.mozilla.org/12345678"],
        "description": "DESCRIPTION...",
        "notification_emails": ["nobody@example.com"],
        "data_reviews": ["https://example.com/review/"],
        "expires": "never",
    }

    for category_key, category_val in chunk.items():
        if category_key in ("$schema", "$tags", "no_lint"):
            continue
        for metric in category_val.values():
            for default_name, default_val in DEFAULTS.items():
                if default_name not in metric:
                    metric[default_name] = default_val

    if "$schema" not in chunk:
        chunk["$schema"] = parser.METRICS_ID

    return chunk


def add_required_ping(chunk):
    DEFAULTS = {
        "bugs": ["http://bugzilla.mozilla.org/12345678"],
        "description": "DESCRIPTION...",
        "notification_emails": ["nobody@nowhere.com"],
        "data_reviews": ["https://nowhere.com/review/"],
        "include_client_id": True,
    }

    for ping_name, ping in chunk.items():
        if ping_name in ("no_lint", "$schema"):
            continue
        for default_name, default_val in DEFAULTS.items():
            if default_name not in ping:
                ping[default_name] = default_val

    if "$schema" not in chunk:
        chunk["$schema"] = parser.PINGS_ID

    return chunk