Repository: packit/packit-service
Issue: Cannot run testing farm on push

Sentry Issue: [PACKIT-SERVICE-48X](https://sentry.io/organizations/red-hat-0p/issues/3227716213/?referrer=github_integration)

```
AssertionError: None
(12 additional frame(s) were not displayed)
...
  File "ogr/abstract.py", line 107, in wrapper
    return function(*args, **kwargs)
  File "ogr/utils.py", line 199, in indirectly_called
    return specialized_function(self, *args, **kwargs)
  File "ogr/abstract.py", line 107, in wrapper
    return function(*args, **kwargs)
  File "ogr/services/github/pull_request.py", line 179, in get
    pr = project.github_repo.get_pull(number=pr_id)
  File "github/Repository.py", line 2745, in get_pull
    assert isinstance(number, int), number
```

In testing farm helper we have a property for acquiring `fmf_url`, current behavior checks metadata of job for the URL and if not provided, then gets source_project from PR. In case of `commit` trigger, there is no PR, therefore it fails.

TODO:
- [ ] Fix the property
  - [ ] Check if there is a PR to be fetched
  - [ ] Return correct URL for `commit` trigger

Changed files:
tests/unit/test_testing_farm.py, packit_service/worker/helpers/testing_farm.py

diff --git a/packit_service/worker/helpers/testing_farm.py b/packit_service/worker/helpers/testing_farm.py
index 9c469fd4..4daf9758 100644
--- a/packit_service/worker/helpers/testing_farm.py
+++ b/packit_service/worker/helpers/testing_farm.py
@@ -99,7 +99,13 @@ class TestingFarmJobHelper(CoprBuildJobHelper):
     def fmf_url(self) -> str:
         return (
             self.job_config.metadata.fmf_url
-            or self.project.get_pr(self.metadata.pr_id).source_project.get_web_url()
+            or (
+                self.metadata.pr_id
+                and self.project.get_pr(
+                    self.metadata.pr_id
+                ).source_project.get_web_url()
+            )
+            or self.project.get_web_url()
         )
 
     @property
diff --git a/tests/unit/test_testing_farm.py b/tests/unit/test_testing_farm.py
index 50534eca..08e49c9c 100644
--- a/tests/unit/test_testing_farm.py
+++ b/tests/unit/test_testing_farm.py
@@ -736,3 +736,47 @@ def test_trigger_build(copr_build, run_new_build):
         job_config_trigger_type=JobConfigTriggerType.pull_request
     )
     tf_handler.run()
+
+
+@pytest.mark.parametrize(
+    ("metadata_url", "pr_id", "fmf_url"),
+    [
+        # custom set URL
+        ("https://custom.xyz/mf/fmf/", None, "https://custom.xyz/mf/fmf/"),
+        # PR, from fork
+        (None, 42, "https://github.com/mf/packit"),
+        # if from branch
+        (None, None, "https://github.com/packit/packit"),
+    ],
+)
+def test_fmf_url(metadata_url, pr_id, fmf_url):
+    job_config = flexmock(type=JobType.tests, metadata=flexmock(fmf_url=metadata_url))
+    metadata = flexmock(pr_id=pr_id)
+
+    git_project = flexmock()
+    if metadata_url is not None:
+        git_project.should_receive("get_pr").never()
+    elif pr_id is not None:
+        git_project.should_receive("get_pr").with_args(pr_id).and_return(
+            flexmock(
+                source_project=flexmock()
+                .should_receive("get_web_url")
+                .and_return(fmf_url)
+                .mock()
+            )
+        )
+    else:
+        git_project.should_receive("get_web_url").and_return(
+            "https://github.com/packit/packit"
+        ).once()
+
+    helper = TFJobHelper(
+        service_config=flexmock(comment_command_prefix="/packit-dev"),
+        package_config=flexmock(jobs=[]),
+        project=git_project,
+        metadata=metadata,
+        db_trigger=flexmock(),
+        job_config=job_config,
+    )
+
+    assert helper.fmf_url == fmf_url