Repository: packit/ogr
Issue: GitlabService used for 'https://src.fedoraproject.org/rpms/python-gitlab'

Sentry Issue: [PACKIT-SERVICE-3XZ](https://sentry.io/organizations/red-hat-0p/issues/2848306023/?referrer=github_integration)

```
OgrException: Instance of type GitlabService matching instance url 'https://src.fedoraproject.org/rpms/python-gitlab' was not provided.
  File "packit/config/config.py", line 213, in _get_project
    project = get_project(
  File "ogr/factory.py", line 103, in get_project
    raise OgrException(

PackitConfigException: ("Authentication for url 'https://src.fedoraproject.org/rpms/python-gitlab' is missing in the config.", OgrException("Instance of type GitlabService matching instance url 'https://src.fedoraproject.org/rpms/python-gitlab' was not provided."))
  File "packit_service/worker/tasks.py", line 76, in process_message
    return SteveJobs().process_message(event=event, topic=topic, source=source)
  File "packit_service/worker/jobs.py", line 395, in process_message
    if not event_object.project:
  File "packit/config/config.py", line 219, in _get_project
    raise PackitConfigException(msg, ex)
```

@lachmanfrantisek:
We need to improve the parsing to cover this edge case so the `PagureService` is used for the `https://src.fedoraproject.org/rpms/python-gitlab` URL instead.

* The mapping is done using this decorator:
  *  https://github.com/packit/ogr/blob/86292f2dd56ae778e1864483449eb228c92ed2b2/ogr/factory.py#L14-L51
* Specifically, for GitLab, we just `gitlab`:
  * https://github.com/packit/ogr/blob/86292f2dd56ae778e1864483449eb228c92ed2b2/ogr/services/gitlab/service.py#L19-L21
* And here, the mapping is used:
  * https://github.com/packit/ogr/blob/86292f2dd56ae778e1864483449eb228c92ed2b2/ogr/factory.py#L112-L137
* The related test cases (please, add the problematic URL to the test suite):
  * https://github.com/packit/ogr/blob/86292f2dd56ae778e1864483449eb228c92ed2b2/tests/unit/test_factory.py#L20-L45
  
Some notes about the solution:
* Ideally, we would like to have something generic for GitLab to cover various instances like `gitlab.com`, `https://gitlab.gnome.org/` and `https://gitlab.freedesktop.org/` without a need to explicitly have a list of them. Some better argument?
* The `get_service_class_or_none` function returns just one value, but in this case, more services can match -- we can think about a rule to pick the best one.
* Or, fix the core issue -- check only the hostname.
* Or anything else what can solve this.

Changed files:
tests/unit/test_factory.py, ogr/factory.py

diff --git a/ogr/factory.py b/ogr/factory.py
index f773ac4..39cae17 100644
--- a/ogr/factory.py
+++ b/ogr/factory.py
@@ -130,8 +130,9 @@ def get_service_class_or_none(
     if service_mapping_update:
         mapping.update(service_mapping_update)
 
+    parsed_url = parse_git_repo(url)
     for service, service_kls in mapping.items():
-        if service in url:
+        if service in parsed_url.hostname:
             return service_kls
 
     return None
diff --git a/tests/unit/test_factory.py b/tests/unit/test_factory.py
index a6ba9d6..fc752b5 100644
--- a/tests/unit/test_factory.py
+++ b/tests/unit/test_factory.py
@@ -38,6 +38,22 @@ from ogr.services.pagure import PagureProject
         ("https://pagure.something.com/ogr", None, PagureService),
         ("https://gitlab.com/someone/project", None, GitlabService),
         ("https://gitlab.abcd.def/someone/project", None, GitlabService),
+        (
+            "https://src.fedoraproject.org/rpms/golang-gitlab-flimzy-testy",
+            None,
+            PagureService,
+        ),
+        (
+            "https://src.stg.fedoraproject.org/rpms/golang-gitlab-flimzy-testy",
+            None,
+            PagureService,
+        ),
+        ("https://src.fedoraproject.org/rpms/python-gitlab", None, PagureService),
+        (
+            "https://src.fedoraproject.org/rpms/golang-gitlab-yawning-utls",
+            None,
+            PagureService,
+        ),
     ],
 )
 def test_get_service_class(url, mapping, result):