diff --git a/README.md b/README.md index cf84f99..745dc04 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ and filed by a GitHub App. Reporters never need a GitHub account. - **GitHub issues:** search every issue, open and closed, across your connected repositories, including the ones opened directly on GitHub. Kept up to date every 2 minutes, no webhooks needed. - **Repo status (optional):** every repository at a glance, like a team status board: open PRs and issues and the oldest open PR, the last commit, issue and PR, what happened in a window you pick (10 minutes to a week, since the last build, or all time: commits, PRs opened and merged, issues, people), and each latest build with its unreleased commits and downloads. Sort by any column; a totals row sums them up. Fix first ranks the open issues across the repositories by what they say (crash, hang, data loss beats "doesn't work"), who filed them, how many people pile on and how fresh they are, with the reasons beside each score. Most reported ranks the issues by how many Discord tickets are about them (a duplicate counts for its original; ones Claude suggested and nobody has reviewed yet are shown as waiting for review), over the last 7, 30 or 90 days or all time, with the tickets one click away, and says when an issue closed as fixed keeps being reported. Pull requests lists the open ones (the ones fixing the most reported issues first, with how many Discord tickets are about them), the merged ones waiting for a release, and the ones merged in the last 90 days; Fix first and Most reported show when someone's working on an issue or it's already fixed. Read in the background every 5 to 60 minutes with GitHub's GraphQL API, which has its own budget, so filing isn't affected. Off until you turn it on; you pick the repositories (your apps' ones to start with). -- **Analytics (optional):** downloads recorded every 30 minutes from when you turn it on (GitHub only keeps running totals), per app, platform, processor, format and version, from 30 minutes to 12 months at a time (today in 30-minute steps by default; steps of 30m, 1h, 3h, 6h, 12h or a day), in your own time zone. Next to them: tickets, issues opened and closed, pull requests merged and stars over the same time, each compared with the period before, and release health: Discord tickets while each release was the latest, per 1,000 of its downloads. Every chart has a table view. +- **Analytics (optional):** downloads recorded every 30 minutes from when you turn it on (GitHub only keeps running totals), per app, platform, processor, format and version, from 30 minutes to 12 months at a time (today in 30-minute steps by default; steps of 30m, 1h, 3h, 6h, 12h or a day), in your own time zone. The main chart switches between downloads and stars: new stars over time (back to each repository's first star) and each app's star total, read every 30 minutes with the downloads. Next to them: tickets, issues opened and closed, pull requests merged and stars over the same time, each compared with the period before, and release health: Discord tickets while each release was the latest, per 1,000 of its downloads. Every chart has a table view. - **AI triage (optional):** Claude flags priority, duplicates, regressions, spam and more, and sorts tickets with your own label groups. Each action can be off, a suggestion, or automatic above a confidence threshold, with separate settings for issues opened directly on GitHub. - AI triage › Review lists everything with suggestions waiting, from Discord tickets and GitHub issues. Every ticket shows its triage state (To review, Partly applied, Applied…), and suggestions say exactly what applying them does. - Apply or dismiss in bulk, e.g. all duplicates at 80%+ confidence. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ca2a1e2..fa986b6 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -127,7 +127,8 @@ Discord endpoint, OAuth), one or more queue workers, and an optional triage work counts from its release's publication). Files are classified by name (`assets.ts`: platform, architecture, format; checksums, signatures and update metadata aren't downloads). Detail is kept 32 days, then added up per UTC day (`download_days`). Stars come with when each was given, so - their history goes back to the first (`repo_stars`). The page buckets everything in the + their history goes back to the first (`repo_stars`); the same read keeps GitHub's own star total + per 30-minute slot (`repo_star_counts`, exact even when a star is taken back). The page buckets everything in the viewer's time zone (a `tr_tz` cookie app.js sets): ranges from today to 12 months, steps from 30 minutes to a day (a step that would make over 400 buckets, or finer than a day beyond the 30-minute detail, isn't offered). Charts are drawn by app.js from the numbers on the page. @@ -232,7 +233,7 @@ stable user ID are recorded in the body. | `submissions` | Tickets, routing snapshot, queue state, lease, reconcile counters, encrypted payload | | `submission_events` | Append-only timeline for investigation | | `contributor_settings`, `contributor_panels`, `contributor_tiers` | On/off, panel channel, published panel, and role tiers (role + minimum contributions) per workspace | -| `analytics_settings`, `download_assets`, `download_counts`, `download_days`, `download_sync`, `repo_stars` | Analytics: on/off; each release file and its total; downloads per 30 minutes (then per day); per repository, when recording began and the last slot read; stars with when each was given | +| `analytics_settings`, `download_assets`, `download_counts`, `download_days`, `download_sync`, `repo_stars`, `repo_star_counts` | Analytics: on/off; each release file and its total; downloads per 30 minutes (then per day); per repository, when recording began and the last slot read; stars with when each was given; star totals per 30 minutes | | `pull_index` | Pull requests of the indexed repositories (open, and closed for 90 days), with the issues each is for | | `repo_status_settings`, `repo_status` | Repo status: on/off, the repositories and how often per workspace; what was last read per repository (stats, the kept activity, the icon, the error and the GraphQL budget left) | | `contributor_links`, `contributor_verifications` | One GitHub account ↔ one Discord member per workspace; audit trail of every verification | diff --git a/src/analytics/queries.ts b/src/analytics/queries.ts index d1e6823..da41ac0 100644 --- a/src/analytics/queries.ts +++ b/src/analytics/queries.ts @@ -62,6 +62,8 @@ export interface AnalyticsData { issuesClosed: Metric; pullsMerged: Metric; stars: Metric; + /** Per app: its star total as GitHub last counted it (every 30 minutes), and the stars given in the period. */ + starsByApp: { label: string; total: number | null; gained: number }[]; releases: ReleaseHealth[]; } @@ -172,6 +174,17 @@ export async function analyticsData(q: Queryable, workspaceId: string, repos: Re `SELECT ${slot('starred_at')} AS at, count(*) AS n FROM repo_stars WHERE repo_id IN (SELECT value FROM json_each($1)) AND starred_at >= $2 AND starred_at < $3 GROUP BY 1`, [repoIds, span[0], span[1]])); + const { rows: totals } = await q.query<{ repo_id: number; stars_total: number | null }>('SELECT repo_id, stars_total FROM download_sync WHERE repo_id IN (SELECT value FROM json_each($1))', [repoIds]); + const { rows: given } = await q.query<{ repo_id: number; n: number }>( + 'SELECT repo_id, count(*) AS n FROM repo_stars WHERE repo_id IN (SELECT value FROM json_each($1)) AND starred_at >= $2 AND starred_at < $3 GROUP BY repo_id', + [repoIds, new Date(w.start), new Date(w.end)], + ); + const totalOf = new Map(totals.map((t) => [t.repo_id, t.stars_total === null ? null : Number(t.stars_total)])); + const gainedOf = new Map(given.map((g) => [g.repo_id, Number(g.n)])); + const starsByApp = repos + .map((r) => ({ label: appNames.get(r.id) ?? r.name, total: totalOf.get(r.id) ?? null, gained: gainedOf.get(r.id) ?? 0 })) + .sort((a, b) => (b.total ?? -1) - (a.total ?? -1) || b.gained - a.gained); + // ---- Release health: tickets while each release was the latest, per 1,000 of its downloads ---- const releases: ReleaseHealth[] = []; for (const repo of repos) { @@ -199,7 +212,7 @@ export async function analyticsData(q: Queryable, workspaceId: string, repos: Re } releases.sort((a, b) => (b.publishedAt?.getTime() ?? 0) - (a.publishedAt?.getTime() ?? 0)); - return { recordingSince, lastRead: lastReadMs ? new Date(lastReadMs) : null, downloads, tickets, issuesOpened, issuesClosed, pullsMerged, stars, releases: releases.slice(0, 15) }; + return { recordingSince, lastRead: lastReadMs ? new Date(lastReadMs) : null, downloads, tickets, issuesOpened, issuesClosed, pullsMerged, stars, starsByApp, releases: releases.slice(0, 15) }; } export { PLATFORM_NAMES }; diff --git a/src/analytics/recorder.ts b/src/analytics/recorder.ts index a177f90..1110b63 100644 --- a/src/analytics/recorder.ts +++ b/src/analytics/recorder.ts @@ -39,6 +39,7 @@ query AnalyticsReleases($owner: String!, $name: String!, $after: String) { const STARS_QUERY = ` query AnalyticsStars($owner: String!, $name: String!, $after: String) { repository(owner: $owner, name: $name) { + stargazerCount stargazers(first: 100, after: $after, orderBy: {field: STARRED_AT, direction: DESC}) { pageInfo { hasNextPage endCursor } edges { starredAt node { login } } @@ -237,15 +238,20 @@ export class AnalyticsRecorder { } } - /** The star history once (back to the first), then each time the stars added since. */ + /** + * The star history once (back to the first), then each time the stars added since; and the + * repository's star total as GitHub counts it, kept per 30-minute slot like the downloads. + */ private async recordStars(sync: SyncRow, now: number): Promise { const { db, github } = this.deps; const since = sync.stars_loaded_at ? (sync.stars_until_at?.getTime() ?? 0) - 60_000 : null; let newest = sync.stars_until_at?.getTime() ?? 0; let after: string | null = null; let complete = false; + let total: number | null = null; for (let page = 0; page < (since === null ? STAR_PAGES : 5); page++) { const d: any = await github!.graphql(sync.installation_id, STARS_QUERY, { owner: sync.owner, name: sync.name, after }); + if (total === null && Number.isFinite(Number(d?.repository?.stargazerCount))) total = Number(d.repository.stargazerCount); const conn = d?.repository?.stargazers; let older = false; for (const e of conn?.edges ?? []) { @@ -266,9 +272,15 @@ export class AnalyticsRecorder { after = conn.pageInfo.endCursor; } await db.query( - 'UPDATE download_sync SET stars_loaded_at = CASE WHEN $2 = 1 THEN COALESCE(stars_loaded_at, $4) ELSE stars_loaded_at END, stars_until_at = $3 WHERE repo_id = $1', - [sync.repo_id, complete ? 1 : 0, newest ? new Date(newest) : null, new Date(now)], + 'UPDATE download_sync SET stars_loaded_at = CASE WHEN $2 = 1 THEN COALESCE(stars_loaded_at, $4) ELSE stars_loaded_at END, stars_until_at = $3, stars_total = COALESCE($5, stars_total) WHERE repo_id = $1', + [sync.repo_id, complete ? 1 : 0, newest ? new Date(newest) : null, new Date(now), total], ); + if (total !== null) { + await db.query( + 'INSERT INTO repo_star_counts (repo_id, slot_at, total) VALUES ($1, $2, $3) ON CONFLICT (repo_id, slot_at) DO UPDATE SET total = excluded.total', + [sync.repo_id, new Date(slotOf(now)), total], + ); + } } } diff --git a/src/db/migrations/037_star_totals.sql b/src/db/migrations/037_star_totals.sql new file mode 100644 index 0000000..faa02fe --- /dev/null +++ b/src/db/migrations/037_star_totals.sql @@ -0,0 +1,10 @@ +-- Analytics: each repository's star total (GitHub's own count) every 30 minutes, with the download +-- snapshot. The star history (repo_stars) says when each star was given; these totals are exact +-- even when someone takes a star back. +CREATE TABLE repo_star_counts ( + repo_id INTEGER NOT NULL, + slot_at INTEGER NOT NULL, + total INTEGER NOT NULL, + PRIMARY KEY (repo_id, slot_at) +); +ALTER TABLE download_sync ADD COLUMN stars_total INTEGER; diff --git a/src/web/public/app.css b/src/web/public/app.css index ade5b62..2de1dfa 100644 --- a/src/web/public/app.css +++ b/src/web/public/app.css @@ -1790,6 +1790,9 @@ a.rs-why:hover { border-color: currentColor; } .an-card { padding: 16px 20px 14px; overflow: visible; } .an-ch { display: flex; align-items: baseline; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px; } .an-ch h2 { margin: 0; font-size: 14px; font-weight: 600; } +.an-metric { height: 30px; } +.an-metric .seg-item { height: 26px; font-weight: 600; } +.an-up { color: var(--ok-text); font-size: 12px; margin-left: 4px; } .an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; align-items: start; } .an-chart { margin: 0; } .an-plot { position: relative; height: 240px; } diff --git a/src/web/routes/analytics.ts b/src/web/routes/analytics.ts index d18c218..9d71d31 100644 --- a/src/web/routes/analytics.ts +++ b/src/web/routes/analytics.ts @@ -85,14 +85,26 @@ export function registerAnalyticsRoutes(app: FastifyInstance, web: Web): void { })}`; } + /** Each app's star total (GitHub's count) and the stars it was given in the period. */ + function starList(rows: AnalyticsData['starsByApp']): SafeHtml { + if (!rows.some((r) => r.total !== null || r.gained)) return html`

Star totals show up after the first read.

`; + const max = Math.max(1, ...rows.map((r) => r.total ?? 0)); + return html``; + } + function tile(label: string, value: string, d: SafeHtml, title?: string): SafeHtml { return html`
${label}
${value}
${d}
`; } - function body(ctx: WorkspaceRequestContext, w: Window, tz: string, d: AnalyticsData, repoChoice: string, apps: { id: number; name: string }[]): SafeHtml { + function body(ctx: WorkspaceRequestContext, w: Window, tz: string, d: AnalyticsData, repoChoice: string, apps: { id: number; name: string }[], metric: 'downloads' | 'stars'): SafeHtml { const compare = w.range.compare; - const href = (o: { range?: string; step?: string | null; app?: string }) => { + const href = (o: { range?: string; step?: string | null; app?: string; metric?: string }) => { const p = new URLSearchParams(); + if ((o.metric ?? metric) === 'stars') p.set('metric', 'stars'); const range = o.range ?? w.range.id; if (range !== 'today') p.set('range', range); const step = o.step === undefined ? (o.range ? null : w.step.id) : o.step; @@ -106,10 +118,14 @@ export function registerAnalyticsRoutes(app: FastifyInstance, web: Web): void { const prevPerK = d.downloads.prev ? (d.tickets.prev ?? 0) / d.downloads.prev * 1000 : null; // One repository (picked, or the only one): downloads by platform; several: all of them together. const single = d.downloads.series.length > 1; - const noDownloads = !d.recordingSince || (d.downloads.total === 0 && d.recordingSince.getTime() > w.start); + const noDownloads = metric === 'downloads' && (!d.recordingSince || (d.downloads.total === 0 && d.recordingSince.getTime() > w.start)); + const per = `per ${w.step.id === '1d' ? 'day' : w.step.label}`; + const switcher = html``; + const appLabel = single ? apps.find((a) => String(a.id) === repoChoice)?.name ?? apps[0]?.name ?? 'this app' : 'all apps'; return html`
${w.range.id !== 'today' ? html`` : ''} + ${metric === 'stars' ? html`` : ''} ${selectWrap(html``, { sm: true })} @@ -133,18 +149,25 @@ export function registerAnalyticsRoutes(app: FastifyInstance, web: Web): void { ${tile('Stars', compact(d.stars.total), delta(d.stars.total, d.stars.prev, compare, 'up'))} -
-

Downloads

${single ? 'by platform' : 'all apps'} · per ${w.step.id === '1d' ? 'day' : w.step.label}
- ${chart(w, tz, { id: 'downloads', title: 'Downloads', unit: 'Downloads', series: single ? d.downloads.series.map((s, i) => ({ ...s, slot: i + 1 })) : [{ ...d.downloads.series[0]!, slot: 1 }] })} +
+

${metric === 'stars' ? 'Stars' : 'Downloads'}

${switcher}${metric === 'stars' + ? `new stars · ${appLabel} · ${per} · back to the first star` + : `${single ? 'by platform' : 'all apps'} · ${per}`}
+ ${metric === 'stars' + ? chart(w, tz, { id: 'stars', title: 'New stars', unit: 'New stars', series: [{ key: 'stars', name: 'New stars', values: d.stars.values, slot: 1 }] }) + : chart(w, tz, { id: 'downloads', title: 'Downloads', unit: 'Downloads', series: single ? d.downloads.series.map((s, i) => ({ ...s, slot: i + 1 })) : [{ ...d.downloads.series[0]!, slot: 1 }] })}
-
+ ${metric === 'stars' ? html`
+

Stars by app

total, and new in this period
${starList(d.starsByApp)} +

Totals are GitHub’s own count, read every 30 minutes with the downloads, so a star taken back is counted out. New stars are the ones given in this period.

+
` : html`
${single ? '' : html`

By app

${bars(d.downloads.byApp, { empty: 'No downloads in this period.' })}
`}

Platforms

${bars(d.downloads.platforms, { empty: 'No downloads in this period.', colored: true })}

Processor

${bars(d.downloads.archs, { empty: 'No downloads in this period.' })}

Formats

${bars(d.downloads.formats, { empty: 'No downloads in this period.' })}

Versions

${bars(d.downloads.versions, { empty: 'No downloads in this period.' })}
-
+
`}

Activity

per ${w.step.id === '1d' ? 'day' : w.step.label}
@@ -178,7 +201,7 @@ export function registerAnalyticsRoutes(app: FastifyInstance, web: Web): void { app.get('/w/:wid/analytics', async (req, reply) => { const ctx = await web.requireWorkspace(req, reply, { permission: 'analytics.view' }); if (!ctx) return reply; - const q = req.query as { range?: string; step?: string; app?: string }; + const q = req.query as { range?: string; step?: string; app?: string; metric?: string }; const edit = can(ctx.membership, 'analytics.edit'); const s = await getAnalyticsSettings(deps.db, ctx.workspace.id); const tz = safeTimeZone((req.cookies as Record).tr_tz); @@ -209,7 +232,7 @@ export function registerAnalyticsRoutes(app: FastifyInstance, web: Web): void { const w = windowOf(q.range, q.step, tz); const picked = repoChoice === 'all' ? repos : repos.filter((r) => String(r.id) === repoChoice); const data = await analyticsData(deps.db, ctx.workspace.id, picked, w, appNames); - content = html`
${body(ctx, w, tz, data, repoChoice, choices)}
`; + content = html`
${body(ctx, w, tz, data, repoChoice, choices, q.metric === 'stars' ? 'stars' : 'downloads')}
`; } const page = html` ${pageHeader({ title: 'Analytics', description: 'Downloads, tickets, issues, pull requests and stars over time.', actions })} diff --git a/test/analytics.test.ts b/test/analytics.test.ts index 39d985d..f606082 100644 --- a/test/analytics.test.ts +++ b/test/analytics.test.ts @@ -130,9 +130,13 @@ describe('Analytics: recording downloads', () => { await tick(t0); const stars = async () => (await env.db.query('SELECT login FROM repo_stars ORDER BY login')).rows.map((r) => r.login); expect(await stars()).toEqual(['ana', 'ben']); + // GitHub's own total, per 30-minute slot, with the downloads. + expect((await env.db.query('SELECT slot_at, total FROM repo_star_counts')).rows).toEqual([{ slot_at: new Date(slotOf(t0)), total: 2 }]); repo().stars!.push({ login: 'cy', at: new Date().toISOString() }); await tick(t0 + SLOT_MS); expect(await stars()).toEqual(['ana', 'ben', 'cy']); + expect((await env.db.query('SELECT total FROM repo_star_counts ORDER BY slot_at')).rows.map((r) => r.total)).toEqual([2, 3]); + expect((await env.db.query('SELECT stars_total FROM download_sync')).rows[0].stars_total).toBe(3); // 30-minute rows older than 32 days are added up per UTC day. const old = Date.parse('2026-08-01T10:30:00Z'); const { rows } = await env.db.query('SELECT id FROM download_assets LIMIT 1'); @@ -188,6 +192,20 @@ describe('Analytics: the page', () => { expect(berlin.body).toContain('data-an-tz="Europe/Berlin"'); }); + it('switches the main chart to stars: new stars over time, and each app’s total', async () => { + await recorded(); + const body = (await page('/analytics?range=7d&metric=stars')).body; + expect(body).toMatch(/aria-label="Chart">Downloads<\/a>Stars<\/a>/); + expect(body).toContain('new stars · PhotoCraft'); + expect(body).toMatch(/data-an-chart='[^']*"name":"New stars"/); + // Total 2 (GitHub's count), 1 given in the last 7 days. + expect(body).toMatch(/Stars by app[\s\S]*?PhotoCraft<\/span>\s*2 \+1<\/span>/); + // The download breakdowns aren't shown; the app picker keeps the stars view. + expect(body).not.toContain('id="an-pl-h"'); + expect(body).toContain(''); + expect((await page('/analytics?range=7d')).body).toContain('id="an-pl-h"'); + }); + it('is on the Overview and in the sidebar; moderators need access, and Edit to turn it off', async () => { await recorded(); expect((await page('')).body).toContain('Open Analytics'); diff --git a/test/fakes.ts b/test/fakes.ts index a9d54a6..7f7925c 100644 --- a/test/fakes.ts +++ b/test/fakes.ts @@ -160,7 +160,7 @@ export class FakeGitHub { if (query.includes('stargazers(')) { const list = [...(r.stars ?? [])].sort((a, b) => at(b.at) - at(a.at)); const p = page(list, v.after, 100); - return { repository: { stargazers: { pageInfo: p.pageInfo, edges: p.nodes.map((x) => ({ starredAt: x.at, node: { login: x.login } })) } } }; + return { repository: { stargazerCount: list.length, stargazers: { pageInfo: p.pageInfo, edges: p.nodes.map((x) => ({ starredAt: x.at, node: { login: x.login } })) } } }; } if (query.includes('releases(')) { const p = page(newestFirst(r.releases ?? [], (x) => x.published_at), v.after, 50); diff --git a/test/helpers.ts b/test/helpers.ts index 938fae1..7ca8f0e 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -53,7 +53,7 @@ export function testDb(): Db { export async function resetDb(db: Db = testDb()): Promise { db.exec('DELETE FROM sessions; DELETE FROM oauth_states; DELETE FROM workspaces; DELETE FROM users; DELETE FROM issue_index; DELETE FROM issue_index_repos; DELETE FROM process_status;'); - db.exec('DELETE FROM pull_index; DELETE FROM repo_status; DELETE FROM download_counts; DELETE FROM download_days; DELETE FROM download_assets; DELETE FROM download_sync; DELETE FROM repo_stars;'); + db.exec('DELETE FROM pull_index; DELETE FROM repo_status; DELETE FROM download_counts; DELETE FROM download_days; DELETE FROM download_assets; DELETE FROM download_sync; DELETE FROM repo_stars; DELETE FROM repo_star_counts;'); db.exec('UPDATE server_settings SET dev_mode_on_at = NULL, dev_mode_by = NULL, dev_mode_off_at = NULL;'); }