]> git.ipfire.org Git - pbs.git/commitdiff
builds: Add points (that will replace scores)
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 May 2023 20:57:29 +0000 (20:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 May 2023 20:57:29 +0000 (20:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/database.sql
src/templates/builds/show.html
tests/build.py

index 256234fdc565c427cdad3a625fab2131a1ee3a69..dabf150c4afdab6e69df3b00a35bc5880b15876a 100644 (file)
@@ -542,9 +542,37 @@ class Build(base.DataObject):
 
                return list(comments)
 
+       # Points
+
+       def add_points(self, points, user=None):
+               """
+                       Add points (can be negative)
+               """
+               # Log points
+               self.db.execute("""
+                       INSERT INTO
+                               build_points
+                       (
+                               build_id,
+                               points,
+                               user_id
+                       )
+                       VALUES
+                       (
+                               %s, %s, %s
+                       )
+                       """, self.id, points, user,
+               )
+
+               # Update the cache
+               self._set_attribute("points", self.points + points)
+
        @property
-       def score(self):
-               return sum((c.score for c in self.comments))
+       def points(self):
+               """
+                       Return the cached points
+               """
+               return self.data.points
 
        ## Watchers
 
@@ -647,6 +675,10 @@ class Build(base.DataObject):
                if not success:
                        self._set_attribute("failed", True)
 
+               # Award some negative points on failure
+               if not success:
+                       self.add_points(-1)
+
                # Notify everyone this build has finished...
                if success:
                        self._send_email("builds/messages/finished.txt")
@@ -1006,8 +1038,11 @@ class Build(base.DataObject):
                """
                        Called when all test builds have finished
                """
-               # Send an email on fail
                if not success:
+                       # Take away more points
+                       self.add_points(-2)
+
+                       # Send an email on fail
                        self._send_email("builds/messages/test-builds-failed.txt",
                                build=self, test_builds=self.test_builds)
 
@@ -1280,18 +1315,18 @@ class Comments(base.Object):
                        """, id,
                )
 
-       def create(self, build, user, text=None, score=None):
+       def create(self, build, user, text=None):
                comment = self._get_comment("""
                        INSERT INTO
                                build_comments(
-                                       build_id, user_id, text, score
+                                       build_id, user_id, text
                                )
                        VALUES(
-                               %s, %s, %s, %s
+                               %s, %s, %s
                        )
                        RETURNING
                                *
-                       """, build, user, text or "", score or 0,
+                       """, build, user, text or ""
                )
 
                # Notify people about this new comment
@@ -1315,10 +1350,6 @@ class Comment(base.DataObject):
        def text(self):
                return self.data.text
 
-       @property
-       def score(self):
-               return self.data.score
-
        def notify(self):
                """
                        Notifies all watchers about this comment (except the user who posted it)
index b561c244125460d4ee44b8f479ff06920d44ece6..3e1057ecf29a32c9b049114934072298e1f3a018 100644 (file)
@@ -50,7 +50,6 @@ CREATE TABLE public.build_comments (
     build_id integer NOT NULL,
     user_id integer NOT NULL,
     text text DEFAULT ''::text NOT NULL,
-    score integer NOT NULL,
     created_at timestamp without time zone DEFAULT now() NOT NULL,
     deleted boolean DEFAULT false NOT NULL
 );
@@ -105,6 +104,18 @@ CREATE TABLE public.build_packages (
 );
 
 
+--
+-- Name: build_points; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.build_points (
+    build_id integer NOT NULL,
+    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+    points integer DEFAULT 0 NOT NULL,
+    user_id integer
+);
+
+
 --
 -- Name: builds; Type: TABLE; Schema: public; Owner: -
 --
@@ -130,7 +141,8 @@ CREATE TABLE public.builds (
     deprecated_by integer,
     test_group_id integer,
     test boolean DEFAULT false NOT NULL,
-    disable_test_builds boolean DEFAULT false NOT NULL
+    disable_test_builds boolean DEFAULT false NOT NULL,
+    points integer DEFAULT 0 NOT NULL
 );
 
 
@@ -1396,6 +1408,13 @@ CREATE UNIQUE INDEX build_groups_uuid ON public.build_groups USING btree (uuid)
 CREATE INDEX build_packages_build_id ON public.build_packages USING btree (build_id);
 
 
+--
+-- Name: build_points_build_id; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX build_points_build_id ON public.build_points USING btree (build_id);
+
+
 --
 -- Name: build_watchers_unique; Type: INDEX; Schema: public; Owner: -
 --
@@ -1712,6 +1731,22 @@ ALTER TABLE ONLY public.build_packages
     ADD CONSTRAINT build_packages_package_id FOREIGN KEY (package_id) REFERENCES public.packages(id);
 
 
+--
+-- Name: build_points build_points_build_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_points
+    ADD CONSTRAINT build_points_build_id FOREIGN KEY (build_id) REFERENCES public.builds(id);
+
+
+--
+-- Name: build_points build_points_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_points
+    ADD CONSTRAINT build_points_user_id FOREIGN KEY (user_id) REFERENCES public.users(id);
+
+
 --
 -- Name: build_watchers build_watchers_build_id; Type: FK CONSTRAINT; Schema: public; Owner: -
 --
index 6bff850ebcc22907a8aa639f9ccc15c64c49f30e..bd6aa6f068c77e944aa0645061f01d75ae619d5f 100644 (file)
 
                                        <div class="column is-3">
                                                <div class="box">
-                                                       {# Score #}
+                                                       {# Points #}
                                                        <nav class="level">
                                                                <div class="level-item has-text-centered">
                                                                        <div>
-                                                                               <p class="heading">{{ _("Score") }}</p>
-                                                                               <p class="title">{{ build.score }}</p>
+                                                                               <p class="heading">{{ _("Points") }}</p>
+                                                                               <p class="title">{{ build.points }}</p>
                                                                        </div>
                                                                </div>
                                                        </nav>
index 56af86ddbe071e0ffee069d33f7ac01c947f41f4..821a8bf6e3eba84c265087de5541641dd8a70d0c 100755 (executable)
@@ -171,17 +171,17 @@ class BuildTestCase(test.TestCase):
                # Check if the comment is correctly cached
                self.assertIn(comment, build.comments)
 
-               # Create another comment with some score
-               build.comment(self.user, "This is a negative comment", score=-1)
+               # Award some points
+               build.add_points(2)
 
-               # The score should now be -1
-               self.assertEqual(build.score, -1)
+               # The score should now be 2
+               self.assertEqual(build.score, 2)
 
-               # Create another comment with a larger, positive score
-               build.comment(self.user, "This is a positive comment", score=2)
+               # Take away some points
+               build.add_points(-4)
 
-               # The score should now be 1
-               self.assertEqual(build.score, 1)
+               # The score should now be -2
+               self.assertEqual(build.score, -2)
 
        async def test_run(self):
                """