From 581f2fa94fead148baae9df91f88f5c303dc406f Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: May 25 2020 08:35:47 +0000
Subject: www: repoinfo page


Fixes: https://pagure.io/koji/issue/2181

---

diff --git a/www/kojiweb/buildrootinfo.chtml b/www/kojiweb/buildrootinfo.chtml
index e04781a..7d1d4de 100644
--- a/www/kojiweb/buildrootinfo.chtml
+++ b/www/kojiweb/buildrootinfo.chtml
@@ -29,7 +29,7 @@
       <th>Retired</th><td>$util.formatTimeLong($buildroot.retire_event_time)</td>
     </tr>
     <tr>
-      <th>Repo ID</th><td>$buildroot.repo_id</td>
+      <th>Repo ID</th><td><a href="repoinfo?repoID=$buildroot.repo_id">$buildroot.repo_id</a></td>
     </tr>
     <tr>
       <th>Repo Tag</th><td><a href="taginfo?tagID=$buildroot.tag_id">$buildroot.tag_name</a></td>
diff --git a/www/kojiweb/index.py b/www/kojiweb/index.py
index d27e4f0..d6b847a 100644
--- a/www/kojiweb/index.py
+++ b/www/kojiweb/index.py
@@ -2521,3 +2521,22 @@ def watchlogs(environ, taskID):
 </html>
 """ % values
     return html
+
+
+def repoinfo(environ, repoID):
+    values = _initValues(environ, 'Repo Info', 'tags')
+    server = _getServer(environ)
+
+    values['repo_id'] = repoID
+    repo_info = server.repoInfo(repoID, strict=False)
+    values['repo'] = repo_info
+    if repo_info:
+        topurl = environ['koji.options']['KojiFilesURL']
+        pathinfo = koji.PathInfo(topdir=topurl)
+        if repo_info['dist']:
+            values['url'] = pathinfo.distrepo(repo_info['id'], repo_info['tag_name'])
+        else:
+            values['url'] = pathinfo.repo(repo_info['id'], repo_info['tag_name'])
+        values['repo_json'] = os.path.join(pathinfo.repo(repo_info['id'], repo_info['tag_name']),
+                                           'repo.json')
+    return _genHTML(environ, 'repoinfo.chtml')
diff --git a/www/kojiweb/repoinfo.chtml b/www/kojiweb/repoinfo.chtml
new file mode 100644
index 0000000..afbcfe0
--- /dev/null
+++ b/www/kojiweb/repoinfo.chtml
@@ -0,0 +1,26 @@
+#import koji
+#from kojiweb import util
+
+#include "includes/header.chtml"
+
+<h4>Information for repo $repo_id</h4>
+
+#if $repo
+<table>
+  <tr><th>ID</th><td>$repo.id</td><th></tr>
+  <tr><th>Tag</th><td><a href="taginfo?tagID=$repo.tag_id">$repo.tag_name</a></td></tr>
+  #set $state = $util.repoState($repo.state)
+  <tr><th>State</th><td class="repo$state">$state</td></tr>
+  <tr><th>Event</th><td>$repo.create_event ($util.formatTimeLong($repo.creation_time))</td></tr>
+  #if $repo.state != koji.REPO_STATES['DELETED']
+  <tr><th>URL</th><td><a href="$url">repodata</a></td></tr>
+  <tr><th>Repo json</th><td><a href="$repo_json">repo.json</a></td></tr>
+  #end if
+  <tr><th>Dist repo?</th><td class="$str($repo.dist).lower()">#if $repo.dist then 'yes' else 'no'#</td></tr>
+</table>
+#else
+Repo $repo_id not found.
+#end if
+
+
+#include "includes/footer.chtml"
diff --git a/www/kojiweb/taginfo.chtml b/www/kojiweb/taginfo.chtml
index 6bf5a18..63b1fb9 100644
--- a/www/kojiweb/taginfo.chtml
+++ b/www/kojiweb/taginfo.chtml
@@ -112,7 +112,12 @@
     </tr>
     #end if
     <tr>
-      <th>Repo&nbsp;created</th><td>#if $repo then $util.formatTimeRSS($repo.creation_time) else ''#</td>
+      <th>Repo&nbsp;created</th>
+      <td>
+      #if $repo
+        <a href="repoinfo?repoID=$repo.id">$util.formatTimeRSS($repo.creation_time)</a>
+      #end if
+      </td>
     </tr>
     <tr>
       <th>Packages</th>
diff --git a/www/kojiweb/taskinfo_params.chtml b/www/kojiweb/taskinfo_params.chtml
index eed2f6b..b83a4d2 100644
--- a/www/kojiweb/taskinfo_params.chtml
+++ b/www/kojiweb/taskinfo_params.chtml
@@ -184,17 +184,17 @@ $printOpts($params[2])
 #end if
 #elif $task.method == 'distRepo'
 <strong>Tag:</strong> <a href="taginfo?tagID=$tag.id">$tag.name</a><br/>
-<strong>Repo ID:</strong> <a href="$pathinfo.distrepo($params[1],$tag.name)">$params[1]</a></br>
+<strong>Repo ID:</strong> <a href="repoinfo?repoID=$params[1]">$params[1]</a></br>
 <strong>Keys:</strong> $printValue(0, $params[2])<br/>
 $printOpts($params[3])
 #elif $task.method == 'prepRepo'
 <strong>Tag:</strong> <a href="taginfo?tagID=$params[0].id">$params[0].name</a>
 #elif $task.method == 'createrepo'
-<strong>Repo ID:</strong> $params[0]<br/>
+<strong>Repo ID:</strong> <a href="repoinfo?repoID=$params[0]">$params[0]</a><br/>
 <strong>Arch:</strong> $params[1]<br/>
 #set $oldrepo = $params[2]
 #if $oldrepo
-    <strong>Old Repo ID:</strong> $oldrepo.id<br/>
+    <strong>Old Repo ID:</strong> <a href="repoinfo?repoID=$oldrepo.id">$oldrepo.id</a><br/>
     <strong>Old Repo Creation:</strong> $koji.formatTimeLong($oldrepo.creation_time)<br/>
 #end if
 #if $len($params) > 4 and $params[4]
@@ -202,7 +202,7 @@ $printOpts($params[3])
 #end if
 #elif $task.method == 'createdistrepo'
 <strong>Tag:</strong> <a href="taginfo?tagID=$tag.id">$tag.name</a><br/>
-<strong>Repo ID:</strong> <a href="$pathinfo.distrepo($params[1],$tag.name)">$params[1]</a></br>
+<strong>Repo ID:</strong> <a href="repoinfo?repoID=$params[1]">$params[1]</a></br>
 <strong>Arch:</strong> $printValue(0, $params[2])<br/>
 <strong>Keys:</strong> $printValue(0, $params[3])<br/>
 <strong>Options:</strong> $printMap($params[4], '&nbsp;&nbsp;&nbsp;&nbsp;')
diff --git a/www/lib/kojiweb/util.py b/www/lib/kojiweb/util.py
index 90f569f..8d9f5f3 100644
--- a/www/lib/kojiweb/util.py
+++ b/www/lib/kojiweb/util.py
@@ -447,6 +447,11 @@ def repoStateName(stateID):
         return 'unknown'
 
 
+def repoState(stateID):
+    """Convert a numeric repo state into a readable name"""
+    return koji.REPO_STATES[stateID].lower()
+
+
 def taskState(stateID):
     """Convert a numeric task state into a readable name"""
     return koji.TASK_STATES[stateID].lower()
diff --git a/www/static/koji.css b/www/static/koji.css
index aa0b912..b2535f9 100644
--- a/www/static/koji.css
+++ b/www/static/koji.css
@@ -387,7 +387,7 @@ tr.row-even td.tree span.treeLabel {
     background-color: #eee;
 }
 
-.taskfree {
+.taskfree, .repoinit {
     color: #30c;
 }
 
@@ -395,11 +395,11 @@ tr.row-even td.tree span.treeLabel {
     color: #f60;
 }
 
-.taskclosed {
+.taskclosed, .repoready {
     color: #0c0;
 }
 
-.taskcanceled {
+.taskcanceled, .repoexpired {
     color: #c90;
 }
 
@@ -407,7 +407,7 @@ tr.row-even td.tree span.treeLabel {
     color: #c0f;
 }
 
-.taskfailed {
+.taskfailed, .repodeleted, .repoproblem {
     color: #c00;
 }
 

