File: add_required_checks.py

package info (click to toggle)
python-opentelemetry 1.39.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,952 kB
  • sloc: python: 53,083; sh: 398; makefile: 142; sql: 39
file content (55 lines) | stat: -rw-r--r-- 1,610 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
53
54
55
# This script is to be used by maintainers by running it locally.

from json import dumps
from os import environ

from requests import put
from yaml import safe_load

job_names = ["EasyCLA"]

# Check that the files below are all the workflow YAML files that should be
# considered.
for yml_file_name in [
    "test_0",
    "test_1",
    "misc_0",
    "lint_0",
    "contrib_0",
    "check-links",
]:
    with open(f"../.github/workflows/{yml_file_name}.yml") as yml_file:
        job_names.extend(
            [job["name"] for job in safe_load(yml_file)["jobs"].values()]
        )

owner = "open-telemetry"
repo = "opentelemetry-python"
branch = "main"

response = put(
    (
        f"https://api.github.com/repos/{owner}/{repo}/branches/{branch}/"
        "protection/required_status_checks/contexts"
    ),
    headers={
        "Accept": "application/vnd.github.v3+json",
        # The token has to be created in Github, and exported to the
        # environment variable below. When creating the token, the resource
        # owner must be open-telemetry, the access must be for the repo above,
        # and read and write permissions must be granted for administration
        # permissions and read permissions must be granted for metadata
        # permissions.
        "Authorization": f"token {environ.get('REQUIRED_CHECKS_TOKEN')}",
    },
    data=dumps({"contexts": job_names}),
)

if response.status_code == 200:
    print(response.content)
else:
    print(
        "Failed to update branch protection settings. "
        f"Status code: {response.status_code}"
    )
    print(response.json())