mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-24 21:29:00 +08:00
- 新建项目(new-project.tsx):项目页/空态入口 → 选已绑定 Git 账号 → 全屏可搜索选仓库(含手动填地址)→ 命名创建,成功进项目详情
- Git 账号管理(git-identities.tsx):列表 + 删除(409 占用提示)+ 添加方式选择(OAuth 一键授权 / 其他平台手动 Token)
- 绑定/编辑账号(git-identity-form.tsx):手动 PAT 表单,选平台自动填默认地址;?id= 进入编辑,platform/base_url 锁定、Token 留空不改、GitHub App 身份隐藏 Token
- OAuth 授权(git-oauth.tsx):复用登录 WebView 的域名判定,标准浏览器 UA 规避第三方(Google 等)对内嵌 WebView 的登录拦截,支持复制链接
- API/类型(client.ts/types.ts):createProject、git-identities 增删查/详情/更新、{platform}/authorize_url
- 我的页新增「集成」分组 + Git 账号入口;项目页改聚焦刷新并加「新建」入口
- 修复:创建/表单页改 push 屏,消除 iOS modal 下 GlassNav 顶部空白;PreviewBrowser cookie 行为注释(host-only 域隔离,刻意不加 sharedCookiesEnabled/incognito);Icons 补 key/link
51 lines
2.3 KiB
TypeScript
51 lines
2.3 KiB
TypeScript
/**
|
||
* Git 平台元数据 —— 对齐 Web 端 add-identity.tsx 的平台列表与默认地址,
|
||
* 以及 utils/common.tsx 的 GitHub App 安装地址逻辑。
|
||
*/
|
||
import { getBaseUrl } from '@/api/client';
|
||
import type { GitPlatform } from '@/api/types';
|
||
|
||
export interface GitPlatformDef {
|
||
key: GitPlatform;
|
||
label: string;
|
||
/** 选中平台后自动填入的默认 Base URL(用户仍可改为自建实例地址) */
|
||
defaultBaseUrl: string;
|
||
/** 是否支持 OAuth 一键授权(其余平台只能手动填 Access Token) */
|
||
oauth: boolean;
|
||
}
|
||
|
||
// 顺序与 Web 平台下拉一致。GitCode 在后端对应 atomgit。
|
||
export const GIT_PLATFORMS: GitPlatformDef[] = [
|
||
{ key: 'github', label: 'GitHub', defaultBaseUrl: 'https://github.com', oauth: true },
|
||
{ key: 'gitlab', label: 'GitLab', defaultBaseUrl: 'https://gitlab.com', oauth: true },
|
||
{ key: 'gitee', label: 'Gitee', defaultBaseUrl: 'https://gitee.com', oauth: true },
|
||
{ key: 'gitea', label: 'Gitea', defaultBaseUrl: 'https://gitea.com', oauth: true },
|
||
{ key: 'codeup', label: 'Codeup', defaultBaseUrl: 'https://openapi-rdc.aliyuncs.com', oauth: false },
|
||
{ key: 'cnb', label: 'CNB', defaultBaseUrl: 'https://api.cnb.cool', oauth: false },
|
||
{ key: 'atomgit', label: 'GitCode', defaultBaseUrl: 'https://api.atomgit.com', oauth: false },
|
||
];
|
||
|
||
/** 支持 OAuth 一键授权的平台(添加身份时的「一键授权」入口) */
|
||
export const OAUTH_PLATFORMS = GIT_PLATFORMS.filter((p) => p.oauth);
|
||
|
||
export function gitPlatformDef(platform?: string): GitPlatformDef | undefined {
|
||
return GIT_PLATFORMS.find((p) => p.key === platform);
|
||
}
|
||
|
||
export function gitPlatformLabel(platform?: string): string {
|
||
return gitPlatformDef(platform)?.label ?? (platform || '未知平台');
|
||
}
|
||
|
||
/** GitLab OAuth 授权需要指定实例 base,默认公有云。 */
|
||
export const GITLAB_DEFAULT_BASE = 'https://gitlab.com';
|
||
|
||
/**
|
||
* GitHub App 安装地址:生产环境用 monkeycode-ai,其它环境用开发 App(对齐 Web getGithubAppInstallUrl)。
|
||
* 安装完成后 GitHub 会回跳后端 setup 回调,再重定向回站点,WebView 据此判定完成。
|
||
*/
|
||
export function githubAppInstallUrl(): string {
|
||
return getBaseUrl() === 'https://monkeycode-ai.com'
|
||
? 'https://github.com/apps/monkeycode-ai/installations/new'
|
||
: 'https://github.com/apps/mcai-dev-nb/installations/new';
|
||
}
|