Repository: packit-service/packit
Pull request #621 (2019-12-04 15:30:33)

aliases: better error

softwarefactory-project-zuul[bot]: Build failed.

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/a4ceb3a551134c709bbcf059fdf2266f) : SUCCESS in 1m 50s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/7765ae2bedeb40738c3fb25fd8483383) : FAILURE in 2m 18s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/f1c79e57659b405080885947e830b561) : FAILURE in 3m 08s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/77ec45da6a0c46658fdf4117aa4b741a) : FAILURE in 2m 49s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/90553453752944bab2f205479719eb36) : SUCCESS in 2m 03s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/24fab7e4e2df47b59b826d1a77b7e914) : SUCCESS in 2m 35s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/69ff868955124b91b21d91e65e37dafb) : SUCCESS in 2m 54s

packit-as-a-service[bot]: Congratulations! The build [has finished](https://copr-be.cloud.fedoraproject.org/results/packit/packit-service-packit-621/fedora-31-x86_64/01123896-packit/builder-live.log.gz) successfully. :champagne:

You can install the built RPMs by following these steps:

* `sudo yum install -y dnf-plugins-core` on RHEL 8
* `sudo dnf install -y dnf-plugins-core` on Fedora
* `dnf copr enable packit/packit-service-packit-621`
* And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Patch:
diff --git a/packit/config/aliases.py b/packit/config/aliases.py
index 7eeec462..2cf9b2f1 100644
--- a/packit/config/aliases.py
+++ b/packit/config/aliases.py
@@ -67,15 +67,20 @@ def get_build_targets(*name: str, default=DEFAULT_VERSION) -> Set[str]:
     possible_sys_and_versions: Set[str] = set([])
     for one_name in names:
         name_split = one_name.rsplit("-", maxsplit=2)
+        l_name_split = len(name_split)
 
-        if len(name_split) < 2:  # only one part
+        if l_name_split < 2:  # only one part
             # => cannot guess anything other than rawhide
             if "rawhide" in one_name:
                 sys_name, version, architecture = "fedora", "rawhide", "x86_64"
             else:
-                raise PackitException(f"Cannot get build target from '{one_name}'.")
+                err_msg = (
+                    "Cannot get build target from '{one_name}'"
+                    f", packit understands values like these: '{list(ALIASES.keys())}'."
+                )
+                raise PackitException(err_msg.format(one_name=one_name))
 
-        elif len(name_split) == 2:  # "name-version"
+        elif l_name_split == 2:  # "name-version"
             sys_name, version = name_split
             architecture = "x86_64"  # use the x86_64 as a default
 


Test patch:
diff --git a/tests/unit/test_config_aliases.py b/tests/unit/test_config_aliases.py
index 193923b9..ef7fc536 100644
--- a/tests/unit/test_config_aliases.py
+++ b/tests/unit/test_config_aliases.py
@@ -1,6 +1,7 @@
 import pytest
 
-from packit.config.aliases import get_versions, get_build_targets, get_branches
+from packit.config.aliases import get_versions, get_build_targets, get_branches, ALIASES
+from packit.exceptions import PackitException
 
 
 @pytest.mark.parametrize(
@@ -35,6 +36,7 @@ def test_get_versions_from_multiple_values(names, versions):
 @pytest.mark.parametrize(
     "name,targets",
     [
+        ("rawhide", {"fedora-rawhide-x86_64"}),
         ("fedora-29", {"fedora-29-x86_64"}),
         ("epel-8", {"epel-8-x86_64"}),
         ("fedora-rawhide", {"fedora-rawhide-x86_64"}),
@@ -64,6 +66,18 @@ def test_get_build_targets(name, targets):
     assert get_build_targets(name) == targets
 
 
+def test_get_build_targets_invalid_input():
+    name = "rafhajd"
+    with pytest.raises(PackitException) as ex:
+
+        get_build_targets(name)
+    err_msg = (
+        f"Cannot get build target from '{name}'"
+        f", packit understands values like these: '{list(ALIASES.keys())}'."
+    )
+    assert str(ex.value) == err_msg
+
+
 @pytest.mark.parametrize(
     "names,versions",
     [