Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to populate required checks list #4127

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scripts/add_required_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This script is to be used by maintainers by running it locally.

from requests import put
from os import environ
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
from yaml import safe_load
from json import dumps

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')}"
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
},
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())
Loading