Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions app/tasks/coreping/coreping.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/usr/bin/env bun --watch

import DIE from "@snomiao/die";
import chalk from "chalk";
import isCI from "is-ci";
import sflow, { pageFlow } from "sflow";
import { P } from "ts-pattern";
import type { UnionToIntersection } from "type-fest";
import z from "zod";
import { tsmatch } from "@/packages/mongodb-pipeline-ts/Task";
import { db } from "@/src/db";
import { MetaCollection, TaskMetaCollection } from "@/src/db/TaskMeta";
import { type GH, gh } from "@/src/gh";
import { MetaCollection } from "@/src/db/TaskMeta";
import { type GH } from "@/src/gh";
import { ghc } from "@/src/ghc";
import { ghData } from "@/src/ghData";
import { ghPaged } from "@/src/paged";
import { parseIssueUrl } from "@/src/parseIssueUrl";
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
import { parsePullUrl } from "@/src/parsePullUrl";
import { yaml } from "@/src/utils/yaml";
import DIE from "@snomiao/die";
import chalk from "chalk";
import isCI from "is-ci";
import sflow from "sflow";
import { P } from "ts-pattern";
import type { UnionToIntersection } from "type-fest";
import z from "zod";
import { upsertSlackMessage } from "../gh-desktop-release-notification/upsertSlackMessage";

// yeah, if the bot could ping when updates have been made to a previously-reviewed PR, would be extremely helpful
Expand Down Expand Up @@ -125,7 +124,7 @@ const saveTask = async (pr: Partial<ComfyCorePRs> & { url: string }) => {
{ url: pr.url },
{ $set: { ...pr, task_updated_at: new Date() } },
{ upsert: true, returnDocument: "after" },
)) || DIE(`fail to save task${JSON.stringify(pr)}`)
)) || DIE(`fail to save task: ${JSON.stringify(pr)}`)
);
};

Expand Down Expand Up @@ -169,7 +168,7 @@ function reviewStatusExplained(
() =>
"The PR has requested reviews from specific reviewers, but none have reviewed or commented yet.",
)
.with("AUTHOR_COMMENTED", () => "The PR has been responed by the author.")
.with("AUTHOR_COMMENTED", () => "The PR has been responded by the author.")
.with("COMMITTED", () => "The PR has new commits pushed to it.")
.with(
"REVIEWER_COMMENTED",
Expand Down Expand Up @@ -283,7 +282,6 @@ async function runCorePingTaskFull() {
// state: "all",
sort: "created",
direction: "asc",
query: `label:${LABELS.map((e) => `"${e}"`).join(" OR label:")}`,
}),
)
.confluenceByConcat()
Expand Down Expand Up @@ -335,7 +333,9 @@ async function runCorePingTaskFull() {
// // send or update slack message
let meta = await Meta.$upsert({});

// can only post new message: tz: PST, day: working day + sat, time: 10-12am
// can only post new message:
// 1. tz: PST, day: working day + sat, time: 10-12am
// 2. last message sent >23h ago, if any last message exists
const canPostNewMessage = (() => {
const now = new Date();
const pstTime = new Date(
Expand All @@ -350,7 +350,11 @@ async function runCorePingTaskFull() {
const isValidTime = hour >= 10 && hour < 12;

return isValidDay && isValidTime;
})();
})() && (
!meta.lastSlackMessage?.sendAt ||
Date.now() - new Date(meta.lastSlackMessage.sendAt).getTime() >=
23 * 60 * 60 * 1000
)

const canUpdateExistingMessage =
meta.lastSlackMessage?.sendAt &&
Expand Down