Blob Blame Raw
From 7cef29d843fabce5abab317303e9016c91414913 Mon Sep 17 00:00:00 2001
From: Ondrej Nosek <onosek@redhat.com>
Date: Fri, 24 May 2019 11:21:34 +0200
Subject: [PATCH] Show nvr in container-build

JIRA: COMPOSE-3481

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
---
 pyrpkg/__init__.py | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 291b9ac..0348420 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -3036,6 +3036,39 @@ class Commands(object):
         # Run the command
         self._run_command(cmd, shell=True)
 
+    def _process_koji_task_result(self, task_id):
+        """
+        Parse and modify output from brew/koji containing information about
+        task (and eventually builds).
+
+        :param int task_id: id of the current task
+        :return: record containing information about repositories, builds and nvrs
+        :rtype: dict(str, str)
+        """
+        koji_result = self.kojisession.getTaskResult(task_id)
+        if not koji_result:
+            raise rpkgError('Unknown task: %s' % task_id)
+        koji_builds = koji_result.get("koji_builds", [])
+        koji_result["koji_builds"] = []
+
+        for build_id in koji_builds:
+            try:
+                build_id = int(build_id)
+            except ValueError:
+                raise rpkgError("Can not convert 'build_id' to integer: %s" % build_id)
+
+            bdata = self.kojisession.getBuild(build_id)
+            if not bdata:
+                raise rpkgError('Unknown build: %s' % build_id)
+            nvr = bdata.get("nvr")
+            if nvr:
+                koji_result.setdefault("nvrs", []).append(nvr)
+
+            koji_result["koji_builds"].append(
+                "%s/buildinfo?buildID=%d" % (self.kojiweburl, build_id))
+
+        return koji_result
+
     def container_build_koji(self, target_override=False, opts={},
                              kojiconfig=None, kojiprofile=None,
                              build_client=None,
@@ -3105,14 +3138,7 @@ class Commands(object):
             if not nowait:
                 rv = koji_task_watcher(self.kojisession, [task_id])
                 if rv == 0:
-                    result = self.kojisession.getTaskResult(task_id)
-                    try:
-                        result["koji_builds"] = [
-                            "%s/buildinfo?buildID=%s" % (self.kojiweburl,
-                                                         build_id)
-                            for build_id in result.get("koji_builds", [])]
-                    except TypeError:
-                        pass
+                    result = self._process_koji_task_result(task_id)
                     log_result(self.log.info, result)
 
         finally:
-- 
2.20.1