Skip to content

Instantly share code, notes, and snippets.

@robdimsdale
Last active January 28, 2022 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robdimsdale/a516223ba17848d40b5c4a1cba9bd9be to your computer and use it in GitHub Desktop.
Save robdimsdale/a516223ba17848d40b5c4a1cba9bd9be to your computer and use it in GitHub Desktop.
Ensure semver labels exist for PRs
#!/usr/bin/env python3
import argparse
import json
import subprocess
import sys
repos=[
"conda-env-update",
"cpython",
"miniconda",
"pip",
"pip-install",
"pipenv",
"pipenv-install",
"poetry",
"poetry-install",
"poetry-run",
"python",
"python-start"
]
parser = argparse.ArgumentParser()
parser.add_argument('--include-closed', action='store_true',
help='Optionally include closed PRs')
args = parser.parse_args()
search_args="-label:semver:major,semver:minor,semver:patch is:open"
if args.include_closed:
search_args = search_args + " is:closed"
for repo in repos:
print("Checking", repo)
completed_process = subprocess.run(
args=[
"gh",
"pr",
"list",
"--search", search_args,
"--json", "number,title"],
cwd=repo, capture_output=True)
if completed_process.returncode != 0:
sys.exit(completed_process.stderr)
prs = json.loads(completed_process.stdout)
for pr in prs:
print(repo, "#"+str(pr['number']), "-", pr['title'])
semver_input = input("--> Label as major (M), minor (m), patch (p), or skip (s): ")
match semver_input:
case ("M"|"major"):
semver_label="semver:major"
case ("m"|"minor"):
semver_label="semver:minor"
case ("p"|"patch"):
semver_label="semver:patch"
case ("s"|"skip"):
print()
continue
case _:
sys.exit("Invalid semver label: " + semver_input)
subprocess.run([
"gh",
"pr",
"edit",
str(pr['number']),
"--add-label", semver_label,
],
cwd=repo)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment