diff options
Diffstat (limited to '.ci/scripts/merge/apply-patches-by-label-private.py')
| -rw-r--r-- | .ci/scripts/merge/apply-patches-by-label-private.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.ci/scripts/merge/apply-patches-by-label-private.py b/.ci/scripts/merge/apply-patches-by-label-private.py new file mode 100644 index 000000000..fe0acd510 --- /dev/null +++ b/.ci/scripts/merge/apply-patches-by-label-private.py | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | # Download all pull requests as patches that match a specific label | ||
| 2 | # Usage: python download-patches-by-label.py <Label to Match> <Root Path Folder to DL to> | ||
| 3 | |||
| 4 | import requests, sys, json, shutil, subprocess, os, traceback | ||
| 5 | |||
| 6 | org = os.getenv("PRIVATEMERGEORG", "yuzu-emu") | ||
| 7 | repo = os.getenv("PRIVATEMERGEREPO", "yuzu-private") | ||
| 8 | tagline = sys.argv[3] | ||
| 9 | user = sys.argv[1] | ||
| 10 | |||
| 11 | dl_list = {} | ||
| 12 | |||
| 13 | TAG_NAME = sys.argv[2] | ||
| 14 | |||
| 15 | def check_individual(repo_id, pr_id): | ||
| 16 | url = 'https://%sdev.azure.com/%s/%s/_apis/git/repositories/%s/pullRequests/%s/labels?api-version=5.1-preview.1' % (user, org, repo, repo_id, pr_id) | ||
| 17 | response = requests.get(url) | ||
| 18 | if (response.ok): | ||
| 19 | try: | ||
| 20 | js = response.json() | ||
| 21 | return any(tag.get('name') == TAG_NAME for tag in js['value']) | ||
| 22 | except: | ||
| 23 | return False | ||
| 24 | return False | ||
| 25 | |||
| 26 | def merge_pr(pn, ref): | ||
| 27 | print("Matched PR# %s" % pn) | ||
| 28 | print(subprocess.check_output(["git", "fetch", "https://%sdev.azure.com/%s/_git/%s" % (user, org, repo), ref, "-f"])) | ||
| 29 | print(subprocess.check_output(["git", "merge", "--squash", 'origin/' + ref.replace('refs/heads/','')])) | ||
| 30 | print(subprocess.check_output(["git", "commit", "-m\"Merge %s PR %s\"" % (tagline, pn)])) | ||
| 31 | |||
| 32 | def main(): | ||
| 33 | url = 'https://%sdev.azure.com/%s/%s/_apis/git/pullrequests?api-version=5.1' % (user, org, repo) | ||
| 34 | response = requests.get(url) | ||
| 35 | if (response.ok): | ||
| 36 | js = response.json() | ||
| 37 | tagged_prs = filter(lambda pr: check_individual(pr['repository']['id'], pr['pullRequestId']), js['value']) | ||
| 38 | map(lambda pr: merge_pr(pr['pullRequestId'], pr['sourceRefName']), tagged_prs) | ||
| 39 | |||
| 40 | if __name__ == '__main__': | ||
| 41 | try: | ||
| 42 | main() | ||
| 43 | except: | ||
| 44 | traceback.print_exc(file=sys.stdout) | ||
| 45 | sys.exit(-1) | ||