Skip to content

Commit

Permalink
Include reviewer stats in stale stories email
Browse files Browse the repository at this point in the history
  • Loading branch information
jboolean committed Sep 16, 2023
1 parent be82358 commit 23451d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Senders from './Senders';
type StoryEmailTemplateData = {
storiesCount: number;
reviewStoriesUrl: string;
stats: { reviewer: string; count: number }[];
};

class ReviewQueueStaleTemplate extends EmailTemplate<
Expand Down
13 changes: 13 additions & 0 deletions backend/src/cron/checkStaleStories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ function forgeReviewStoriesUrl(): string {
return storyEditUrl.toString();
}

async function getReviewerStats(): Promise<
{ reviewer: string; count: number }[]
> {
const stats = (await StoryRepository().query(
`select last_reviewer as reviewer, count(*) as count from stories where last_reviewer is not null group by last_reviewer order by count(*) desc;`
)) as Promise<{ reviewer: string; count: number }[]>;
console.log(stats);
return stats;
}

export default async function checkStaleStories(): Promise<void> {
const hasStaleStories =
(await StoryRepository()
Expand All @@ -34,10 +44,13 @@ export default async function checkStaleStories(): Promise<void> {

const reviewStoriesUrl = forgeReviewStoriesUrl();

const stats = await getReviewerStats();

const email = ReviewQueueStaleTemplate.createTemplatedEmail({
templateContext: {
reviewStoriesUrl,
storiesCount,
stats,
},
metadata: {},
to: process.env.MODERATORS_TO_EMAIL ?? '',
Expand Down

0 comments on commit 23451d5

Please sign in to comment.