Ural Tunaboyu has proposed merging 
~uralt/autopkgtest-cloud:autopkgtest-web-version into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~uralt/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/479106

Added a version display to the home page which shows the short commit hash (if 
there is one) of the running autopkgtest-web instance. The hash is a link to 
the commit itself on LP.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of 
~uralt/autopkgtest-cloud:autopkgtest-web-version into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index 67a4110..dd63f33 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -8,6 +8,7 @@ import json
 import os
 import re
 import sqlite3
+import subprocess
 import sys
 import traceback
 from collections import OrderedDict
@@ -50,6 +51,7 @@ setup_key(app, secret_path)
 
 db_con = None
 CONFIG = {}
+COMMIT_HASH = None
 
 ALL_UBUNTU_RELEASES = get_all_releases()
 SUPPORTED_UBUNTU_RELEASES = get_supported_releases()
@@ -80,6 +82,17 @@ def connect_db(path: str):
     db_con = sqlite3.connect(path, uri=True, check_same_thread=False)
 
 
+def get_version_info():
+    global COMMIT_HASH
+    try:
+        print("attempt version info")
+        COMMIT_HASH = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
+        print(COMMIT_HASH)
+    except subprocess.CalledProcessError:
+        # no valid git repo
+        COMMIT_HASH = "none"
+        pass
+
 def get_package_release_arch(test_id):
     """
     The opposite of get_test_id - gets the package/release/arch
@@ -367,6 +380,9 @@ def index_root():
     indexes = letters + ["lib" + l for l in letters]
     indexes.sort()
 
+    if not COMMIT_HASH:
+        get_version_info()
+
     recent = []
     for row in db_con.execute(
         "SELECT exitcode, package, release, arch, triggers, uuid "
@@ -379,7 +395,7 @@ def index_root():
         res = hc if "code" not in hc else "fail"
         recent.append((res, row[1], row[2], row[3], row[4], row[5]))
 
-    return render("browse-home.html", indexes=indexes, recent_runs=recent)
+    return render("browse-home.html", indexes=indexes, recent_runs=recent, commit_hash=COMMIT_HASH)
 
 
 # backwards-compatible path with debci that specifies the source hash
@@ -946,6 +962,7 @@ if __name__ == "__main__":
         )
 
     app.config["DEBUG"] = True
+    get_version_info()
     init_config()
     connect_db("file:%s?mode=ro" % CONFIG["database"])
     CGIHandler().run(app)
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
index e4ee001..7b88136 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-home.html
@@ -53,6 +53,11 @@
               <li>
                 <a href="{{base_url}}queues.json">Queued tests in JSON format</a>
               </li>
+              {% if commit_hash != "none" %}
+              <li>
+                autopkgtest-web version: <a href="https://git.launchpad.net/autopkgtest-cloud/commit/?id={{commit_hash}}";>{{commit_hash[:7]}}</a>
+              </li>
+              {% endif %}
             </ul>
           </div>
         </div>
-- 
Mailing list: https://launchpad.net/~canonical-ubuntu-qa
Post to     : canonical-ubuntu-qa@lists.launchpad.net
Unsubscribe : https://launchpad.net/~canonical-ubuntu-qa
More help   : https://help.launchpad.net/ListHelp

Reply via email to