Skip to content

Commit

Permalink
Add patcher script (#73)
Browse files Browse the repository at this point in the history
* Added yaptide patching script

* Update yaptide_patching_script.py

* Update yaptide_patching_script.py

Co-authored-by: Leszek Grzanka <[email protected]>

* Update yaptide_patching_script.py

Co-authored-by: Leszek Grzanka <[email protected]>

* Update yaptide_patching_script.py

* moved yaptide_patching_script.py

---------

Co-authored-by: Leszek Grzanka <[email protected]>
  • Loading branch information
p1003 and grzanka authored Oct 30, 2023
1 parent 13d7e36 commit 8686c97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,6 @@ shieldhit
roles/backend/files/password
secure.yaml
server.key
server.crt
server.crt

patches*
40 changes: 40 additions & 0 deletions scripts/yaptide_patching_script.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8686c97

Please sign in to comment.