Repository: packit-service/packit
Pull request #797 (2020-04-15 09:18:58)

Rename job metadata dist_git_branch to dist_git_branches 
`dist_git_branch` (and older `dist-git-branch`) are still accepted, but deprecated

We need the key to be able to accept a list of strings (branches), not just one string.
Internally it's (and also `targets` now) stored as `Set[str]`, but it's loaded as `List[str]` from config (yaml doesn't know sets).

packit-as-a-service[bot]: Congratulations! One of the builds has completed. :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-797`
* And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.
softwarefactory-project-zuul[bot]: Build failed.

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/3b04c598b3cd4cb7b76cfa4148a2431f) : SUCCESS in 2m 32s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/306c27504e4042b2a2750c46f622a13b) : FAILURE in 6m 31s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/94f5a7ec878940248173345ba5ce906c) : FAILURE in 6m 09s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/a3c2612c2fe84dfea5f3a823e761a2ad) : FAILURE in 6m 47s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/ab41bc5ee77c4cabb6e9639fb5e692f1) : SUCCESS in 2m 07s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/67465f19aec14e708b15ac1c4677db45) : SUCCESS in 2m 23s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/5d3258e06173452bbd013b175c058cee) : SUCCESS in 2m 40s
- [reverse-dep-packit-service-tests ](https://softwarefactory-project.io/zuul/t/local/build/b39905e331e344c9b760d7ccd729434c) : FAILURE in 3m 38s

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

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/f048b92472c048d3b2c77a52d11d8522) : SUCCESS in 2m 07s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/137d2084f05241dcb01b8b1cd8288c6c) : FAILURE in 5m 04s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/191ee70c8dda47e7aa4258bcfd9580b8) : FAILURE in 7m 42s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/e345bd2d688c4d0d9a6903283ab21c7b) : FAILURE in 7m 00s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/c9dc3e34d24f406db876c60ab4c859d3) : SUCCESS in 1m 53s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/416c0cfc242d45139ff9fd4a1aa4fa3d) : SUCCESS in 2m 30s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/d81f53415be24828b7300a600fff697f) : SUCCESS in 2m 36s
- [reverse-dep-packit-service-tests ](https://softwarefactory-project.io/zuul/t/local/build/493c0922595e498296a1635f0fe6d9d3) : FAILURE in 3m 20s

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

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/8b02b7d5d15e405a81b921f323220a32) : SUCCESS in 1m 56s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/38446cdc22a649ff88c90015ef8e3c82) : SUCCESS in 7m 39s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/d18bbd7453144e6eba56d4f5bd07bcf3) : FAILURE in 7m 57s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/7e0e38f79fc7480da49572d0be9f2c71) : FAILURE in 8m 05s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/3ef655670e47437789e76992e65e9826) : SUCCESS in 1m 49s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/a4a7ef2d6fc74dbcaae40b9b4322513c) : SUCCESS in 2m 30s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/941fc44d48b94dada900c7bf3009ed20) : SUCCESS in 2m 23s
- [reverse-dep-packit-service-tests ](https://softwarefactory-project.io/zuul/t/local/build/8619ea2a8328473cb1b8711ece14490f) : FAILURE in 3m 32s

jpopelka: > tests/unit/test_package_config.py::test_package_config_validate[raw3-True] FAILED

I don't get that - it passes for me locally, even after --no-cache rebuild
softwarefactory-project-zuul[bot]: Build failed.

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/e0fc9c223d8c4ed1a021166b58712b53) : SUCCESS in 2m 03s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/03be2a0e140c42d0b30ca1329c7a15ca) : SUCCESS in 8m 15s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/c4dbd37b0aec4344b27c59690072ebd5) : FAILURE in 8m 03s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/f6db09c49d8e485d901854739c380ba7) : FAILURE in 8m 46s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/23dede9b1b3a451bae8879c491270494) : SUCCESS in 2m 28s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/a4e7f9dae96f4ae096875185778f3dcc) : SUCCESS in 2m 19s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/7031b085aecc4da48b5a6a4d8ca7e5e7) : SUCCESS in 2m 27s
- [reverse-dep-packit-service-tests ](https://softwarefactory-project.io/zuul/t/local/build/47a41dfdacd24386b6324a268cb808d1) : FAILURE in 3m 35s

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

- [packit-pre-commit ](https://softwarefactory-project.io/zuul/t/local/build/b85c70475bf141a185ead727a0d20d43) : SUCCESS in 2m 37s
- [packit-tests-rpm ](https://softwarefactory-project.io/zuul/t/local/build/9c0695dad38e4e53bc0a061cc029d054) : SUCCESS in 8m 04s
- [packit-tests-pip-deps ](https://softwarefactory-project.io/zuul/t/local/build/6daa6eda57a7462db64e8cfdc5d38f79) : FAILURE in 7m 36s
- [packit-tests-git-master ](https://softwarefactory-project.io/zuul/t/local/build/7e8568410e5b45c38c7c7a3ef7f21d57) : FAILURE in 8m 44s
- [packit-tests-rpm-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/e43750d53c0640179606eca86324bb64) : SUCCESS in 1m 57s
- [packit-tests-pip-deps-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/e4b7fb4dca55416f985a0115098f62ea) : SUCCESS in 2m 24s
- [packit-tests-git-master-sess-rec ](https://softwarefactory-project.io/zuul/t/local/build/4d9d77faaa514ce89ae4dc086a05678a) : SUCCESS in 2m 37s
- [reverse-dep-packit-service-tests ](https://softwarefactory-project.io/zuul/t/local/build/750e47ad2be84edca26ff39e06aff15a) : FAILURE in 3m 33s


Patch:
diff --git a/.packit.yaml b/.packit.yaml
index 68df8a78..1e56dadf 100644
--- a/.packit.yaml
+++ b/.packit.yaml
@@ -17,7 +17,7 @@ jobs:
   - job: propose_downstream
     trigger: release
     metadata:
-      dist_git_branch: fedora-all
+      dist_git_branches: fedora-all
   - job: sync_from_downstream
     trigger: commit
   - job: copr_build
diff --git a/packit/config/job_config.py b/packit/config/job_config.py
index 395f08c6..2e62a6a5 100644
--- a/packit/config/job_config.py
+++ b/packit/config/job_config.py
@@ -20,13 +20,14 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-import logging
+
 from enum import Enum
-from typing import List
+from logging import getLogger
+from typing import List, Set
 
 from packit.exceptions import PackitConfigException
 
-logger = logging.getLogger(__name__)
+logger = getLogger(__name__)
 
 
 class JobType(Enum):
@@ -58,7 +59,7 @@ class JobMetadataConfig:
         timeout: int = 7200,
         owner: str = None,
         project: str = None,
-        dist_git_branch: str = None,
+        dist_git_branches: List[str] = None,
         branch: str = None,
         scratch: bool = False,
     ):
@@ -67,25 +68,28 @@ class JobMetadataConfig:
         :param timeout: copr_build, give up watching a build after timeout, defaults to 7200s
         :param owner: copr_build, a namespace in COPR where the build should happen
         :param project: copr_build, a name of the copr project
-        :param dist_git_branch: propose_downstream, a branch in dist-git where packit should work
+        :param dist_git_branches: propose_downstream, branches in dist-git where packit should work
         :param branch: for `commit` trigger to specify the branch name
         :param scratch: if we want to run scratch build in koji
         """
-        self.targets = targets or []
+        self.targets: Set[str] = set(targets) if targets else set()
         self.timeout: int = timeout
         self.owner: str = owner
         self.project: str = project
-        self.dist_git_branch: str = dist_git_branch
+        self.dist_git_branches: Set[str] = set(
+            dist_git_branches
+        ) if dist_git_branches else set()
         self.branch: str = branch
         self.scratch: bool = scratch
 
     def __repr__(self):
         return (
-            f"JobMetadataConfig(targets={self.targets}, "
+            f"JobMetadataConfig("
+            f"targets={self.targets}, "
             f"timeout={self.timeout}, "
             f"owner={self.owner}, "
             f"project={self.project}, "
-            f"dist_git_branch={self.dist_git_branch},"
+            f"dist_git_branches={self.dist_git_branches},"
             f"branch={self.branch},"
             f"scratch={self.scratch})"
         )
@@ -100,7 +104,7 @@ class JobMetadataConfig:
             and self.timeout == other.timeout
             and self.owner == other.owner
             and self.project == other.project
-            and self.dist_git_branch == other.dist_git_branch
+            and self.dist_git_branches == other.dist_git_branches
             and self.branch == other.branch
             and self.scratch == other.scratch
         )
@@ -154,6 +158,6 @@ default_jobs = [
     JobConfig(
         type=JobType.propose_downstream,
         trigger=JobConfigTriggerType.release,
-        metadata=JobMetadataConfig(dist_git_branch="fedora-all"),
+        metadata=JobMetadataConfig(dist_git_branches=["fedora-all"]),
     ),
 ]
diff --git a/packit/schema.py b/packit/schema.py
index 8d952c43..2d0a0295 100644
--- a/packit/schema.py
+++ b/packit/schema.py
@@ -205,21 +205,23 @@ class JobMetadataSchema(Schema):
     timeout = fields.Integer()
     owner = fields.String()
     project = fields.String()
-    dist_git_branch = fields.String()
+    dist_git_branches = fields.List(fields.String())
     branch = fields.String()
     scratch = fields.Boolean()
 
     @pre_load
     def ordered_preprocess(self, data, **_):
-        if "dist-git-branch" in data:
-            logger.warning(
-                f"Job metadata key 'dist-git-branch' has been renamed to 'dist_git_branch', "
-                f"please update your configuration file."
-            )
-            data["dist_git_branch"] = data.pop("dist-git-branch")
-        if isinstance(data.get("targets"), str):
-            # allow "targets" being specified as string
-            data["targets"] = [data.pop("targets")]
+        for key in ("dist-git-branch", "dist_git_branch"):
+            if key in data:
+                logger.warning(
+                    f"Job metadata key {key!r} has been renamed to 'dist_git_branches', "
+                    f"please update your configuration file."
+                )
+                data["dist_git_branches"] = data.pop(key)
+        for key in ("targets", "dist_git_branches"):
+            if isinstance(data.get(key), str):
+                # allow key value being specified as string, convert to list
+                data[key] = [data.pop(key)]
         return data
 
     @post_load


Test patch:
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index dd27b34f..0899cb67 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -62,7 +62,7 @@ def get_job_config_full():
     return JobConfig(
         type=JobType.propose_downstream,
         trigger=JobConfigTriggerType.pull_request,
-        metadata=JobMetadataConfig(dist_git_branch="master"),
+        metadata=JobMetadataConfig(dist_git_branches=["master"]),
     )
 
 
@@ -97,7 +97,7 @@ def get_default_job_config():
         JobConfig(
             type=JobType.propose_downstream,
             trigger=JobConfigTriggerType.release,
-            metadata=JobMetadataConfig(dist_git_branch="fedora-all"),
+            metadata=JobMetadataConfig(dist_git_branches=["fedora-all"]),
         ),
     ]
 
diff --git a/tests/unit/test_package_config.py b/tests/unit/test_package_config.py
index b2562aa2..1352bce9 100644
--- a/tests/unit/test_package_config.py
+++ b/tests/unit/test_package_config.py
@@ -225,12 +225,40 @@ def test_package_config_not_equal(not_equal_package_config):
                     {
                         "job": "propose_downstream",
                         "trigger": "release",
+                        "metadata": {"dist_git_branches": ["fedora-all", "epel-8"]},
+                    }
+                ],
+            },
+            True,
+        ),
+        (
+            {
+                "specfile_path": "fedora/package.spec",
+                "jobs": [
+                    {
+                        "job": "copr_build",
+                        "trigger": "release",
                         "metadata": {"targets": "fedora-stable"},
                     }
                 ],
             },
             True,
         ),
+        (
+            {
+                "specfile_path": "fedora/package.spec",
+                "jobs": [
+                    {
+                        "job": "copr_build",
+                        "trigger": "release",
+                        "metadata": {
+                            "targets": ["fedora-stable", "fedora-development"]
+                        },
+                    }
+                ],
+            },
+            True,
+        ),
         (
             {
                 "specfile_path": "fedora/package.spec",