diff --git a/apps/webapp/package.json b/apps/webapp/package.json index 714d225..f3668ad 100644 --- a/apps/webapp/package.json +++ b/apps/webapp/package.json @@ -16,7 +16,7 @@ "@blueprintjs/icons": "^5.9.0", "@blueprintjs/select": "^5.1.5", "@repo/github": "workspace:*", - "@repo/types": "workspace:*", + "@repo/model": "workspace:*", "clsx": "^2.1.1", "comlink": "^4.4.1", "dexie": "^4.0.7", diff --git a/apps/webapp/src/components/CommandBar.tsx b/apps/webapp/src/components/CommandBar.tsx index 25536f6..d243b7f 100644 --- a/apps/webapp/src/components/CommandBar.tsx +++ b/apps/webapp/src/components/CommandBar.tsx @@ -1,7 +1,7 @@ import { useMemo, useState } from "react"; import { HotkeysTarget2, HotkeyConfig, MenuItem } from "@blueprintjs/core"; import { ItemPredicate, ItemRenderer, Omnibar } from "@blueprintjs/select"; -import type { Pull } from "@repo/types"; +import type { Pull } from "@repo/model"; import { usePulls } from "../lib/queries"; type Props = { diff --git a/apps/webapp/src/components/ConnectionDialog.tsx b/apps/webapp/src/components/ConnectionDialog.tsx index ec668fb..c4dfb8d 100644 --- a/apps/webapp/src/components/ConnectionDialog.tsx +++ b/apps/webapp/src/components/ConnectionDialog.tsx @@ -1,7 +1,7 @@ import { Button, Dialog, DialogBody, DialogFooter, FormGroup, HTMLSelect, InputGroup, Intent } from "@blueprintjs/core" import { useState } from "react" import ConfirmDialog from "./ConfirmDialog" -import type { ConnectionProps } from "@repo/types"; +import type { ConnectionProps } from "@repo/model"; import { isTruthy } from "remeda"; import { AppToaster } from "../lib/toaster"; diff --git a/apps/webapp/src/components/ConnectionTable.tsx b/apps/webapp/src/components/ConnectionTable.tsx index baf954b..1910e3f 100644 --- a/apps/webapp/src/components/ConnectionTable.tsx +++ b/apps/webapp/src/components/ConnectionTable.tsx @@ -1,7 +1,7 @@ import { Button, HTMLTable } from "@blueprintjs/core" import { useState } from "react" import ConnectionDialog from "./ConnectionDialog" -import type { Connection, ConnectionProps } from "@repo/types" +import type { Connection, ConnectionProps } from "@repo/model" import styles from "./ConnectionTable.module.scss"; diff --git a/apps/webapp/src/components/DashboardSection.tsx b/apps/webapp/src/components/DashboardSection.tsx index 7746f01..0c7bb87 100644 --- a/apps/webapp/src/components/DashboardSection.tsx +++ b/apps/webapp/src/components/DashboardSection.tsx @@ -1,7 +1,7 @@ import { Button, Card, Collapse, H5, Icon, Intent, Spinner, Tag } from "@blueprintjs/core" import { useState } from "react" import SectionDialog from "./SectionDialog"; -import type { Pull, Section } from "@repo/types"; +import type { Pull, Section } from "@repo/model"; import PullTable from "./PullTable"; import styles from "./DashboardSection.module.scss"; diff --git a/apps/webapp/src/components/PullTable.tsx b/apps/webapp/src/components/PullTable.tsx index 779f1c1..602c64c 100644 --- a/apps/webapp/src/components/PullTable.tsx +++ b/apps/webapp/src/components/PullTable.tsx @@ -1,6 +1,6 @@ import { HTMLTable, Tooltip, Tag, Icon } from "@blueprintjs/core"; import ReactTimeAgo from "react-time-ago"; -import { type Pull, PullState } from "@repo/types"; +import { type Pull, PullState } from "@repo/model"; import IconWithTooltip from "./IconWithTooltip"; import { computeSize } from "../lib/size"; diff --git a/apps/webapp/src/components/SectionDialog.tsx b/apps/webapp/src/components/SectionDialog.tsx index 7263589..405eb18 100644 --- a/apps/webapp/src/components/SectionDialog.tsx +++ b/apps/webapp/src/components/SectionDialog.tsx @@ -2,7 +2,7 @@ import { Button, Checkbox, Dialog, DialogBody, DialogFooter, FormGroup, InputGro import { useState } from "react"; import { AppToaster } from "../lib/toaster" import ConfirmDialog from "./ConfirmDialog"; -import { type SectionProps, defaultSectionProps } from "@repo/types"; +import { type SectionProps, defaultSectionProps } from "@repo/model"; type Props = { title: string, diff --git a/apps/webapp/src/lib/db.ts b/apps/webapp/src/lib/db.ts index 9e9ebde..ccad1bf 100644 --- a/apps/webapp/src/lib/db.ts +++ b/apps/webapp/src/lib/db.ts @@ -1,4 +1,4 @@ -import type { Connection, Pull, Section, Star } from "@repo/types"; +import type { Connection, Pull, Section, Star } from "@repo/model"; import Dexie, { type EntityTable } from "dexie"; export type Activity = { diff --git a/apps/webapp/src/lib/mutations.ts b/apps/webapp/src/lib/mutations.ts index 9c27963..ef698bc 100644 --- a/apps/webapp/src/lib/mutations.ts +++ b/apps/webapp/src/lib/mutations.ts @@ -1,5 +1,5 @@ import { db } from "./db"; -import { defaultSections, type Connection, type Pull, type Section } from "@repo/types"; +import { defaultSections, type Connection, type Pull, type Section } from "@repo/model"; import { omit } from "remeda"; export async function saveConnection (value: Connection): Promise { diff --git a/apps/webapp/src/lib/queries.ts b/apps/webapp/src/lib/queries.ts index 5ef6d70..1ebf613 100644 --- a/apps/webapp/src/lib/queries.ts +++ b/apps/webapp/src/lib/queries.ts @@ -1,6 +1,6 @@ import { db } from "./db"; import { useLiveQuery } from "dexie-react-hooks"; -import { defaultSections } from "@repo/types"; +import { defaultSections } from "@repo/model"; // Defaults to populate after adding new fields. const connectionDefaults = { orgs: [] }; diff --git a/apps/webapp/src/lib/size.ts b/apps/webapp/src/lib/size.ts index 810791f..ed38c5d 100644 --- a/apps/webapp/src/lib/size.ts +++ b/apps/webapp/src/lib/size.ts @@ -1,5 +1,5 @@ import { reverse, zip } from "remeda"; -import type { PullProps } from "@repo/types" +import type { PullProps } from "@repo/model" // Defaults come from Prow: // https://github.com/kubernetes/test-infra/blob/master/prow/plugins/size/size.go diff --git a/apps/webapp/src/routes/dashboard.tsx b/apps/webapp/src/routes/dashboard.tsx index 9e7e7dc..618142b 100644 --- a/apps/webapp/src/routes/dashboard.tsx +++ b/apps/webapp/src/routes/dashboard.tsx @@ -3,7 +3,7 @@ import { useSearchParams } from "react-router-dom"; import { Button } from "@blueprintjs/core"; import SectionDialog from "../components/SectionDialog"; import DashboardSection from "../components/DashboardSection"; -import { type Section, type SectionProps, defaultSectionProps } from "@repo/types"; +import { type Section, type SectionProps, defaultSectionProps } from "@repo/model"; import { useSections, usePulls } from "../lib/queries"; import { deleteSection, moveSectionDown, moveSectionUp, saveSection, toggleStar } from "../lib/mutations"; import Navbar from "../components/Navbar"; diff --git a/apps/webapp/src/routes/settings.tsx b/apps/webapp/src/routes/settings.tsx index e054b3c..234769e 100644 --- a/apps/webapp/src/routes/settings.tsx +++ b/apps/webapp/src/routes/settings.tsx @@ -6,7 +6,7 @@ import ConfirmDialog from "../components/ConfirmDialog"; import { getWorker } from "../worker/client"; import { useConnections } from "../lib/queries"; import { deleteConnection, resetSections, saveConnection } from "../lib/mutations"; -import type { Connection, ConnectionProps } from "@repo/types" +import type { Connection, ConnectionProps } from "@repo/model" import styles from "./settings.module.scss"; import { AppToaster } from "../lib/toaster"; import { useNavigate } from "react-router-dom"; diff --git a/apps/webapp/src/worker/instance.ts b/apps/webapp/src/worker/instance.ts index 298d261..6c723ac 100644 --- a/apps/webapp/src/worker/instance.ts +++ b/apps/webapp/src/worker/instance.ts @@ -1,7 +1,8 @@ import * as Comlink from "comlink"; import { groupBy, unique } from "remeda"; import { db } from "../lib/db"; -import { splitQueries, type Pull, type Connection } from "@repo/github"; +import { splitQueries } from "@repo/github"; +import type { Pull, Connection } from "@repo/model"; import { GitHubClient, isInAttentionSet } from "@repo/github"; import { gitHubClient } from "../github"; @@ -18,7 +19,7 @@ function syncViewers(client: GitHubClient) { async function executeActivity(name: string, intervalMillis: number, force: boolean, fn: () => Promise): Promise { const activity = await db.activities.get(name); - if (!force && activity !== undefined && activity.refreshTime <= new Date(Date.now() - intervalMillis)) { + if (!force && activity !== undefined && activity.refreshTime > new Date(Date.now() - intervalMillis)) { return; } if (activity === undefined) { diff --git a/apps/webapp/tests/components/ConnectionDialog.test.tsx b/apps/webapp/tests/components/ConnectionDialog.test.tsx index 40f9841..fe1e783 100644 --- a/apps/webapp/tests/components/ConnectionDialog.test.tsx +++ b/apps/webapp/tests/components/ConnectionDialog.test.tsx @@ -3,7 +3,7 @@ import { render, screen } from "@testing-library/react"; import { userEvent, type UserEvent } from "@testing-library/user-event"; import ConnectionDialog from "../../src/components/ConnectionDialog.js"; import { AppToaster } from "../../src/lib/toaster.js"; -import type { ConnectionProps } from "@repo/types"; +import type { ConnectionProps } from "@repo/model"; import { mockConnection } from "@repo/testing"; describe("connection dialog", () => { diff --git a/apps/webapp/tests/lib/db.test.ts b/apps/webapp/tests/lib/db.test.ts index 982251d..056023a 100644 --- a/apps/webapp/tests/lib/db.test.ts +++ b/apps/webapp/tests/lib/db.test.ts @@ -1,6 +1,6 @@ import { test, expect } from "vitest"; import { Activity, db } from "../../src/lib/db.js"; -import type { Star } from "@repo/types"; +import type { Star } from "@repo/model"; import { mockConnection, mockSection, mockPull } from "@repo/testing"; test("db should save a connection", async () => { diff --git a/apps/webapp/src/worker/instance.test.ts b/apps/webapp/tests/worker/instance.test.ts similarity index 81% rename from apps/webapp/src/worker/instance.test.ts rename to apps/webapp/tests/worker/instance.test.ts index d4f3067..89a8fd0 100644 --- a/apps/webapp/src/worker/instance.test.ts +++ b/apps/webapp/tests/worker/instance.test.ts @@ -1,14 +1,11 @@ import { TestGitHubClient } from "@repo/github"; import { afterEach, beforeEach, it, describe, expect, assert } from "vitest"; -import { syncPullsOnce, syncViewersOnce } from "./instance"; -import { db } from "../lib/db"; +import { syncPullsOnce, syncViewersOnce } from "../../src/worker/instance.js"; +import { db } from "../../src/lib/db.js"; import { mockPull, mockConnection, mockSection } from "@repo/testing"; describe("sync viewers", () => { - let client: TestGitHubClient|undefined; - beforeEach(async () => { - client = new TestGitHubClient(); await db.connections.add(mockConnection({ id: "1" })); await db.connections.add(mockConnection({ id: "2" })); }) @@ -19,38 +16,39 @@ describe("sync viewers", () => { }) it("should update connections", async () => { - assert(client !== undefined); + let activity = await db.activities.get("syncViewers"); + expect(activity).toBeUndefined(); + + const client = new TestGitHubClient(); await syncViewersOnce(client); let connection = await db.connections.get("1"); - expect(connection).toBeDefined(); + expect(connection?.viewer).toBeDefined(); expect(connection?.viewer?.user).toEqual({ name: "test[1]", avatarUrl: "" }); connection = await db.connections.get("2"); expect(connection?.viewer).toBeDefined(); expect(connection?.viewer?.user).toEqual({ name: "test[2]", avatarUrl: "" }); - }) - - it("should update activity", async () => { - assert(client !== undefined); - - let activity = await db.activities.get("syncViewers"); - expect(activity).toBeUndefined(); - - await syncViewersOnce(client); activity = await db.activities.get("syncViewers"); expect(activity?.running).toBeFalsy(); expect(activity?.refreshTime.getTime()).toBeGreaterThan(0); expect(activity?.refreshTime.getTime()).toBeLessThanOrEqual(Date.now()); }) + + it("should not update connections if recently completed", async () => { + await db.activities.add({ name: "syncViewers", running: false, refreshTime: new Date() }); + + const client = new TestGitHubClient(); + await syncViewersOnce(client); + + const connection = await db.connections.get("1"); + expect(connection?.viewer).toBeUndefined(); + }) }) describe("sync pulls", () => { - let client: TestGitHubClient|undefined; - beforeEach(async () => { - client = new TestGitHubClient(); await db.connections.add(mockConnection({ id: "1" })); await db.connections.add(mockConnection({ id: "2" })); await db.sections.add(mockSection({ id: "1", search: "author:@me draft:true;author:@me draft:false" })); @@ -65,11 +63,14 @@ describe("sync pulls", () => { }) it("should update pulls", async () => { - assert(client !== undefined); + let activity = await db.activities.get("syncPulls"); + expect(activity).toBeUndefined(); // GIVEN some pull requests are returned from GitHub. let connection = await db.connections.get("1"); assert(connection !== undefined); + + const client = new TestGitHubClient(); client.setPulls(connection, "author:@me draft:true", [ mockPull({ uid: "1:1" }), mockPull({ uid: "1:2" }), @@ -110,19 +111,20 @@ describe("sync pulls", () => { pull = await db.pulls.get("1:4"); expect(pull?.sections).toEqual(["1"]); - }) - - it("should update activity", async () => { - assert(client !== undefined); - - let activity = await db.activities.get("syncPulls"); - expect(activity).toBeUndefined(); - - await syncPullsOnce(client); + // THEN the activity should have been updated. activity = await db.activities.get("syncPulls"); expect(activity?.running).toBeFalsy(); expect(activity?.refreshTime.getTime()).toBeGreaterThan(0); expect(activity?.refreshTime.getTime()).toBeLessThanOrEqual(Date.now()); }) + + it("should not update pulls if recently completed", async () => { + await db.activities.add({ name: "syncPulls", running: false, refreshTime: new Date() }); + + const client = new TestGitHubClient(); + await syncPullsOnce(client); + + expect(await db.pulls.count()).toBe(0); + }) }) \ No newline at end of file diff --git a/packages/github/package.json b/packages/github/package.json index 920b5ee..ef0ecfb 100644 --- a/packages/github/package.json +++ b/packages/github/package.json @@ -29,6 +29,6 @@ "dependencies": { "@octokit/core": "^6.1.2", "@octokit/rest": "^20.1.1", - "@repo/types": "workspace:*" + "@repo/model": "workspace:*" } } diff --git a/packages/github/src/attention.ts b/packages/github/src/attention.ts index 61946a1..024c3e1 100644 --- a/packages/github/src/attention.ts +++ b/packages/github/src/attention.ts @@ -1,4 +1,4 @@ -import { type Attention, type PullProps, type Comment, type Connection, PullState } from "@repo/types"; +import { type Attention, type PullProps, type Comment, type Connection, PullState } from "@repo/model"; import { GitHubClient } from "./client.js"; export async function isInAttentionSet(client: GitHubClient, connection: Connection, pull: PullProps): Promise { diff --git a/packages/github/src/client.ts b/packages/github/src/client.ts index 0ce6737..47a90db 100644 --- a/packages/github/src/client.ts +++ b/packages/github/src/client.ts @@ -1,5 +1,5 @@ import { Octokit } from "@octokit/rest"; -import { type Connection, type Comment, PullState, type PullProps, type Team, type User, type Profile } from "@repo/types"; +import { type Connection, type Comment, PullState, type PullProps, type Team, type User, type Profile } from "@repo/model"; import { SearchQuery } from "./search.js"; const MAX_PULLS_TO_FETCH = 50; diff --git a/packages/github/tests/attention.test.ts b/packages/github/tests/attention.test.ts index 1e5ca76..2d68a46 100644 --- a/packages/github/tests/attention.test.ts +++ b/packages/github/tests/attention.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"; import { isInAttentionSet } from "../src/attention.js"; import { TestGitHubClient } from "../src/client.js"; import { mockConnection, mockPull } from "@repo/testing"; -import { PullState } from "@repo/types"; +import { PullState } from "@repo/model"; describe("attention set", () => { const client = new TestGitHubClient(); diff --git a/packages/types/.eslintrc.cjs b/packages/model/.eslintrc.cjs similarity index 100% rename from packages/types/.eslintrc.cjs rename to packages/model/.eslintrc.cjs diff --git a/packages/types/README.md b/packages/model/README.md similarity index 73% rename from packages/types/README.md rename to packages/model/README.md index b78423f..bc0b84c 100644 --- a/packages/types/README.md +++ b/packages/model/README.md @@ -1,3 +1,3 @@ -# packages/types +# packages/model This package contains common Typescript types. \ No newline at end of file diff --git a/packages/types/package.json b/packages/model/package.json similarity index 94% rename from packages/types/package.json rename to packages/model/package.json index 8a6ab9c..891acb0 100644 --- a/packages/types/package.json +++ b/packages/model/package.json @@ -1,5 +1,5 @@ { - "name": "@repo/types", + "name": "@repo/model", "version": "0.0.0", "type": "module", "exports": { diff --git a/packages/types/src/comment.ts b/packages/model/src/comment.ts similarity index 100% rename from packages/types/src/comment.ts rename to packages/model/src/comment.ts diff --git a/packages/types/src/config.ts b/packages/model/src/config.ts similarity index 100% rename from packages/types/src/config.ts rename to packages/model/src/config.ts diff --git a/packages/types/src/index.ts b/packages/model/src/index.ts similarity index 100% rename from packages/types/src/index.ts rename to packages/model/src/index.ts diff --git a/packages/types/src/pull.ts b/packages/model/src/pull.ts similarity index 100% rename from packages/types/src/pull.ts rename to packages/model/src/pull.ts diff --git a/packages/types/src/user.ts b/packages/model/src/user.ts similarity index 100% rename from packages/types/src/user.ts rename to packages/model/src/user.ts diff --git a/packages/types/tsconfig.json b/packages/model/tsconfig.json similarity index 100% rename from packages/types/tsconfig.json rename to packages/model/tsconfig.json diff --git a/packages/testing/package.json b/packages/testing/package.json index 7b25356..0df91ab 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -15,7 +15,7 @@ "lint": "eslint \"**/*.ts\"" }, "dependencies": { - "@repo/types": "workspace:*" + "@repo/model": "workspace:*" }, "devDependencies": { "@repo/eslint-config": "workspace:*", diff --git a/packages/testing/src/index.ts b/packages/testing/src/index.ts index 3182b49..49ab45c 100644 --- a/packages/testing/src/index.ts +++ b/packages/testing/src/index.ts @@ -1,4 +1,4 @@ -import { type Pull, type Section, type Connection, PullState } from "@repo/types"; +import { type Pull, type Section, type Connection, PullState } from "@repo/model"; export function mockPull(props?: Partial): Pull { return { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index abe810e..a2fabd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,9 @@ importers: '@repo/github': specifier: workspace:* version: link:../../packages/github - '@repo/types': + '@repo/model': specifier: workspace:* - version: link:../../packages/types + version: link:../../packages/model clsx: specifier: ^2.1.1 version: 2.1.1 @@ -180,9 +180,9 @@ importers: '@octokit/rest': specifier: ^20.1.1 version: 20.1.1 - '@repo/types': + '@repo/model': specifier: workspace:* - version: link:../types + version: link:../model devDependencies: '@repo/eslint-config': specifier: workspace:* @@ -206,11 +206,7 @@ importers: specifier: ^2.0.5 version: 2.0.5(@types/node@22.5.0)(jsdom@24.1.1)(less@4.2.0)(sass@1.77.6)(stylus@0.62.0) - packages/testing: - dependencies: - '@repo/types': - specifier: workspace:* - version: link:../types + packages/model: devDependencies: '@repo/eslint-config': specifier: workspace:* @@ -225,7 +221,11 @@ importers: specifier: ^5.5.4 version: 5.5.4 - packages/types: + packages/testing: + dependencies: + '@repo/model': + specifier: workspace:* + version: link:../model devDependencies: '@repo/eslint-config': specifier: workspace:*