Skip to content

Commit 555fb6f

Browse files
authored
fix(web): follow configured desktop update repository (pingdotgg#21210)
1 parent 27ccbe9 commit 555fb6f

6 files changed

Lines changed: 102 additions & 11 deletions

File tree

‎apps/web/src/components/desktopUpdate.logic.test.ts‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,37 @@ describe("getDesktopUpdateActionError", () => {
201201

202202
describe("desktop update UI helpers", () => {
203203
it("builds the stable release URL for a downloaded version", () => {
204-
expect(getDesktopUpdateReleaseUrl("0.0.30")).toBe(
204+
expect(getDesktopUpdateReleaseUrl("0.0.30", "pingdotgg/t3code")).toBe(
205205
"https://github.com/pingdotgg/t3code/releases/tag/v0.0.30",
206206
);
207207
});
208208

209+
it("uses the configured desktop update repository for release URLs", () => {
210+
expect(getDesktopUpdateReleaseUrl("1.2.3", "JustYannicc/t3code")).toBe(
211+
"https://github.com/JustYannicc/t3code/releases/tag/v1.2.3",
212+
);
213+
expect(getDesktopUpdateReleaseHistoryUrl("JustYannicc/t3code")).toBe(
214+
"https://github.com/JustYannicc/t3code/releases",
215+
);
216+
});
217+
218+
it.each([
219+
"owner/repo/extra",
220+
"owner#notes/repo",
221+
"owner/repo#notes",
222+
"owner?tab=notes/repo",
223+
"owner/repo?tab=notes",
224+
])("falls back to upstream for an invalid configured repository: %s", (repository) => {
225+
expect(getDesktopUpdateReleaseHistoryUrl(repository)).toBe(
226+
"https://github.com/pingdotgg/t3code/releases",
227+
);
228+
expect(getDesktopUpdateReleaseUrl("1.2.3", repository)).toBe(
229+
"https://github.com/pingdotgg/t3code/releases/tag/v1.2.3",
230+
);
231+
});
232+
209233
it("builds the nightly release URL without dropping its version suffix", () => {
210-
expect(getDesktopUpdateReleaseUrl("0.0.30-nightly.20260728.931")).toBe(
234+
expect(getDesktopUpdateReleaseUrl("0.0.30-nightly.20260728.931", "pingdotgg/t3code")).toBe(
211235
"https://github.com/pingdotgg/t3code/releases/tag/v0.0.30-nightly.20260728.931",
212236
);
213237
});
@@ -218,7 +242,7 @@ describe("desktop update UI helpers", () => {
218242
});
219243

220244
it("builds the release history URL", () => {
221-
expect(getDesktopUpdateReleaseHistoryUrl()).toBe(
245+
expect(getDesktopUpdateReleaseHistoryUrl("pingdotgg/t3code")).toBe(
222246
"https://github.com/pingdotgg/t3code/releases",
223247
);
224248
});

‎apps/web/src/components/desktopUpdate.logic.ts‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@ import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/con
22

33
export type DesktopUpdateButtonAction = "download" | "install" | "none";
44

5-
const DESKTOP_RELEASE_HISTORY_URL = "https://github.com/pingdotgg/t3code/releases";
6-
const DESKTOP_RELEASE_TAG_URL = `${DESKTOP_RELEASE_HISTORY_URL}/tag`;
5+
const DEFAULT_DESKTOP_RELEASE_REPOSITORY = "pingdotgg/t3code";
6+
const GITHUB_REPOSITORY_SEGMENT = /^[A-Za-z0-9._-]+$/u;
7+
8+
function isValidRepositorySegment(value: string | undefined): value is string {
9+
return (
10+
value !== undefined && value !== "." && value !== ".." && GITHUB_REPOSITORY_SEGMENT.test(value)
11+
);
12+
}
13+
14+
function desktopReleaseRepositoryUrl(repository: string | undefined): string {
15+
const configuredRepository = repository?.trim() ?? "";
16+
const [owner, name, ...extra] = configuredRepository.split("/");
17+
const releaseRepository =
18+
isValidRepositorySegment(owner) && isValidRepositorySegment(name) && extra.length === 0
19+
? configuredRepository
20+
: DEFAULT_DESKTOP_RELEASE_REPOSITORY;
21+
return `https://github.com/${releaseRepository}/releases`;
22+
}
723

824
/**
925
* The main process fills `downloadedVersion` from the updater's `update-downloaded`
@@ -14,14 +30,19 @@ export function getDesktopUpdateDownloadedVersion(state: DesktopUpdateState): st
1430
return state.downloadedVersion ?? state.availableVersion;
1531
}
1632

17-
export function getDesktopUpdateReleaseUrl(version: string | null): string | null {
33+
export function getDesktopUpdateReleaseUrl(
34+
version: string | null,
35+
repository: string | undefined = import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY,
36+
): string | null {
1837
const normalizedVersion = version?.trim();
1938
if (!normalizedVersion) return null;
20-
return `${DESKTOP_RELEASE_TAG_URL}/v${encodeURIComponent(normalizedVersion)}`;
39+
return `${desktopReleaseRepositoryUrl(repository)}/tag/v${encodeURIComponent(normalizedVersion)}`;
2140
}
2241

23-
export function getDesktopUpdateReleaseHistoryUrl(): string {
24-
return DESKTOP_RELEASE_HISTORY_URL;
42+
export function getDesktopUpdateReleaseHistoryUrl(
43+
repository: string | undefined = import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY,
44+
): string {
45+
return desktopReleaseRepositoryUrl(repository);
2546
}
2647

2748
export function resolveDesktopUpdateButtonAction(

‎apps/web/src/components/desktopUpdate.toast.test.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isValidElement, type ReactElement, type ReactNode } from "react";
2-
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
33
import type { DesktopUpdateState } from "@t3tools/contracts";
44

55
const testState = vi.hoisted(() => ({
@@ -64,6 +64,24 @@ describe("showDesktopUpdateDownloadedToast", () => {
6464
testState.addToast.mockReset();
6565
});
6666

67+
afterEach(() => {
68+
vi.unstubAllEnvs();
69+
});
70+
71+
it("opens release notes from the configured repository", async () => {
72+
vi.stubEnv("T3CODE_DESKTOP_UPDATE_REPOSITORY", "JustYannicc/t3code");
73+
const openExternal = vi.fn().mockResolvedValue(true);
74+
75+
showDesktopUpdateDownloadedToast({ openExternal }, downloadedState());
76+
findReleaseNotesLink(getDescription())?.props.onClick?.();
77+
78+
await vi.waitFor(() => {
79+
expect(openExternal).toHaveBeenCalledWith(
80+
"https://github.com/JustYannicc/t3code/releases/tag/v0.0.30",
81+
);
82+
});
83+
});
84+
6785
it("opens the downloaded version's release notes", async () => {
6886
const openExternal = vi.fn().mockResolvedValue(true);
6987

‎apps/web/src/components/sidebar/SidebarUpdateReleaseNotes.test.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DesktopUpdateState } from "@t3tools/contracts";
22
import { isValidElement, type MouseEvent, type ReactElement, type ReactNode } from "react";
3-
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
3+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
44

55
const testState = vi.hoisted(() => ({
66
addToast: vi.fn(),
@@ -74,6 +74,26 @@ describe("SidebarUpdateReleaseNotes", () => {
7474
testState.addToast.mockReset();
7575
});
7676

77+
afterEach(() => {
78+
vi.unstubAllEnvs();
79+
});
80+
81+
it("uses the configured repository for release links", () => {
82+
vi.stubEnv("T3CODE_DESKTOP_UPDATE_REPOSITORY", "JustYannicc/t3code");
83+
const anchors = collectAnchors(
84+
renderNotes({
85+
...baseState,
86+
releaseNotes: [{ version: "0.0.36-nightly.3", items: ["Change 3"], totalItems: 1 }],
87+
omittedReleaseCount: 1,
88+
}),
89+
);
90+
91+
expect(anchors.map(({ props }) => props.href)).toEqual([
92+
"https://github.com/JustYannicc/t3code/releases/tag/v0.0.36-nightly.3",
93+
"https://github.com/JustYannicc/t3code/releases",
94+
]);
95+
});
96+
7797
it("links each preview to its exact release and labels hidden changes", () => {
7898
const anchors = collectAnchors(
7999
renderNotes({

‎apps/web/src/vite-env.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface ImportMetaEnv {
1313
readonly VITE_RELAY_OTLP_TRACES_URL: string;
1414
readonly VITE_RELAY_OTLP_TRACES_DATASET: string;
1515
readonly VITE_RELAY_OTLP_TRACES_TOKEN: string;
16+
readonly T3CODE_DESKTOP_UPDATE_REPOSITORY: string;
1617
readonly APP_VERSION: string;
1718
}
1819

‎apps/web/vite.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const configuredRelayTracingDataset = repoEnv.VITE_RELAY_OTLP_TRACES_DATASET?.tr
4242
const configuredRelayTracingToken = repoEnv.VITE_RELAY_OTLP_TRACES_TOKEN?.trim() || "";
4343
const configuredHostedAppChannel = process.env.VITE_HOSTED_APP_CHANNEL?.trim() || "";
4444
const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version;
45+
const configuredDesktopUpdateRepository =
46+
process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
47+
process.env.GITHUB_REPOSITORY?.trim() ||
48+
"";
4549
const configuredHostedAppUrl = (() => {
4650
const explicitHostedAppUrl = process.env.VITE_HOSTED_APP_URL?.trim();
4751
if (explicitHostedAppUrl) {
@@ -215,6 +219,9 @@ export default defineConfig(() => {
215219
"import.meta.env.VITE_RELAY_OTLP_TRACES_TOKEN": JSON.stringify(configuredRelayTracingToken),
216220
"import.meta.env.VITE_HOSTED_APP_URL": JSON.stringify(configuredHostedAppUrl ?? ""),
217221
"import.meta.env.VITE_HOSTED_APP_CHANNEL": JSON.stringify(configuredHostedAppChannel),
222+
"import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY": JSON.stringify(
223+
configuredDesktopUpdateRepository,
224+
),
218225
"import.meta.env.APP_VERSION": JSON.stringify(configuredAppVersion),
219226
},
220227
resolve: {

0 commit comments

Comments
 (0)