]> git.ipfire.org Git - pbs.git/commitdiff
builds: Add bugs table that records when they have been added/removed
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 May 2023 20:53:30 +0000 (20:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 May 2023 20:53:30 +0000 (20:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/buildservice/events.py
src/buildservice/repository.py
src/database.sql
src/templates/events/modules/system-message.html

index 795bfe13b97b61907c2a37b0af3b33800a314d07..401c8e5033c6d06c122043d6e9f97eba8bc3cbd1 100644 (file)
@@ -781,46 +781,76 @@ class Build(base.DataObject):
 
        ## Bugs
 
-       def get_bug_ids(self):
-               return self.data.bug_ids
+       @lazy_property
+       def bug_ids(self):
+               rows = self.db.query("""
+                       SELECT
+                               bug_id
+                       FROM
+                               build_bugs
+                       WHERE
+                               build_id = %s
+                       AND
+                               removed_at IS NULL
+                       ORDER BY
+                               bug_id
+                       """, self.id,
+               )
 
-       def set_bug_ids(self, bug_ids):
-               self._set_attribute("bug_ids", bug_ids or [])
+               return set([row.bug_id for row in rows])
 
-       bug_ids = property(get_bug_ids, set_bug_ids)
+       def add_bug(self, bug_id, user=None):
+               self.db.execute("""
+                       INSERT INTO
+                               build_bugs
+                       (
+                               build_id,
+                               bug_id,
+                               added_by
+                       )
+                       VALUES
+                       (
+                               %s, %s, %s
+                       )
+                       ON CONFLICT
+                       (
+                               build_id,
+                               bug_id
+                       )
+                       WHERE
+                               removed_at IS NULL
+                       DO NOTHING
+                       """, self.id, bug_id, user,
+               )
 
-       async def get_bugs(self):
-               return await self.backend.bugzilla.get_bugs(self.bug_ids)
+               # Add to cache
+               self.bug_ids.add(bug_id)
 
-       def _update_bugs_helper(self, repo):
-               """
-                       This function takes a new status and generates messages that
-                       are appended to all bugs.
-               """
+       def remove_bug(self, bug_id, user):
+               self.db.execute("""
+                       UPDATE
+                               build_bugs
+                       SET
+                               removed_at = CURRENT_TIMESTAMP,
+                               removed_by = %s
+                       WHERE
+                               build_id = %s
+                       AND
+                               bug_id = %s
+                       """, self.id, bug_id,
+               )
+
+               # Remove from cache
                try:
-                       kwargs = BUG_MESSAGES[repo.type].copy()
+                       self.bug_ids.remove(bug_id)
                except KeyError:
-                       return
-
-               baseurl = self.backend.settings.get("baseurl", "")
-               args = {
-                       "build_url"    : "%s/build/%s" % (baseurl, self.uuid),
-                       "distro_name"  : self.distro.name,
-                       "package_name" : self.name,
-                       "repo_name"    : repo.name,
-               }
-               kwargs["comment"] = kwargs["comment"] % args
-
-               self.update_bugs(**kwargs)
-
-       def _update_bug(self, bug_id, status=None, resolution=None, comment=None):
-               self.db.execute("INSERT INTO builds_bugs_updates(bug_id, status, resolution, comment, time) \
-                       VALUES(%s, %s, %s, %s, NOW())", bug_id, status, resolution, comment)
+                       pass
 
-       def update_bugs(self, status, resolution=None, comment=None):
-               # Update all bugs linked to this build.
-               for bug_id in self.get_bug_ids():
-                       self._update_bug(bug_id, status=status, resolution=resolution, comment=comment)
+       async def get_bugs(self):
+               """
+                       Fetch all bugs from Bugzilla
+               """
+               return await self.backend.bugzilla.get_bugs(self.bug_ids)
 
        # Deprecation
 
index 1ef82e435dc076481568ceeb7c2ebaacc406fde1..f41746df79f9795c3c22fb81982762d44eead599 100644 (file)
@@ -48,6 +48,7 @@ log = logging.getLogger("pbs.events")
 # by_user
 # builder
 # repository
+# bug
 # error
 # points
 #
@@ -72,6 +73,7 @@ class Events(base.Object):
                                        builds.owner_id AS by_user,
                                        NULL::integer AS builder,
                                        NULL::integer AS repository,
+                                       NULL::integer AS bug,
                                        NULL::text AS error,
                                        NULL::integer AS points
                                FROM
@@ -102,6 +104,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -126,6 +129,7 @@ class Events(base.Object):
                                        builds.deleted_by AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -151,6 +155,7 @@ class Events(base.Object):
                                        builds.deprecated_by AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -177,6 +182,7 @@ class Events(base.Object):
                                        build_comments.user_id AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -201,6 +207,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -223,6 +230,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -232,6 +240,55 @@ class Events(base.Object):
 
                                UNION ALL
 
+                               -- Bugs added to builds
+                               SELECT
+                                       'build-bug-added' AS type,
+                                       build_bugs.added_at AS t,
+                                       4 AS priority,
+                                       build_bugs.build_id AS build,
+                                       NULL AS by_build,
+                                       NULL AS build_comment,
+                                       NULL AS build_group,
+                                       NULL AS job,
+                                       NULL AS mirror,
+                                       NULL AS user,
+                                       build_bugs.added_by AS by_user,
+                                       NULL AS builder,
+                                       NULL AS repository,
+                                       build_bugs.bug_id AS bug,
+                                       NULL AS error,
+                                       NULL AS points
+                               FROM
+                                       build_bugs
+
+                               UNION ALL
+
+                               -- Bugs removed from builds
+
+                               SELECT
+                                       'build-bug-removed' AS type,
+                                       build_bugs.removed_at AS t,
+                                       4 AS priority,
+                                       build_bugs.build_id AS build,
+                                       NULL AS by_build,
+                                       NULL AS build_comment,
+                                       NULL AS build_group,
+                                       NULL AS job,
+                                       NULL AS mirror,
+                                       NULL AS user,
+                                       build_bugs.removed_by AS by_user,
+                                       NULL AS builder,
+                                       NULL AS repository,
+                                       build_bugs.bug_id AS bug,
+                                       NULL AS error,
+                                       NULL AS points
+                               FROM
+                                       build_bugs
+                               WHERE
+                                       removed_at IS NOT NULL
+
+                               UNION ALL
+
                                -- Build added to repository
                                SELECT
                                        'repository-build-added' AS type,
@@ -247,6 +304,7 @@ class Events(base.Object):
                                        repository_builds.added_by AS by_user,
                                        NULL AS builder,
                                        repository_builds.repo_id AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -269,6 +327,7 @@ class Events(base.Object):
                                        repository_builds.removed_by AS by_user,
                                        NULL AS builder,
                                        repository_builds.repo_id AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -294,6 +353,7 @@ class Events(base.Object):
                                        build_points.user_id AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        build_points.points AS points
                                FROM
@@ -317,6 +377,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -347,6 +408,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -371,6 +433,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        jobs.builder_id AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -401,6 +464,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        jobs.builder_id AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -431,6 +495,7 @@ class Events(base.Object):
                                        jobs.aborted_by AS by_user,
                                        jobs.builder_id AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -457,6 +522,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        jobs.builder_id AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -483,6 +549,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -509,6 +576,7 @@ class Events(base.Object):
                                        mirrors.created_by AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -531,6 +599,7 @@ class Events(base.Object):
                                        mirrors.deleted_by AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        NULL AS error,
                                        NULL AS points
                                FROM
@@ -560,6 +629,7 @@ class Events(base.Object):
                                        NULL AS by_user,
                                        NULL AS builder,
                                        NULL AS repository,
+                                       NULL AS bug,
                                        mirror_status_changes.error AS error,
                                        NULL AS points
                                FROM (
index 5f1be9bd57bc5c08a9e3002ea89c2144c44431f8..88a118322be2bfb80bdc4d160c7625d19f6243b5 100644 (file)
@@ -439,8 +439,8 @@ class Repository(base.DataObject):
                # Update the cache
                build.repos.append(self)
 
-               # Update bug status.
-               #build._update_bugs_helper(self)
+               # Update bug status
+               # XXX TODO
 
                # Update the repository
                if update:
index 504dea2ecbffbc6419564bfc6121b2f95afe3d62..355ffd3788f5486631b70e4c4310911cc0d596bd 100644 (file)
@@ -27,6 +27,21 @@ SET default_tablespace = '';
 
 SET default_table_access_method = heap;
 
+--
+-- Name: build_bugs; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.build_bugs (
+    id integer NOT NULL,
+    build_id integer NOT NULL,
+    bug_id integer NOT NULL,
+    added_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+    added_by integer,
+    removed_at timestamp without time zone,
+    removed_by integer
+);
+
+
 --
 -- Name: build_comments; Type: TABLE; Schema: public; Owner: -
 --
@@ -194,6 +209,26 @@ CREATE TABLE public.repository_builds (
 );
 
 
+--
+-- Name: build_bugs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.build_bugs_id_seq
+    AS integer
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+--
+-- Name: build_bugs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.build_bugs_id_seq OWNED BY public.build_bugs.id;
+
+
 --
 -- Name: build_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
 --
@@ -321,41 +356,6 @@ CREATE SEQUENCE public.builders_id_seq
 ALTER SEQUENCE public.builders_id_seq OWNED BY public.builders.id;
 
 
---
--- Name: builds_bugs_updates; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.builds_bugs_updates (
-    id integer NOT NULL,
-    bug_id integer NOT NULL,
-    status text,
-    resolution text,
-    comment text,
-    "time" timestamp without time zone NOT NULL,
-    error boolean DEFAULT false NOT NULL,
-    error_msg text
-);
-
-
---
--- Name: builds_bugs_updates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.builds_bugs_updates_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-
-
---
--- Name: builds_bugs_updates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.builds_bugs_updates_id_seq OWNED BY public.builds_bugs_updates.id;
-
-
 --
 -- Name: builds_comments_id_seq; Type: SEQUENCE; Schema: public; Owner: -
 --
@@ -1179,6 +1179,13 @@ CREATE SEQUENCE public.users_id_seq
 ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
 
 
+--
+-- Name: build_bugs id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_bugs ALTER COLUMN id SET DEFAULT nextval('public.build_bugs_id_seq'::regclass);
+
+
 --
 -- Name: build_comments id; Type: DEFAULT; Schema: public; Owner: -
 --
@@ -1207,13 +1214,6 @@ ALTER TABLE ONLY public.builders ALTER COLUMN id SET DEFAULT nextval('public.bui
 ALTER TABLE ONLY public.builds ALTER COLUMN id SET DEFAULT nextval('public.builds_id_seq'::regclass);
 
 
---
--- Name: builds_bugs_updates id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.builds_bugs_updates ALTER COLUMN id SET DEFAULT nextval('public.builds_bugs_updates_id_seq'::regclass);
-
-
 --
 -- Name: distributions id; Type: DEFAULT; Schema: public; Owner: -
 --
@@ -1340,6 +1340,14 @@ ALTER TABLE ONLY public.user_push_subscriptions ALTER COLUMN id SET DEFAULT next
 ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
 
 
+--
+-- Name: build_bugs build_bugs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_bugs
+    ADD CONSTRAINT build_bugs_pkey PRIMARY KEY (id);
+
+
 --
 -- Name: build_comments build_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
 --
@@ -1380,14 +1388,6 @@ ALTER TABLE ONLY public.builders
     ADD CONSTRAINT idx_2197954_primary PRIMARY KEY (id);
 
 
---
--- Name: builds_bugs_updates idx_2198008_primary; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.builds_bugs_updates
-    ADD CONSTRAINT idx_2198008_primary PRIMARY KEY (id);
-
-
 --
 -- Name: images_types idx_2198057_primary; Type: CONSTRAINT; Schema: public; Owner: -
 --
@@ -1532,6 +1532,13 @@ ALTER TABLE ONLY public.user_push_subscriptions
     ADD CONSTRAINT user_push_subscriptions_pkey PRIMARY KEY (id);
 
 
+--
+-- Name: build_bugs_unique; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX build_bugs_unique ON public.build_bugs USING btree (build_id, bug_id) WHERE (removed_at IS NULL);
+
+
 --
 -- Name: build_comments_build_id; Type: INDEX; Schema: public; Owner: -
 --
@@ -1875,6 +1882,30 @@ CREATE UNIQUE INDEX uploads_uuid ON public.uploads USING btree (uuid);
 CREATE INDEX user_push_subscriptions_user_id ON public.user_push_subscriptions USING btree (user_id) WHERE (deleted_at IS NULL);
 
 
+--
+-- Name: build_bugs build_bugs_added_by; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_bugs
+    ADD CONSTRAINT build_bugs_added_by FOREIGN KEY (added_by) REFERENCES public.users(id);
+
+
+--
+-- Name: build_bugs build_bugs_build_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_bugs
+    ADD CONSTRAINT build_bugs_build_id FOREIGN KEY (build_id) REFERENCES public.builds(id);
+
+
+--
+-- Name: build_bugs build_bugs_removed_by; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_bugs
+    ADD CONSTRAINT build_bugs_removed_by FOREIGN KEY (removed_by) REFERENCES public.users(id);
+
+
 --
 -- Name: build_groups build_groups_created_by; Type: FK CONSTRAINT; Schema: public; Owner: -
 --
index f6aefa165127ff2c21337d666c82a16d5cbdaa02..bb8ebcf5f08c18affd19940b770128586ca8078d 100644 (file)
                                <p class="icon is-large has-text-danger">
                                        <i class="fa-solid fa-2x fa-thumbs-down"></i>
                                </p>
+                       {% elif event.type == "build-bug-added" %}
+                               <p class="icon is-large has-text-success">
+                                       <i class="fa-solid fa-2x fa-bug"></i>
+                               </p>
+                       {% elif event.type == "build-bug-removed" %}
+                               <p class="icon is-large has-text-danger">
+                                       <i class="fa-solid fa-2x fa-bug"></i>
+                               </p>
                        {% elif event.type == "test-builds-succeeded" %}
                                <p class="icon is-large has-text-success">
                                        <i class="fa-solid fa-2x fa-flask-vial"></i>
                                        {{ _("%s started watching this build") % event.user }}
                                {% elif event.type == "build-watcher-removed" %}
                                        {{ _("%s stopped watching this build") % event.user }}
+                               {% elif event.type == "build-bug-added" %}
+                                       {{ _("Bug #%s has been added") % event.bug }}
+                               {% elif event.type == "build-bug-removed" %}
+                                       {{ _("Bug #%s has been removed") % event.bug }}
                                {% elif event.type == "build-points" %}
                                        {% if event.points > 0 %}
                                                {{ _("This build has gained one point", "This build has gained %(points)s points", event.points) % { "points" : event.points } }}