|
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 |
|
@@ -871,49 +872,44 @@ def group_advisories_by_content(advisories): |
871 | 872 | return grouped |
872 | 873 |
|
873 | 874 |
|
874 | | -def generate_patch_url(vcs_url, commit_hash): |
| 875 | +def generate_commit_url(vcs_url, commit_hash): |
875 | 876 | """ |
876 | | - Generate patch URL from VCS URL and commit hash. |
| 877 | + Generate commit URL from VCS URL and commit hash. |
877 | 878 | """ |
878 | 879 | if not vcs_url or not commit_hash: |
879 | | - return None |
| 880 | + return |
880 | 881 |
|
881 | | - vcs_url = vcs_url.rstrip("/") |
| 882 | + purl = url2purl(vcs_url) |
| 883 | + if not purl: |
| 884 | + return |
882 | 885 |
|
883 | | - if vcs_url.startswith("https://github.com"): |
884 | | - return f"{vcs_url}/commit/{commit_hash}.patch" |
885 | | - elif vcs_url.startswith("https://gitlab.com"): |
886 | | - return f"{vcs_url}/-/commit/{commit_hash}.patch" |
887 | | - elif vcs_url.startswith("https://codeberg.org"): |
888 | | - return f"{vcs_url}/-/commit/{commit_hash}.patch" |
889 | | - elif vcs_url.startswith("https://android.googlesource.com"): |
890 | | - return f"{vcs_url}/+/{commit_hash}%5E%21?format=TEXT" |
891 | | - elif vcs_url.startswith("https://bitbucket.org"): |
892 | | - return f"{vcs_url}/-/commit/{commit_hash}/raw" |
893 | | - elif vcs_url.startswith("https://git.kernel.org"): |
894 | | - return f"{vcs_url}/patch/?id={commit_hash}" |
895 | | - return |
| 886 | + base_purl = get_core_purl(str(purl)) |
| 887 | + purl_with_version = PackageURL( |
| 888 | + type=base_purl.type, namespace=base_purl.namespace, name=base_purl.name, version=commit_hash |
| 889 | + ) |
| 890 | + commit_url = purl2url(str(purl_with_version)) |
| 891 | + return commit_url |
896 | 892 |
|
897 | 893 |
|
898 | | -def generate_commit_url(vcs_url, commit_hash): |
| 894 | +def generate_patch_url(vcs_url, commit_hash): |
899 | 895 | """ |
900 | | - Generate commit URL from VCS URL and commit hash. |
| 896 | + Generate patch URL from VCS URL and commit hash. |
901 | 897 | """ |
902 | 898 | if not vcs_url or not commit_hash: |
903 | 899 | return None |
904 | 900 |
|
905 | 901 | vcs_url = vcs_url.rstrip("/") |
906 | 902 |
|
907 | 903 | if vcs_url.startswith("https://github.com"): |
908 | | - return f"{vcs_url}/commit/{commit_hash}" |
| 904 | + return f"{vcs_url}/commit/{commit_hash}.patch" |
909 | 905 | elif vcs_url.startswith("https://gitlab.com"): |
910 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 906 | + return f"{vcs_url}/-/commit/{commit_hash}.patch" |
| 907 | + elif vcs_url.startswith("https://bitbucket.org"): |
| 908 | + return f"{vcs_url}/-/commit/{commit_hash}/raw" |
911 | 909 | elif vcs_url.startswith("https://codeberg.org"): |
912 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 910 | + return f"{vcs_url}/-/commit/{commit_hash}.patch" |
913 | 911 | elif vcs_url.startswith("https://android.googlesource.com"): |
914 | | - return f"{vcs_url}/+/{commit_hash}" |
915 | | - elif vcs_url.startswith("https://bitbucket.org"): |
916 | | - return f"{vcs_url}/-/commit/{commit_hash}" |
| 912 | + return f"{vcs_url}/+/{commit_hash}%5E%21?format=TEXT" |
917 | 913 | elif vcs_url.startswith("https://git.kernel.org"): |
918 | 914 | return f"{vcs_url}/patch/?id={commit_hash}" |
919 | 915 | return |
0 commit comments