zephyr/scripts/ci/do_not_merge.py
Fabio Baltieri 649eb6280d ci: pr_metadata_check: convert DNM logic to python
GitHub seems to have issue with workflow state caching that causes the
DNM step to not work properly in few cases and not detecting changes in
the DNM tag, forcing people to mess with tags or close/opening PRs,
which in turns restarts all workflows.

Convert the script to Python so that the tag data is guaranteed to be
fresh.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-05-20 10:17:19 +02:00

44 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import sys
import github
DNM_LABELS = ["DNM", "DNM (manifest)", "TSC", "Architecture Review", "dev-review"]
def parse_args(argv):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
allow_abbrev=False,
)
parser.add_argument("-p", "--pull-request", required=True, type=int, help="The PR number")
return parser.parse_args(argv)
def main(argv):
args = parse_args(argv)
token = os.environ.get('GITHUB_TOKEN', None)
gh = github.Github(token)
repo = gh.get_repo("zephyrproject-rtos/zephyr")
pr = repo.get_pull(args.pull_request)
for label in pr.get_labels():
if label.name in DNM_LABELS:
print(f"Pull request is labeled as \"{label.name}\".")
print("This workflow fails so that the pull request cannot be merged.")
sys.exit(1)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))