From: Michael Tremer Date: Fri, 12 May 2023 20:57:29 +0000 (+0000) Subject: builds: Add points (that will replace scores) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=100b864f7b1cdd79f33ae8b375d419d7de4cfa4e;p=pbs.git builds: Add points (that will replace scores) Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 256234fd..dabf150c 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -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) diff --git a/src/database.sql b/src/database.sql index b561c244..3e1057ec 100644 --- a/src/database.sql +++ b/src/database.sql @@ -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: - -- diff --git a/src/templates/builds/show.html b/src/templates/builds/show.html index 6bff850e..bd6aa6f0 100644 --- a/src/templates/builds/show.html +++ b/src/templates/builds/show.html @@ -75,12 +75,12 @@
- {# Score #} + {# Points #} diff --git a/tests/build.py b/tests/build.py index 56af86dd..821a8bf6 100755 --- a/tests/build.py +++ b/tests/build.py @@ -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): """