Repository navigation
Expand file tree
/
Copy pathgithubRoadmap.ts
More file actions
500 lines (439 loc) · 17.2 KB
/
Copy pathgithubRoadmap.ts
File metadata and controls
500 lines (439 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
// src/libs/githubRoadmap.ts
/**
* GitHub Milestones roadmap fetcher.
*
* Fetches milestones from the datum-cloud/enhancements repo via the GraphQL
* API to drive the /roadmap Upcoming/Shipped tabs. Cover images are resolved
* separately from static repo assets (see `getRoadmapCoverImage`).
*
* Cache strategy:
* - Redis (when REDIS_URL is set): key `${redisKeyPrefix}github:roadmaps`, TTL 1 day
* (the github-milestone webhook invalidates this actively on status changes;
* the TTL is just a fallback)
* - In-memory Map: fallback for local dev (single-instance, no persistence)
*
* Auth: uses existing APP_ID / APP_PRIVATE_KEY / APP_INSTALLATION_ID env vars
* via the `graph()` helper in `src/libs/github.ts`.
*/
import { graph } from './github';
import { redisClient, redisKeyPrefix } from './strapi/_runtime';
export interface RoadmapMilestone {
number: number;
title: string;
slug: string;
summary?: string;
releaseDate: string;
githubUrl: string;
shipped: boolean;
}
const GITHUB_ORG = 'datum-cloud';
const GITHUB_REPO = 'enhancements';
// The github-milestone webhook actively invalidates this cache on status
// changes, so the TTL is just a fallback safety net rather than the primary
// refresh mechanism.
const CACHE_TTL_SECONDS = 24 * 60 * 60; // 1 day
const REDIS_CACHE_KEY = `${redisKeyPrefix}github:roadmaps`;
/** Logical cache name for admin force-regen (`POST /api/cache/strapi`). */
export const GITHUB_ROADMAPS_CACHE_KEY = 'github-roadmaps';
/** Module-level in-memory cache for local dev (no Redis). */
const memCache = {
data: null as RoadmapMilestone[] | null,
expiresAt: 0,
};
const ROADMAP_MILESTONES_QUERY = `
query GetRoadmapMilestones($owner: String!, $name: String!, $cursor: String) {
repository(owner: $owner, name: $name) {
milestones(first: 100, after: $cursor, states: [OPEN, CLOSED]) {
nodes {
number
title
description
dueOn
state
url
issues(first: 100) {
nodes {
number
title
url
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
`;
interface GitHubMilestoneIssueNode {
number?: number;
title?: string;
url?: string;
}
interface GitHubMilestoneNode {
number?: number;
title?: string;
description?: string | null;
dueOn?: string | null;
state?: string;
url?: string;
issues?: { nodes: GitHubMilestoneIssueNode[] };
}
interface GitHubMilestonesPage {
nodes: GitHubMilestoneNode[];
pageInfo: { hasNextPage: boolean; endCursor: string | null };
}
interface GitHubMilestonesResponse {
repository: {
milestones: GitHubMilestonesPage;
};
}
function isValidCachedMilestone(item: unknown): item is RoadmapMilestone {
if (!item || typeof item !== 'object') return false;
const record = item as Record<string, unknown>;
return (
typeof record.number === 'number' &&
typeof record.title === 'string' &&
typeof record.slug === 'string' &&
typeof record.releaseDate === 'string' &&
typeof record.githubUrl === 'string' &&
typeof record.shipped === 'boolean'
);
}
function isValidCachedMilestones(items: unknown): items is RoadmapMilestone[] {
return Array.isArray(items) && items.every(isValidCachedMilestone);
}
function sortMilestones(items: RoadmapMilestone[]): RoadmapMilestone[] {
return [...items].sort(
(a, b) => new Date(a.releaseDate).getTime() - new Date(b.releaseDate).getTime()
);
}
/** Read cached roadmap milestones from Redis. Returns null on miss or error. */
async function readFromRedis(): Promise<RoadmapMilestone[] | null> {
if (!redisClient) return null;
try {
const raw = await redisClient.get(REDIS_CACHE_KEY);
if (!raw) return null;
const parsed = JSON.parse(raw) as unknown;
if (!isValidCachedMilestones(parsed)) {
console.warn('[githubRoadmap] Invalid cached roadmaps data detected, refetching');
return null;
}
return parsed;
} catch (err) {
console.warn('[githubRoadmap] Redis read error:', err);
return null;
}
}
/** Write roadmap milestones to Redis with TTL. Silently logs on error. */
async function writeToRedis(items: RoadmapMilestone[]): Promise<void> {
if (!redisClient) return;
try {
await redisClient.set(REDIS_CACHE_KEY, JSON.stringify(items), 'EX', CACHE_TTL_SECONDS);
} catch (err) {
console.warn('[githubRoadmap] Redis write error:', err);
}
}
/** Escape HTML special characters so issue titles can't inject markup into the rendered summary. */
function escapeHtml(value: string): string {
return value
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
/** Build a markdown list of issues linked to a milestone, for appending to its description. */
function buildIssuesListMarkdown(issues: GitHubMilestoneIssueNode[]): string {
const validIssues = issues.filter(
(issue): issue is Required<GitHubMilestoneIssueNode> =>
typeof issue.number === 'number' &&
typeof issue.title === 'string' &&
typeof issue.url === 'string'
);
if (validIssues.length === 0) return '';
const items = validIssues
.map(
(issue) =>
`<li>${escapeHtml(issue.title)} <a href="${issue.url}" target="_blank" rel="noopener noreferrer">#${issue.number}</a></li>`
)
.join('');
return `<div><p style="margin-bottom: 2rem;"><strong>What's included in this milestone:</strong></p><ul style="margin-top: 0;">${items}</ul></div>`;
}
/** Fetch all milestone pages from the GitHub GraphQL API. */
async function fetchFromGitHub(): Promise<RoadmapMilestone[]> {
const items: RoadmapMilestone[] = [];
let cursor: string | null = null;
while (true) {
const variables: Record<string, unknown> = {
owner: GITHUB_ORG,
name: GITHUB_REPO,
};
if (cursor) variables.cursor = cursor;
let data: unknown;
try {
data = await graph(ROADMAP_MILESTONES_QUERY, variables);
} catch (err) {
console.error('[githubRoadmap] GraphQL fetch error:', err);
break;
}
const response = data as GitHubMilestonesResponse | null;
const page = response?.repository?.milestones;
if (!page) break;
for (const node of page.nodes) {
if (typeof node.number !== 'number' || !node.title || !node.dueOn) continue;
const issuesMarkdown = buildIssuesListMarkdown(node.issues?.nodes ?? []);
const summaryParts = [node.description, issuesMarkdown].filter((part): part is string =>
Boolean(part && part.trim())
);
items.push({
number: node.number,
title: node.title,
slug: getRoadmapSlug({ title: node.title }),
summary: summaryParts.length > 0 ? summaryParts.join('\n\n') : undefined,
releaseDate: node.dueOn,
githubUrl: node.url ?? `https://github.com/${GITHUB_ORG}/${GITHUB_REPO}`,
shipped: node.state === 'CLOSED',
});
}
if (!page.pageInfo.hasNextPage || !page.pageInfo.endCursor) break;
cursor = page.pageInfo.endCursor;
}
return sortMilestones(items);
}
/** Returns true when a non-expired roadmap milestones cache entry exists. */
export async function isGitHubRoadmapsCached(): Promise<boolean> {
if (redisClient) {
try {
return (await redisClient.get(REDIS_CACHE_KEY)) !== null;
} catch {
return false;
}
}
return memCache.data !== null && Date.now() < memCache.expiresAt;
}
/** Clear Redis and in-memory roadmap milestones cache without refetching. */
export async function clearGitHubRoadmapsCache(): Promise<void> {
if (redisClient) {
try {
await redisClient.del(REDIS_CACHE_KEY);
} catch (err) {
console.warn('[githubRoadmap] Redis delete error:', err);
}
}
memCache.data = null;
memCache.expiresAt = 0;
}
/**
* Clear roadmap milestones cache and fetch fresh data from GitHub.
* @throws When the GitHub fetch fails after cache was cleared
*/
export async function forceRegenerateGitHubRoadmaps(): Promise<RoadmapMilestone[]> {
await clearGitHubRoadmapsCache();
const items = await fetchFromGitHub();
await writeToRedis(items);
if (!redisClient) {
memCache.data = items;
memCache.expiresAt = Date.now() + CACHE_TTL_SECONDS * 1000;
}
return items;
}
/**
* Fetch roadmap milestones from the datum-cloud/enhancements GitHub repo.
*
* Cache read order:
* 1. Redis (if configured) — 30-min TTL
* 2. In-memory map (local dev, single-instance)
* 3. Live fetch from GitHub API → write result back to cache
*
* Never throws — returns empty array on complete failure.
*/
export async function fetchGitHubRoadmaps(): Promise<RoadmapMilestone[]> {
// 1. Try Redis
const cached = await readFromRedis();
if (cached) return cached;
// 2. Try in-memory (local dev / no Redis)
if (
!redisClient &&
memCache.data &&
Date.now() < memCache.expiresAt &&
isValidCachedMilestones(memCache.data)
) {
return memCache.data;
}
// 3. Fetch live
try {
const items = await fetchFromGitHub();
await writeToRedis(items);
if (!redisClient) {
memCache.data = items;
memCache.expiresAt = Date.now() + CACHE_TTL_SECONDS * 1000;
}
return items;
} catch (err) {
console.error('[githubRoadmap] Failed to fetch roadmap milestones:', err);
return [];
}
}
export interface GroupedRoadmaps {
upcoming: RoadmapMilestone[];
previous: RoadmapMilestone[];
}
export function isRoadmapShipped(milestone: Pick<RoadmapMilestone, 'shipped'>): boolean {
return milestone.shipped === true;
}
/**
* Group roadmaps into upcoming and previous based on shipped status.
* releaseDate is a due date (target completion), not a ship date, so a
* closed milestone is "previous" even if its due date hasn't passed yet.
*/
export function groupRoadmapsByDate(roadmaps: RoadmapMilestone[]): GroupedRoadmaps {
const upcoming: RoadmapMilestone[] = [];
const previous: RoadmapMilestone[] = [];
for (const roadmap of roadmaps) {
(isRoadmapShipped(roadmap) ? previous : upcoming).push(roadmap);
}
upcoming.sort((a, b) => new Date(a.releaseDate).getTime() - new Date(b.releaseDate).getTime());
previous.sort((a, b) => new Date(b.releaseDate).getTime() - new Date(a.releaseDate).getTime());
return { upcoming, previous };
}
/** Three-letter uppercase month from an ISO date string (e.g. `"2025-03-01"` → `"MAR"`). */
export function getMonthAbbreviation(dateString: string): string {
const date = new Date(dateString);
return date.toLocaleString('en-US', { month: 'short' }).toUpperCase();
}
/**
* Month key for aligning roadmap entries to calendar grid slots.
* @example getRoadmapMonthKey("2026-01-01") → "2026-01"
*/
export function getRoadmapMonthKey(releaseDate: string): string {
return releaseDate.slice(0, 7);
}
/**
* Extract the release codename from a milestone title, stripping the redundant
* month/year prefix GitHub milestones are named with (e.g. `August 2026 - "Armstrong"` → `Armstrong`).
* Falls back to a legacy "Name: Version" format, then the raw title.
*/
export function getRoadmapReleaseName(title: string): string {
const quotedNameMatch = title.match(/"([^"]+)"/);
if (quotedNameMatch?.[1]) return quotedNameMatch[1].trim();
const titleParts = title.split(':');
return titleParts[0]?.trim() ?? title;
}
/**
* Browser-tab title for a roadmap detail page, e.g. `August 2026 "Armstrong" Release - Datum Roadmap`.
* `milestone.title` already carries the month/year (`August 2026 - "Armstrong"`), so this must not
* append another formatted date on top of it (see datum-cloud/datum.net#1737).
*/
export function getRoadmapPageTitle(
milestone: Pick<RoadmapMilestone, 'title' | 'releaseDate' | 'shipped'>
): string {
const formattedDate = new Date(milestone.releaseDate).toLocaleString('en-US', {
month: 'long',
year: 'numeric',
});
const releaseName = getRoadmapReleaseName(milestone.title);
const kind = milestone.shipped ? 'Release' : 'Milestone';
return `${formattedDate} "${releaseName}" ${kind} - Datum Roadmap`;
}
/**
* Hand-written SEO descriptions per roadmap milestone, keyed by slug (@see getRoadmapSlug).
* The milestone `summary` is release-note HTML (including an inline-styled issue list) meant
* for the page body — it must never be dumped into `<meta name="description">` verbatim (see
* datum-cloud/datum.net#1737). There's no formulaic way to derive good SEO copy from that HTML,
* so this is a manually curated override map; unlisted milestones fall back to a stripped,
* truncated version of the summary via `getRoadmapSeoDescription`.
*/
const ROADMAP_SEO_DESCRIPTIONS: Record<string, string> = {
'august-2026-armstrong':
"Datum's August 2026 Armstrong release: an Internet NAT66 gateway for Galactic VPC, billing for Datum Compute, horizontal autoscaling, and customer-facing logs.",
'september-2026-brother-ray':
"What shipped in Datum's September 2026 Brother Ray release: Datum Compute for instant secure workloads, a NAT64 gateway for Galactic VPC, and BIMI.",
'november-2026-lovelace':
"See what's planned for Datum's November 2026 Lovelace milestone, track the open issues on GitHub, and request or vote for the features you want next.",
'june-2026-katherine':
"What shipped in Datum's June 2026 Katherine release: a reworked quota page with display names and product grouping across Datum Cloud services.",
'january-2026-mary-elizabeth':
"What shipped in Datum's January 2026 Mary Elizabeth release: the Datum Desktop MVP, apex ALIAS records for DNS, and Grafana metrics export.",
'march-2026-dolores':
"What shipped in Datum's March 2026 Dolores release: service accounts, one-click WAF, fine-grained roles, and on-demand access with the waitlist retired.",
'december-2026-hopper':
"See what's planned for Datum's December 2026 Hopper milestone, the final release of the year, and vote for the features you want on the open roadmap.",
'july-2026-kwolek':
"What shipped in Datum's July 2026 Kwolek release: the Platform and Dedicated Cloud landing pages, a new onboarding flow, and billing accounts.",
'april-2026-thuerk':
"What shipped in Datum's April 2026 Thuerk release: HTTP/3 at the edge, datumctl contexts, the Iroh Gateway, and the first public Agent Skills.",
'october-2026-hedy':
"See what's planned for Datum's October 2026 Hedy milestone, follow the issues on GitHub, and vote for the features you want next on the open roadmap.",
'may-2026-timbl':
"What shipped in Datum's May 2026 TimBL release: Galactic VPC underlay design, activity timelines across the portal, and usage billing and metering.",
'february-2026-blankenbaker':
"What shipped in Datum's February 2026 Blankenbaker release: Datum Desktop, configurable WAF at the proxy and path level, and semantic activity logs.",
};
/** Strip tags and collapse whitespace, for a summary-derived meta description fallback. */
function stripHtmlForDescription(html: string): string {
return html
.replace(/<[^>]*>/g, ' ')
.replace(/\s+/g, ' ')
.trim();
}
const MAX_SEO_DESCRIPTION_LENGTH = 160;
/**
* SEO meta description for a roadmap detail page. Prefers the curated override above;
* falls back to a plain-text, length-capped version of the milestone summary rather than
* the raw HTML that used to leak into the meta tag.
*/
export function getRoadmapSeoDescription(
milestone: Pick<RoadmapMilestone, 'slug' | 'summary' | 'releaseDate'>
): string {
const override = ROADMAP_SEO_DESCRIPTIONS[milestone.slug];
if (override) return override;
if (milestone.summary) {
const plainText = stripHtmlForDescription(milestone.summary);
if (plainText) {
return plainText.length > MAX_SEO_DESCRIPTION_LENGTH
? `${plainText.slice(0, MAX_SEO_DESCRIPTION_LENGTH - 1).trimEnd()}…`
: plainText;
}
}
const formattedDate = new Date(milestone.releaseDate).toLocaleString('en-US', {
month: 'long',
year: 'numeric',
});
return `Datum roadmap for ${formattedDate}.`;
}
/** URL slug for roadmap detail pages, derived from the milestone title. */
export function getRoadmapSlug(milestone: Pick<RoadmapMilestone, 'title'>): string {
return milestone.title
.toLowerCase()
.trim()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
}
/**
* Days between today and the release date (releases are always on the 1st of the month).
* Returns a positive number for future dates, negative for past dates.
*/
export function getDaysUntilRelease(releaseDate: string): number {
const release = new Date(releaseDate);
const today = new Date();
today.setHours(0, 0, 0, 0);
return Math.ceil((release.getTime() - today.getTime()) / 86_400_000);
}
/** Build-time manifest of static roadmap cover images, keyed by milestone number. */
const coverImageModules = import.meta.glob<{ default: ImageMetadata }>(
'/src/assets/roadmap/*.{png,jpg,jpeg,webp,avif}',
{ eager: true }
);
const coverImagesByNumber = new Map<number, ImageMetadata>();
for (const [path, mod] of Object.entries(coverImageModules)) {
const match = path.match(/\/(\d+)\.[a-z]+$/i);
if (!match) continue;
coverImagesByNumber.set(Number(match[1]), mod.default);
}
/** Resolve the static cover image asset for a milestone, keyed by milestone number. */
export function getRoadmapCoverImage(number: number): ImageMetadata | undefined {
return coverImagesByNumber.get(number);
}