mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
Extract the hardcoded TRUSTED_CONTRIBUTORS set from ci/jobs/scripts/workflow_hooks/trusted.py into a standalone ci/defs/trusted_contributors.json config. The hook now loads the list from JSON. No change to who is trusted. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from praktika.info import Info
|
|
from praktika.utils import Shell
|
|
|
|
TRUSTED_CONTRIBUTORS_CONFIG = Path(__file__).parents[3] / "defs" / "trusted_contributors.json"
|
|
TRUSTED_CONTRIBUTORS = {
|
|
login.lower()
|
|
for login in json.loads(TRUSTED_CONTRIBUTORS_CONFIG.read_text(encoding="utf-8"))
|
|
}
|
|
|
|
CAN_BE_TESTED = "can be tested"
|
|
|
|
|
|
def user_in_trusted_org(user_name: str) -> bool:
|
|
"""Check if the user is in a trusted organization."""
|
|
lines = Shell.get_output(
|
|
"gh api orgs/ClickHouse/members --paginate --cache=1h --jq='.[].login'",
|
|
verbose=True,
|
|
)
|
|
return user_name in [line.strip() for line in lines.splitlines() if line.strip()]
|
|
|
|
|
|
def can_be_tested():
|
|
info = Info()
|
|
if info.repo_name == Info().fork_name:
|
|
print("It's an internal contributor")
|
|
return ""
|
|
if info.user_name.lower() in TRUSTED_CONTRIBUTORS:
|
|
print("It's a trusted contributor")
|
|
return ""
|
|
# we need runtime labels info, info.pr_labels might be non relevant in case of job rerun
|
|
if CAN_BE_TESTED in Shell.get_output(
|
|
f"gh pr view {info.pr_number} --json labels --jq '.labels[].name'"
|
|
):
|
|
print("It's approved by 'can be tested' label")
|
|
return ""
|
|
if user_in_trusted_org(info.user_name):
|
|
print("It's an internal contributor using fork")
|
|
return ""
|
|
|
|
return "'can be tested' label is required"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if can_be_tested() != "":
|
|
sys.exit(1)
|