]> git.ipfire.org Git - pbs.git/commitdiff
distros: Store Bugzilla product & version
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 May 2023 11:20:00 +0000 (11:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 May 2023 11:20:00 +0000 (11:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/bugtracker.py
src/buildservice/distribution.py
src/database.sql
src/templates/distros/edit.html
src/web/distributions.py

index f3693f92c5a313de9baa7d23c90acd725ae4f93e..677b84a8353fdd05e7da4f5ee7169ec469dc607b 100644 (file)
@@ -50,6 +50,28 @@ class Bugzilla(base.Object):
        def product(self):
                return self.settings.get("bugzilla-product")
 
+       async def get_products(self):
+               """
+                       Returns a dictionary with all products and versions
+               """
+               products = {}
+
+               # Fetch all products
+               response = await self._request("GET", "/rest/product", type="accessible")
+
+               # Walk through all products
+               for product in response.get("products", []):
+                       # Fetch name
+                       name = product.get("name")
+
+                       # Fetch versions
+                       versions = [v.get("name") for v in product.get("versions")]
+
+                       # Add the product and versions
+                       products[name] = versions
+
+               return products
+
        def make_url(self, *args, **kwargs):
                """
                        Composes a URL based on the base URL
index e6a7d161e3a607c918461ce7b81614adec9c2f9a..38578d8df50ec00c6688bb68b647eadc8d061a26 100644 (file)
@@ -212,6 +212,38 @@ class Distribution(base.DataObject):
 
        custom_config = property(get_custom_config, set_custom_config)
 
+       # Bugzilla Product
+
+       def get_bugzilla_product(self):
+               return self.data.bugzilla_product
+
+       def set_bugzilla_product(self, product):
+               self._set_attribute("bugzilla_product", product)
+
+       bugzilla_product = property(get_bugzilla_product, set_bugzilla_product)
+
+       # Bugzilla Version
+
+       def get_bugzilla_version(self):
+               return self.data.bugzilla_version
+
+       def set_bugzilla_version(self, version):
+               self._set_attribute("bugzilla_version", version)
+
+       bugzilla_version = property(get_bugzilla_version, set_bugzilla_version)
+
+       # Bugzilla Fields
+
+       @property
+       def bugzilla_fields(self):
+               """
+                       Short hand to convey all fields for Bugzilla
+               """
+               return {
+                       "product" : self.bugzilla_product,
+                       "version" : self.bugzilla_version,
+               }
+
        # Permissions
 
        def has_perm(self, user):
index 3e1057ecf29a32c9b049114934072298e1f3a018..5ba1e8ff59e85b3e035d115087a000cda0cefb16 100644 (file)
@@ -343,7 +343,9 @@ CREATE TABLE public.distributions (
     arches text[] DEFAULT ARRAY[]::text[] NOT NULL,
     created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
     custom_config text DEFAULT ''::text NOT NULL,
-    codename text DEFAULT ''::text NOT NULL
+    codename text DEFAULT ''::text NOT NULL,
+    bugzilla_product text DEFAULT ''::text NOT NULL,
+    bugzilla_version text DEFAULT ''::text NOT NULL
 );
 
 
index 6a1c72c035124a48d9e0c66c7283fefaf3bb14ec..3f9e0d9b48661e17c8c12b8f013fe7d640c435d9 100644 (file)
                                                </div>
                                        </div>
 
+                                       {# Bugzilla #}
+                                       {% if bugzilla_products %}
+                                               <div class="field">
+                                                       <label class="label">{{ _("Bugzilla") }}</label>
+
+                                                       <div class="control">
+                                                               <div class="select">
+                                                                       <select name="bugzilla">
+                                                                               {% for bugzilla_product in bugzilla_products %}
+                                                                                       <optgroup label="{{ bugzilla_product }}">
+                                                                                               {% for bugzilla_version in bugzilla_products[bugzilla_product] %}
+                                                                                                       <option value="{{ bugzilla_product }}:{{ bugzilla_version }}"
+                                                                                                                       {% if distro.bugzilla_product == bugzilla_product and distro.bugzilla_version == bugzilla_version %}selected{% end %}>
+                                                                                                               {{ bugzilla_product }} {{ bugzilla_version }}
+                                                                                                       </option>
+                                                                                               {% end %}
+                                                                                       </optgroup>
+                                                                               {% end %}
+                                                                       </select>
+                                                               </div>
+                                                       </div>
+                                               </div>
+                                       {% end %}
+
                                        <div class="field is-grouped">
                                                <div class="control">
                                                        <button class="button is-success is-link" type="submit">
index e078ce8b467da2c523fc8d031d235805fe673cf0..566c9c77f5fb656a7904f013537600408db10b09 100644 (file)
@@ -21,16 +21,19 @@ class ShowHandler(base.BaseHandler):
 
 class EditHandler(base.BaseHandler):
        @tornado.web.authenticated
-       def get(self, slug):
+       async def get(self, slug):
                distro = self.backend.distros.get_by_slug(slug)
                if not distro:
                        raise tornado.web.HTTPError(404, "Could not find distribution: %s" % slug)
 
+               # Fetch available Bugzilla products
+               bugzilla_products = await self.backend.bugzilla.get_products()
+
                # Check for permissions
                if not distro.has_perm(self.current_user):
                        raise tornado.web.HTTPError(403)
 
-               self.render("distros/edit.html", distro=distro)
+               self.render("distros/edit.html", distro=distro, bugzilla_products=bugzilla_products)
 
        @tornado.web.authenticated
        def post(self, slug):
@@ -45,6 +48,10 @@ class EditHandler(base.BaseHandler):
                        distro.slogan  = self.get_argument("slogan", None)
                        distro.arches  = self.get_arguments("arches")
 
+                       # Bugzilla Product/Version
+                       distro.bugzilla_product, delim, distro.bugzilla_version = \
+                               self.get_argument("bugzilla", "").partition(":")
+
                self.redirect("/distros/%s" % distro.slug)