Skip to content

Commit 56ad0ce

Browse files
authored
Add script to populate required checks list (open-telemetry#4127)
Fixes open-telemetry#4126
1 parent 909708c commit 56ad0ce

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/add_required_checks.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This script is to be used by maintainers by running it locally.
2+
3+
from requests import put
4+
from os import environ
5+
from yaml import safe_load
6+
from json import dumps
7+
8+
job_names = ["EasyCLA"]
9+
10+
# Check that the files below are all the workflow YAML files that should be
11+
# considered.
12+
for yml_file_name in [
13+
"test_0", "test_1", "misc_0", "lint_0", "contrib_0", "check-links"
14+
]:
15+
16+
with open(f"../.github/workflows/{yml_file_name}.yml") as yml_file:
17+
job_names.extend(
18+
[job["name"] for job in safe_load(yml_file)["jobs"].values()]
19+
)
20+
21+
owner = "open-telemetry"
22+
repo = "opentelemetry-python"
23+
branch = "main"
24+
25+
response = put(
26+
(
27+
f"https://api.github.com/repos/{owner}/{repo}/branches/{branch}/"
28+
"protection/required_status_checks/contexts"
29+
),
30+
headers={
31+
"Accept": "application/vnd.github.v3+json",
32+
# The token has to be created in Github, and exported to the
33+
# environment variable below. When creating the token, the resource
34+
# owner must be open-telemetry, the access must be for the repo above,
35+
# and read and write permissions must be granted for administration
36+
# permissions and read permissions must be granted for metadata
37+
# permissions.
38+
"Authorization": f"token {environ.get('REQUIRED_CHECKS_TOKEN')}"
39+
},
40+
data=dumps({"contexts": job_names})
41+
)
42+
43+
if response.status_code == 200:
44+
print(response.content)
45+
else:
46+
print(
47+
"Failed to update branch protection settings. "
48+
f"Status code: {response.status_code}"
49+
)
50+
print(response.json())

0 commit comments

Comments
 (0)