From 8686c977808ca16ad02218c0a6bfef842ea0ec22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pitrus?= <56313631+p1003@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:33:18 +0100 Subject: [PATCH] Add patcher script (#73) * Added yaptide patching script * Update yaptide_patching_script.py * Update yaptide_patching_script.py Co-authored-by: Leszek Grzanka * Update yaptide_patching_script.py Co-authored-by: Leszek Grzanka * Update yaptide_patching_script.py * moved yaptide_patching_script.py --------- Co-authored-by: Leszek Grzanka --- .gitignore | 4 ++- scripts/yaptide_patching_script.py | 40 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 scripts/yaptide_patching_script.py diff --git a/.gitignore b/.gitignore index 0bdc19a..8331583 100644 --- a/.gitignore +++ b/.gitignore @@ -198,4 +198,6 @@ shieldhit roles/backend/files/password secure.yaml server.key -server.crt \ No newline at end of file +server.crt + +patches* \ No newline at end of file diff --git a/scripts/yaptide_patching_script.py b/scripts/yaptide_patching_script.py new file mode 100644 index 0000000..29efb95 --- /dev/null +++ b/scripts/yaptide_patching_script.py @@ -0,0 +1,40 @@ +# use bash script to get all PR patches from github +# install gh cli tool before running this script +# run `gh auth login` before running this script +import subprocess +import json + +from pathlib import Path +from tqdm import tqdm +from zipfile import ZipFile + + +def main(): + base_dir = Path(__file__).resolve().parent.parent + patches_dir = base_dir / "patches" + patches_dir.mkdir(exist_ok=True) + + for repo_name in ["ui", "yaptide", "converter"]: + repo = f"yaptide/{repo_name}" + # get all PRs with EuroHPC label and closed state + output = subprocess.check_output( + f"gh pr --repo {repo} list --label EuroHPC --state all --json number --limit 10000", shell=True, text=True) + # read json file + data = json.loads(output) + print(f"Number of patches for {repo} repo: {len(data)}") + + # get patches for each PR + for pull_request in tqdm(data, desc=f"Getting patches for {repo_name} repo", unit="patch"): + patch = subprocess.check_output( + f'gh pr --repo {repo} diff {pull_request["number"]} --patch', shell=True, text=True) + + (patches_dir / f'patch_{repo_name}_{pull_request["number"]}.patch').write_text(patch) + + zip_file = base_dir / "patches.zip" + with ZipFile(zip_file, 'w') as zip_obj: + for file in patches_dir.iterdir(): + zip_obj.write(file) + + +if __name__ == "__main__": + main()