apply-patches-by-label.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # SPDX-FileCopyrightText: 2019 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Download all pull requests as patches that match a specific label
  4. # Usage: python apply-patches-by-label.py <Label to Match>
  5. import json, requests, subprocess, sys, traceback
  6. tagline = sys.argv[2]
  7. def check_individual(labels):
  8. for label in labels:
  9. if (label["name"] == sys.argv[1]):
  10. return True
  11. return False
  12. def do_page(page):
  13. url = f"https://api.github.com/repos/yuzu-emu/yuzu/pulls?page={page}"
  14. response = requests.get(url)
  15. response.raise_for_status()
  16. if (response.ok):
  17. j = json.loads(response.content)
  18. if j == []:
  19. return
  20. for pr in j:
  21. if (check_individual(pr["labels"])):
  22. pn = pr["number"]
  23. print(f"Matched PR# {pn}")
  24. print(subprocess.check_output(["git", "fetch", "https://github.com/yuzu-emu/yuzu.git", f"pull/{pn}/head:pr-{pn}", "-f", "--no-recurse-submodules"]))
  25. print(subprocess.check_output(["git", "merge", "--squash", f"pr-{pn}"]))
  26. print(subprocess.check_output(["git", "commit", f"-m\"Merge {tagline} PR {pn}\""]))
  27. try:
  28. for i in range(1,10):
  29. do_page(i)
  30. except:
  31. traceback.print_exc(file=sys.stdout)
  32. sys.exit(-1)