From 5eebd653666f4967163857a30a034d4ec3fe624f Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Sun, 19 May 2024 09:30:19 -0500 Subject: [PATCH] audit: disallow github.com/org/repo/pull/n/commits/hash.patch?full_index=1 (#44212) * audit: disallow github.com/org/repo/pull/n/commits/hash.patch?full_index=1 * [@spackbot] updating style on behalf of wdconinc * audit: fix style * audit: github.com/o/r/pull/n/commits/sha.patch -> sha.patch * [@spackbot] updating style on behalf of wdconinc * Revert "[@spackbot] updating style on behalf of wdconinc" This reverts commit 2ecec9923829c9514f6e09885ee57cda3688b2f4. * Revert "audit: github.com/o/r/pull/n/commits/sha.patch -> sha.patch" This reverts commit 5bd7da2cadee9dae44ce14f35a4fb72323c0b98e. * fix: modify audit message with suggested fix * audit: github.com/o/r/pull/n/commits/sha.patch -> /o/r/commit/sha.patch?full_index=1 --------- Co-authored-by: wdconinc --- lib/spack/spack/audit.py | 26 ++++++++++++++----- lib/spack/spack/test/audit.py | 2 ++ .../package.py | 20 ++++++++++++++ .../builtin/packages/dla-future/package.py | 4 +-- .../builtin/packages/miopen-hip/package.py | 4 +-- .../repos/builtin/packages/mlpack/package.py | 4 +-- .../packages/openscenegraph/package.py | 4 +-- .../builtin/packages/py-astor/package.py | 4 +-- .../repos/builtin/packages/umpire/package.py | 8 +++--- .../repos/builtin/packages/wrf/package.py | 8 +++--- 10 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 var/spack/repos/builtin.mock/packages/invalid-github-pull-commits-patch-url/package.py diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py index 50eb8b8ec5d..3154723e162 100644 --- a/lib/spack/spack/audit.py +++ b/lib/spack/spack/audit.py @@ -421,6 +421,10 @@ def _check_patch_urls(pkgs, error_cls): r"^https?://(?:patch-diff\.)?github(?:usercontent)?\.com/" r".+/.+/(?:commit|pull)/[a-fA-F0-9]+\.(?:patch|diff)" ) + github_pull_commits_re = ( + r"^https?://(?:patch-diff\.)?github(?:usercontent)?\.com/" + r".+/.+/pull/\d+/commits/[a-fA-F0-9]+\.(?:patch|diff)" + ) # Only .diff URLs have stable/full hashes: # https://forum.gitlab.com/t/patches-with-full-index/29313 gitlab_patch_url_re = ( @@ -436,14 +440,24 @@ def _check_patch_urls(pkgs, error_cls): if not isinstance(patch, spack.patch.UrlPatch): continue - if re.match(github_patch_url_re, patch.url): + if re.match(github_pull_commits_re, patch.url): + url = re.sub(r"/pull/\d+/commits/", r"/commit/", patch.url) + url = re.sub(r"^(.*)(?