|
43 | 43 | from univers.version_range import VersionRange |
44 | 44 |
|
45 | 45 | from aboutcode.hashid import build_vcid |
| 46 | +from aboutcode.hashid import get_core_purl |
46 | 47 |
|
47 | 48 | logger = logging.getLogger(__name__) |
48 | 49 |
|
@@ -902,49 +903,44 @@ def compute_advisory_content(advisory_data): |
902 | 903 | return content_hash |
903 | 904 |
|
904 | 905 |
|
905 | | -def generate_patch_url(vcs_url, commit_hash): |
| 906 | +def generate_commit_url(vcs_url, commit_hash): |
906 | 907 | """ |
907 | | - Generate patch URL from VCS URL and commit hash. |
| 908 | + Generate commit URL from VCS URL and commit hash. |
908 | 909 | """ |
909 | 910 | if not vcs_url or not commit_hash: |
910 | | - return None |
| 911 | + return |
911 | 912 |
|
912 | | - vcs_url = vcs_url.rstrip("/") |
| 913 | + purl = url2purl(vcs_url) |
| 914 | + if not purl: |
| 915 | + return |
913 | 916 |
|
914 | | - if vcs_url.startswith("https://github.com"): |
915 | | - return f"{vcs_url}/commit/{commit_hash}.patch" |
916 | | - elif vcs_url.startswith("https://gitlab.com"): |
917 | | - return f"{vcs_url}/-/commit/{commit_hash}.patch" |
918 | | - elif vcs_url.startswith("https://codeberg.org"): |
919 | | - return f"{vcs_url}/-/commit/{commit_hash}.patch" |
920 | | - elif vcs_url.startswith("https://android.googlesource.com"): |
921 | | - return f"{vcs_url}/+/{commit_hash}%5E%21?format=TEXT" |
922 | | - elif vcs_url.startswith("https://bitbucket.org"): |
923 | | - return f"{vcs_url}/-/commit/{commit_hash}/raw" |
924 | | - elif vcs_url.startswith("https://git.kernel.org"): |
925 | | - return f"{vcs_url}/patch/?id={commit_hash}" |
926 | | - return |
| 917 | + base_purl = get_core_purl(str(purl)) |
| 918 | + purl_with_version = PackageURL( |
| 919 | + type=base_purl.type, namespace=base_purl.namespace, name=base_purl.name, version=commit_hash |
| 920 | + ) |
| 921 | + commit_url = purl2url(str(purl_with_version)) |
| 922 | + return commit_url |
927 | 923 |
|
928 | 924 |
|
929 | | -def generate_commit_url(vcs_url, commit_hash): |
| 925 | +def generate_patch_url(vcs_url, commit_hash): |
930 | 926 | """ |
931 | | - Generate commit URL from VCS URL and commit hash. |
| 927 | + Generate patch URL from VCS URL and commit hash. |
932 | 928 | """ |
933 | 929 | if not vcs_url or not commit_hash: |
934 | 930 | return None |
935 | 931 |
|
936 | 932 | vcs_url = vcs_url.rstrip("/") |
937 | 933 |
|
938 | 934 | if vcs_url.startswith("https://github.com"): |
939 | | - return f"{vcs_url}/commit/{commit_hash}" |
| 935 | + return f"{vcs_url}/commit/{commit_hash}.patch" |
940 | 936 | elif vcs_url.startswith("https://gitlab.com"): |
941 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 937 | + return f"{vcs_url}/-/commit/{commit_hash}.patch" |
| 938 | + elif vcs_url.startswith("https://bitbucket.org"): |
| 939 | + return f"{vcs_url}/-/commit/{commit_hash}/raw" |
942 | 940 | elif vcs_url.startswith("https://codeberg.org"): |
943 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 941 | + return f"{vcs_url}/-/commit/{commit_hash}.patch" |
944 | 942 | elif vcs_url.startswith("https://android.googlesource.com"): |
945 | | - return f"{vcs_url}/+/{commit_hash}" |
946 | | - elif vcs_url.startswith("https://bitbucket.org"): |
947 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 943 | + return f"{vcs_url}/+/{commit_hash}%5E%21?format=TEXT" |
948 | 944 | elif vcs_url.startswith("https://git.kernel.org"): |
949 | 945 | return f"{vcs_url}/patch/?id={commit_hash}" |
950 | 946 | return |
0 commit comments