|
54 | 54 | from easybuild.framework.easyconfig.parser import EasyConfigParser |
55 | 55 | from easybuild.tools import LooseVersion |
56 | 56 | from easybuild.tools.build_log import EasyBuildError, EasyBuildExit, print_msg, print_warning |
57 | | -from easybuild.tools.config import DEFAULT_DOWNLOAD_MAX_ATTEMPTS, build_option |
| 57 | +from easybuild.tools.config import build_option |
58 | 58 | from easybuild.tools.filetools import apply_patch, copy_dir, copy_easyblocks, copy_file, copy_framework_files |
59 | 59 | from easybuild.tools.filetools import det_patched_files, download_file, extract_file |
60 | 60 | from easybuild.tools.filetools import get_easyblock_class_name, mkdir, read_file, symlink, which, write_file |
@@ -548,15 +548,22 @@ def fetch_files_from_pr(pr, path=None, github_user=None, github_account=None, gi |
548 | 548 | diff_url = pr_data['diff_url'] |
549 | 549 | diff_fn = os.path.basename(diff_url) |
550 | 550 | diff_filepath = os.path.join(path, diff_fn) |
551 | | - # max. 6 attempts + initial wait time of 10sec -> max. 10 * (2^6) = 640sec (~10min) before giving up on download |
552 | | - # see also https://github.com/easybuilders/easybuild-framework/issues/4869 |
553 | | - max_attempts = DEFAULT_DOWNLOAD_MAX_ATTEMPTS |
554 | | - download_file(diff_fn, diff_url, diff_filepath, forced=True, trace=False, |
555 | | - max_attempts=max_attempts) |
556 | | - if not os.path.exists(diff_filepath): |
557 | | - raise EasyBuildError(f"Failed to download {diff_url}, even after {max_attempts} attempts and being patient...") |
558 | | - diff_txt = read_file(diff_filepath) |
559 | | - _log.debug("Diff for PR #%s:\n%s", pr, diff_txt) |
| 551 | + |
| 552 | + def pr_request_fn(gh): |
| 553 | + return gh.repos[github_account][github_repo].pulls[pr] |
| 554 | + |
| 555 | + # see also https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request, |
| 556 | + # in particular part about media types |
| 557 | + accept_diff = {'Accept': 'application/vnd.github.diff'} |
| 558 | + status, data = github_api_get_request(pr_request_fn, github_user=github_user, headers=accept_diff) |
| 559 | + if status == HTTP_STATUS_OK: |
| 560 | + # decode from bytes to text |
| 561 | + diff_txt = data.decode() |
| 562 | + _log.debug("Diff for PR #%s:\n%s", pr, diff_txt) |
| 563 | + write_file(diff_filepath, diff_txt) |
| 564 | + else: |
| 565 | + error_msg = f"Failed to download diff for {github_account}/{github_repo} PR #{pr}! (HTTP status code: {status})" |
| 566 | + raise EasyBuildError(error_msg) |
560 | 567 |
|
561 | 568 | patched_files = det_patched_files(txt=diff_txt, omit_ab_prefix=True, github=True, filter_deleted=True) |
562 | 569 | _log.debug("List of patched files for PR #%s: %s", pr, patched_files) |
@@ -703,24 +710,25 @@ def fetch_files_from_commit(commit, files=None, path=None, github_account=None, |
703 | 710 |
|
704 | 711 | # if no files are specified, determine which files are touched in commit |
705 | 712 | if not files: |
706 | | - diff_url = os.path.join(GITHUB_URL, github_account, github_repo, 'commit', commit + '.diff') |
707 | | - diff_fn = os.path.basename(diff_url) |
708 | | - diff_filepath = os.path.join(path, diff_fn) |
709 | | - # max. 6 attempts + initial wait time of 10sec -> max. 10 * (2^6) = 640sec (~10min) before giving up on download |
710 | | - # see also https://github.com/easybuilders/easybuild-framework/issues/4869 |
711 | | - max_attempts = DEFAULT_DOWNLOAD_MAX_ATTEMPTS |
712 | | - download_file(diff_fn, diff_url, diff_filepath, forced=True, trace=False, |
713 | | - max_attempts=max_attempts) |
714 | | - if os.path.exists(diff_filepath): |
715 | | - diff_txt = read_file(diff_filepath) |
| 713 | + github_user = build_option('github_user') |
| 714 | + |
| 715 | + def pr_request_fn(gh): |
| 716 | + return gh.repos[github_account][github_repo].pulls[pr] |
| 717 | + |
| 718 | + # see also https://docs.github.com/en/rest/commits/commits#get-a-commit, |
| 719 | + # in particular part about media types |
| 720 | + accept_diff = {'Accept': 'application/vnd.github.diff'} |
| 721 | + status, data = github_api_get_request(pr_request_fn, github_user=github_user, headers=accept_diff) |
| 722 | + if status == HTTP_STATUS_OK: |
| 723 | + # decode from bytes to text |
| 724 | + diff_txt = data.decode() |
716 | 725 | _log.debug("Diff for commit %s:\n%s", commit, diff_txt) |
717 | 726 |
|
718 | 727 | files = det_patched_files(txt=diff_txt, omit_ab_prefix=True, github=True, filter_deleted=True) |
719 | 728 | _log.debug("List of patched files for commit %s: %s", commit, files) |
720 | 729 | else: |
721 | | - msg = f"Failed to download diff for commit {commit} of {github_account}/{github_repo} " |
722 | | - msg += " (after {max_attempts} attempts)" |
723 | | - raise EasyBuildError(msg, exit_code=EasyBuildExit.FAIL_GITHUB) |
| 730 | + error_msg = f"Failed to download diff for {github_account}/{github_repo} PR #{pr}! (HTTP status code: {status})" |
| 731 | + raise EasyBuildError(error_msg) |
724 | 732 |
|
725 | 733 | # download tarball for specific commit |
726 | 734 | repo_commit = download_repo(repo=github_repo, commit=commit, account=github_account) |
|
0 commit comments