Skip to content

Commit 950f7fb

Browse files
author
monster
committed
fix: choose github app install url by region
1 parent 1142b81 commit 950f7fb

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

frontend/src/components/console/settings/identities.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ import Icon from "@/components/common/Icon"
4343
import { useCommonData } from "../data-provider"
4444
import { Spinner } from "@/components/ui/spinner"
4545
import { useTranslation } from "react-i18next"
46+
import { useAppRuntime } from "@/components/app-runtime-provider"
4647

4748
export default function Identities() {
4849
const { t } = useTranslation()
49-
const githubAppInstallUrl = getGithubAppInstallUrl()
50+
const { serverConfig } = useAppRuntime()
51+
const isGlobalRegion = serverConfig?.region === "global"
52+
const githubAppInstallUrl = getGithubAppInstallUrl(isGlobalRegion)
5053
const [isDialogOpen, setIsDialogOpen] = useState(false)
5154
const [giteeBindLoading, setGiteeBindLoading] = useState(false)
5255
const [giteaBindLoading, setGiteaBindLoading] = useState(false)

frontend/src/utils/common.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ function commonText(key: string, options?: Record<string, unknown>): string {
1414
return String(i18n.t(key, options))
1515
}
1616

17-
/** GitHub App install URL: production uses monkeycode-ai.com, other domains use the dev app. */
18-
export function getGithubAppInstallUrl(): string {
19-
if (typeof window !== "undefined" && window.location.origin === "https://monkeycode-ai.com") {
20-
return "https://github.com/apps/monkeycode-ai/installations/new"
21-
}
22-
return "https://github.com/apps/mcai-dev-nb/installations/new"
17+
export function getGithubAppInstallUrl(isGlobalRegion: boolean): string {
18+
return isGlobalRegion
19+
? "https://github.com/apps/monkeycode-global/installations/new"
20+
: "https://github.com/apps/monkeycode-ai/installations/new"
2321
}
2422

2523
export function getHostStatusBadge(status?: string) {

frontend/test/console-settings-identities-i18n.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const sourceFiles = {
1010
editIdentity: readSource("../src/components/console/settings/edit-identity.tsx"),
1111
identities: readSource("../src/components/console/settings/identities.tsx"),
1212
};
13+
const commonSource = readSource("../src/utils/common.tsx");
1314
const cjkPattern = /[\u3400-\u9fff]/;
1415

1516
function readSource(path: string) {
@@ -40,3 +41,13 @@ test("设置身份页面提供中英文资源", () => {
4041
assert.equal(cn.consoleSettings.identities.delete.description, "确定要移除身份 \"{{name}}\" 吗?此操作不可撤销。");
4142
assert.equal(en.consoleSettings.identities.delete.description, "Remove identity \"{{name}}\"? This action cannot be undone.");
4243
});
44+
45+
test("GitHub App 绑定地址按国内和国际版切换", () => {
46+
assert.match(sourceFiles.identities, /useAppRuntime/);
47+
assert.match(sourceFiles.identities, /const isGlobalRegion = serverConfig\?\.region === "global"/);
48+
assert.match(sourceFiles.identities, /getGithubAppInstallUrl\(isGlobalRegion\)/);
49+
assert.match(commonSource, /getGithubAppInstallUrl\(isGlobalRegion: boolean\)/);
50+
assert.match(commonSource, /https:\/\/github\.com\/apps\/monkeycode-global\/installations\/new/);
51+
assert.match(commonSource, /https:\/\/github\.com\/apps\/monkeycode-ai\/installations\/new/);
52+
assert.doesNotMatch(commonSource, /mcai-dev-nb|window\.location\.origin/);
53+
});

0 commit comments

Comments
 (0)