Repository: pypi/warehouse

Issue:
GitHub repository URLs that contain a '.git' suffix in the repository name segment are not normalized
<!--
    NOTE: This issue should be for problems with PyPI itself, including:
    * [x] pypi.org
    * [x] test.pypi.org
    * [ ] files.pythonhosted.org
-->

**Describe the bug**
Python packages may include a list of project URLs in their metadata, and when PyPi detects a GitHub-related project URL, it attempts to retrieve statistical information (number of stars, forks, and so on) from the repository by using the GitHub API. 

It is valid for a GitHub repository to specify a URL that contains a `.git` suffix in the repository name part -- for example, `https://github.com/pypi/warehouse.git/`.

This is most commonly found in `git` `remote` references in cloned GitHub repositories, where the  remote reference typically includes the `.git` repository name suffix (it's also part of the HTTPS clone URL that GitHub suggests when using their web UI).

However, the GitHub API expects the repository name to be 'normalized' -- that is, repository type suffixes should not appear.  So to follow the previous example, the repository name `warehouse` (part of organization name `pypi`) should be provided as the repository name when retrieving statistics for this repository.

PyPi doesn't currently handle project URLs that include the `.git` suffix gracefully, and may display broken links and empty statistical fields for affected packages:

![image](https://user-images.githubusercontent.com/55152140/210579958-b58e7f73-0e9f-4cac-9575-3a1e8da7bc69.png)

**Expected behavior**
The `.git` suffix in GitHub repository names could be detected and removed so that statistics can be retrieved for packages that include it within a project URL.

**To Reproduce**
The problem is currently visible following the latest release of `arcana-core` at v0.8.6 here:

- https://pypi.org/project/arcana-core/

And the repository URL configured for that release is visible here:

- https://github.com/ArcanaFramework/arcana-core/blob/238aa5abc46d613b0c5f12fcade354ee0db9feba/pyproject.toml#L66

(note the `.git` suffix in the repository name)

**My Platform**
<!--
    Any details about your specific platform:
    * [ ] If the problem is in the browser, what browser, version, and OS?
    * [ ] If the problem is with a command-line tool, what version of that tool?
    * [ ] If the problem is with connecting to PyPI, include some details about
      your network, including SSL/TLS implementation in use, internet service
      provider, and if there are any firewalls or proxies in use.
-->
N/A

**Additional context**
Similar to (and may include changes in a similar part of the code) to #12725.


Discussion:

Resolving patch:
diff --git a/warehouse/packaging/models.py b/warehouse/packaging/models.py
--- a/warehouse/packaging/models.py
+++ b/warehouse/packaging/models.py
@@ -591,6 +591,8 @@ def github_repo_info_url(self):
             segments = parsed.path.strip("/").split("/")
             if parsed.netloc in {"github.com", "www.github.com"} and len(segments) >= 2:
                 user_name, repo_name = segments[:2]
+                if repo_name.endswith(".git"):
+                    repo_name = repo_name.removesuffix(".git")
                 return f"https://api.github.com/repos/{user_name}/{repo_name}"
 
     @property


Test patch:
diff --git a/tests/unit/packaging/test_models.py b/tests/unit/packaging/test_models.py
--- a/tests/unit/packaging/test_models.py
+++ b/tests/unit/packaging/test_models.py
@@ -430,6 +430,14 @@ def test_acl(self, db_session):
             ("https://google.com/pypi/warehouse/tree/main", None),
             ("https://google.com", None),
             ("incorrect url", None),
+            (
+                "https://www.github.com/pypi/warehouse.git",
+                "https://api.github.com/repos/pypi/warehouse",
+            ),
+            (
+                "https://www.github.com/pypi/warehouse.git/",
+                "https://api.github.com/repos/pypi/warehouse",
+            ),
         ],
     )
     def test_github_repo_info_url(self, db_session, home_page, expected):