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
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")
"""
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)
""", 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
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)
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
);
);
+--
+-- 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: -
--
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
);
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: -
--
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: -
--
<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>
# 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):
"""