Files
Situation-Awareness-Platfor…/src/api/repo/index.ts
2025-03-12 18:41:20 +08:00

1545 lines
40 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import request from '@/utils/request';
import * as types from '@/api/repo/types';
import { reqCatch, reqCatchV2, type catchRt } from '@/utils/catch';
import type { AxiosResponse } from 'axios';
import type { CommonWithPageReqType } from '@/utils/types';
const fileUploadBaseURL = (import.meta as any).env.VITE_FILE_HOST;
const fileDownloadBaseURL = (import.meta as any).env.VITE_DOWNLOAD_HOST;
// 创建一个项目创建CR仓库时请求Headers中x-zone和x-cell为必填参数
export function createRepo(data: types.createRepoReqType): Promise<types.commonRepoResType> {
return request({
url: '/api/v2/projects',
method: 'post',
data
});
}
// 判断是否可以创建公开项目
export function createPublicProject(data: types.createRepoResType): Promise<types.createRepoResType> {
return request({
url: `/api/v1/global/setting?key=${data.key}`,
method: 'get',
data
});
}
// 项目是否可达
export function repoReachable(data: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: '/api/v2/projects/reachable',
method: 'post',
data
})
);
}
// 获取一个项目
export function getRepo(params: types.commonRepoReqType, config?: object): Promise<types.commonRepoResType> {
return reqCatch(
() =>
request(
{
url: `/api/v2/projects/${params.repoId}?view=all`,
method: 'get',
params: {
statistics: params?.statistics
}
},
config
),
params
);
}
// 获取项目详情
export function getRepoDetail(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}`,
method: 'get'
}),
params
);
}
// 修改一个项目
export function editRepo(data: Partial<types.commonRepoResType> & { repoId: string | number }): Promise<any> {
const { repoId, ...conf } = data;
return reqCatch(
() =>
request({
url: `/api/v2/projects/${repoId}`,
method: 'put',
data: conf
}),
data
);
}
// 删除一个项目
export function deleteRepo(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}`,
method: 'delete',
params
}),
params
);
}
// 项目转移 与接口命名保持一致
export function transferRepo(data: { projectId: string; namespace: string }): Promise<any> {
const { projectId, namespace } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${projectId}/transfer`,
method: 'put',
data: { namespace }
})
);
}
/** 获取项目分支 */
export function getRepoBranches(params: {
project_id: string | number;
branch_type?: 'not_protect' | '';
per_page?: number;
view?: string;
search?: string;
}): Promise<any> {
return reqCatch(() =>
request(
{
url: `/api/v2/projects/${params.project_id}/repository/branches`,
method: 'get',
params
},
{ customError: true }
)
);
}
/** 获取项目保护分支 */
export function getRepoProtectedBranches(params: { project_id: string | number }): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${params.project_id}/protected_branches`,
method: 'get',
params
})
);
}
/** 新增项目保护分支 */
export function createProtectedBranches(data: {
project_id: string | number;
conf: Record<string, any>;
}): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${data.project_id}/batch/protected_branches`,
method: 'post',
data: data.conf
}),
data
);
}
/** 编辑项目保护分支 */
export function editProtectedBranches(data: { project_id: string | number; conf: Record<string, any> }): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${data.project_id}/repository/branches/protect`,
method: 'put',
data: data.conf
}),
data
);
}
/** 删除项目保护分支 */
export function delProtectedBranches(data: { project_id: string | number; branch_name: string }): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${data.project_id}/protected_branches/${data.branch_name}`,
method: 'delete'
}),
data
);
}
// 创建分支
export function createBranch(data: { repoId: string | number; ref: string; branch: string }): Promise<any> {
return request({
url: `/api/v2/projects/${data.repoId}/repository/branches`,
method: 'post',
data
});
}
/** 获取保护分支信息 */
export function getProtectedBranchInfo(params: { project_id: string | number; branch_name: string }): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.project_id}/protected_branches/${params.branch_name}`
}),
params
);
}
export function getBranchDetail(params: { project_id: string | number; branch_name: string }): Promise<any> {
return request({
url: `/api/v2/projects/${params.project_id}/repository/branches/${params.branch_name}`
});
}
/** 获取项目保护tag */
export function getProtectedTags(params: { project_id: string | number }): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v1/projects/${params.project_id}/protected_tags`,
params: {
page: 1,
per_page: 100,
...params
}
})
);
}
/** 创建项目保护tag */
export function createProtectedTags(data: {
project_id: string | number;
name: string;
create_access_level: number | string;
}): Promise<any> {
const { project_id, ...conf } = data;
return reqCatch(
() =>
request({
url: `/api/v1/projects/${project_id}/protected_tags`,
method: 'post',
data: conf
}),
{}
);
}
/** 编辑项目保护tag权限 */
export function editProjectTags(data: {
project_id: string | number;
name: string;
create_access_level: number | string;
}): Promise<any> {
const { project_id, ...conf } = data;
return reqCatch(
() =>
request({
url: `/api/v1/projects/${project_id}/protected_tags`,
method: 'put',
data: conf
}),
{}
);
}
/** 删除项目保护分支tag权限 */
export function delProjectTags(data: { project_id: string | number; name: string }) {
return reqCatch(
() =>
request({
url: `/api/v1/projects/${data.project_id}/protected_tags/${data.name}`,
method: 'delete'
}),
{}
);
}
/** 获取用户组织列表 */
export function getGroupMembers(): Promise<any> {
return reqCatch(() =>
request({
url: 'api/v2/groups/list',
params: {
page: 1,
per_page: 50,
develop_mode: 'normal',
maintained: true
}
})
);
}
/** 项目设置模块开发 */
export function getSettingsValues(data: { repoId: string | number }): Promise<any> {
const { repoId } = data;
return reqCatch(() =>
request(
{
url: `/api/v2/projects/${repoId}/module/setting`,
method: 'get',
params: data
},
{
customError: true
}
)
);
}
/** 更新项目设置模块开关 */
export function updateSettingsValues(data: {
repoId: string | number;
modules: { key: string; value: string | number; type: string }[];
}): Promise<any> {
const { repoId, modules } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/module/setting`,
method: 'put',
data: { modules }
})
);
}
/** 修改项目设置模块开关 */
export function changeSettingsValues(data: {
repoId: string | number;
modules: { key: string; value: string | number; type: string };
}): Promise<any> {
const { repoId, modules } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/module_item/setting`,
method: 'put',
data: modules
})
);
}
/** 项目设置仓库分支权限设置 */
export function getRepoBranchSetting(data: { project_id: string }) {
const { project_id } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/policies/general`
})
);
}
/** 修改项目设置仓库配置 */
export function editRepoBranchSetting(data: { project_id: string; conf: Record<string, any> }) {
const { project_id, conf } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/policies/general`,
method: 'put',
data: conf
})
);
}
/* 项目webhooks相关开始 */
/** 获取项目分支webhook */
export function getRepoWebhooks(params: { repoId: string | null; conf: Record<string, any> }) {
return reqCatch(
() =>
request({
url: `/api/v1/projects/${params.repoId}/hooks`,
params: params.conf
}),
params
);
}
/** 新增webhook配置 */
export function createWebhook(data: { repoId: string | number | null; conf: Record<string, any> }) {
return reqCatch(
() =>
request(
{
url: `/api/v1/projects/${data.repoId}/hooks`,
data: data.conf,
method: 'post'
},
{
customError: true
}
),
data
);
}
/** 编辑webhook */
export function editWebhook(data: { repoId: string | null; hook_id: string; conf: Record<string, any> }) {
const { repoId, hook_id, conf } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/hooks/${hook_id}`,
method: 'put',
data: conf
})
);
}
/** 获取webhook详情 */
export function getWebhookDetail(data: { repoId: string | null; hook_id: string }) {
const { repoId, hook_id } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/hooks/${hook_id}`
})
);
}
/** 获取webhook请求日志 */
export function getWebhookLogs(data: { repoId: string | null; hook_id: string; page?: number; per_page?: number }) {
const { repoId, hook_id, ...param } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/hooks/${hook_id}/logs`,
params: Object.assign({ page: 1, per_page: 10 }, param)
})
);
}
/** 获取项目webhook日志详情 */
export function getWebhookLogDetail(data: { repoId: string | null; hook_id: string; id: string }) {
const { repoId, hook_id, id } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/hooks/${hook_id}/logs/${id}`
})
);
}
/** 删除webhook */
export function deleteWebHook(data: { repoId: string | null; hook_id: string }) {
const { repoId, hook_id } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/hooks/${hook_id}`,
method: 'delete'
})
);
}
/* 项目相关webhooks结束 */
// 获取开发者分支权限设置
export function repoPolicies(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/policies/general`,
method: 'get',
params
});
}
// 开发者分支创建权限设置、开发者Tag创建权限设置、分支名规则设置、Tag名规则设置
export function editRepoPolicies(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${data.repoId}/policies/general`,
method: 'put',
data
});
}
// 获取合并请求设置
export function getMergeSetting(params: types.commonRepoReqType): Promise<any> {
const { repoId } = params;
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/merge_requests/setting`,
method: 'get',
params
})
);
}
// 合并请求设置
export function editMergeSetting(data: {
repoId: string;
conf: Record<string, any>;
}): Promise<types.commonRepoResType> {
const { repoId, conf } = data;
return request({
url: `/api/v2/projects/${repoId}/merge_requests/setting`,
method: 'put',
data: conf
});
}
// 获取经过身份验证的用户的可见项目列表
export function getRepos(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v1/projects`,
method: 'get',
params
}),
params
);
}
// 取消收藏一个项目
export function unstarRepo(data: types.commonRepoReqType): Promise<AxiosResponse<{ star_count: number }>> {
return request({
url: `/api/v2/projects/${data.repoId}/unstar`,
method: 'post',
data
});
}
// 收藏一个项目
export function starRepo(data: types.commonRepoReqType): Promise<AxiosResponse<{ star_count: number }>> {
return request({
url: `/api/v2/projects/${data.repoId}/star`,
method: 'post',
data
});
}
// 取消归档项目
export function unarchiveRepo(data: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${data.repoId}/unarchive`,
method: 'post',
data
}),
data
);
}
// 归档项目
export function archiveRepo(data: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${data.repoId}/archive`,
method: 'post',
data
}),
data
);
}
// Fork一个项目
export function createForkRepo(data: types.forkRepoReqType): Promise<types.forkRepoReqType> {
return request({
url: `/api/v2/projects/${data.repoId}/fork`,
method: 'post',
data
});
}
// 删除Fork项目
export function deleteForkRepo(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}/fork`,
method: 'delete',
params
}),
params
);
}
/** 精准搜索匹配项目中的成员 */
export function toSearchRepoMember(repoId: string, username: string) {
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/members/${username}`
})
);
}
// 获取项目中的语言
export function getRepoLanguages(params: types.commonRepoReqType): Promise<any> {
return request(
{
url: `/api/v2/projects/${params.repoId}/languages`,
method: 'get',
params
},
{
customError: true
}
);
}
// 获取项目审计日志列表
export function getRepoAuditLogs(params: {
repoId: string | number;
param: {
page?: number;
per_page?: number;
search?: string;
log_type?: string;
start_date?: string;
end_date?: string;
operator_id?: string;
};
}): Promise<any> {
const { repoId, param } = params;
return reqCatch(
() =>
request({
url: `/api/v2/projects/${repoId}/audit_logs`,
method: 'get',
params: Object.assign({ page: 1, per_page: 10 }, param)
}),
params
);
}
// 获取项目的Fork列表
export function getRepoForks(params: types.forkRepoReqType): Promise<types.forkRepoReqType> {
return request({
url: `/api/v2/projects`,
method: 'get',
params
});
}
// 获取项目的Star列表
export function getRepoStars(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/star`,
method: 'get',
params
});
}
// 获取项目Star用户列表
export function getRepoStarUsers(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/star_users`,
method: 'get',
params
});
}
// 检查的项目名称
export function checkRepoName(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: '/api/v2/projects/check_name',
method: 'get',
params
});
}
// 获取仓库文件
export function getRepoFiles(params: types.commonRepoReqType): Promise<AxiosResponse<types.commonRepoResType>> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/files`,
method: 'get',
params
});
}
// 编辑仓库文件
export function editRepoFiles(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${data.repoId}/repository/files`,
method: 'put',
data
});
}
// 创建仓库文件
export function createRepoFiles(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${data.repoId}/repository/files`,
method: 'post',
data
});
}
// 删除仓库文件(不能删除文件夹)
export function deleteRepoFiles(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/files`,
method: 'delete',
data: params
});
}
// 批量删除目录和文件(支持文件夹删除)
export function batchDeleteRepoFiles(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/files_in_batch`,
method: 'post',
data: params
});
}
// 获取文件追溯信息
export function getFileBlame(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/blame`,
method: 'get',
params
});
}
// 批量删除指定项目仓库的目录和文件
export function batchDeleteFiles(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${data.repoId}/repository/files_in_batch`,
method: 'post',
data
});
}
// 文件树查询(只能返回1层数组)
export function getRepoTree(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/tree`,
method: 'get',
params
});
}
// 文件树查询(指定路径返回树形结构)
export function getRepoTreeByPath(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/upper_files_tree`,
method: 'get',
params
});
}
// 获取仓库README文件
export function getRepoReadme(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/projects/${params.repoId}/repository/readme_file`,
method: 'get',
params
})
);
}
// 获取仓库网络信息
export function getRepoNetwork(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/network`,
method: 'get',
params
});
}
// 日志树查询
export function getRepoLogsTree(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/logs_tree`,
method: 'get',
params
});
}
// 获取默认分支
export function getRepoDefaultBranch(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}/repository/default_branch`,
method: 'get',
params
}),
params
);
}
// 获取分支概览的分支信息
export function getRepoBranchView(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}/repository/branch_overview`,
method: 'get',
params
}),
params
);
}
// 获取项目仓库比较信息
export function getRepoCompare(params: types.commonRepoReqType): Promise<any> {
return reqCatch(
() =>
request({
url: `/api/v2/projects/${params.repoId}/repository/compare`,
method: 'get',
params
}),
params
);
}
// 获取文件查看链接(浏览器打开)
export function getFileRaw(data: types.commonRepoReqType): Promise<string> {
return Promise.resolve(
`${fileDownloadBaseURL}/${decodeURIComponent(data.repoId)}/raw/${encodeURIComponent(data.ref)}/${data.filePath}`
);
}
// 获取文件下载链接(附件下载)
export function getBlobRaw(params: types.commonRepoReqType): Promise<string> {
return Promise.resolve(
`${fileDownloadBaseURL}/${decodeURIComponent(params.repoId)}/blobs/${params.sha}/${params.file_name}`
);
}
// 仓库文件上传
export function uploadRepoFile(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
// 使用formData上传
const formData = new FormData();
Object.entries(params).forEach(([key, val]) => {
formData.append(key, val);
});
return request(
{
url: `${fileUploadBaseURL}/${decodeURIComponent(params.repoId)}/uploads/file`,
method: 'post',
data: formData,
headers: {
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryn8D9asOnAnEU4Js0'
},
withCredentials: true
},
{
customError: true
}
);
}
// 仓库 issuemr 图片上传方法
export function uploadRepoImage(data: {
project_id: string;
attach: string;
file_name: string;
}): Promise<types.commonRepoResType> {
const { project_id, attach, file_name } = data;
return reqCatch(
() =>
request({
url: `${fileUploadBaseURL}/${project_id}/uploads/image_file`,
method: 'post',
data: { attach, file_name }
}),
data
);
}
// 获取仓库下载压缩包
export function getRepoArchive(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/archive`,
method: 'get',
params
});
}
// 新增里程碑
export function addRepoMilestones(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/projects/${data.repoId}/milestones`,
method: 'post',
data
});
}
// 编辑里程碑
export function editRepoMilestones(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/projects/${data.repoId}/milestones/${data.id}`,
method: 'put',
data
});
}
// 删除里程碑
export function deletedRepoMilestones(data: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/projects/${data.repoId}/milestones/${data.id}`,
method: 'delete'
});
}
// 获取里程碑列表
export function getRepoMilestones(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/projects/${params.repoId}/milestones`,
method: 'get',
params
});
}
// 获取里程碑详情
export function getRepoMileStoneDetail(params: {
project_id: string;
milestone_id: string;
}): Promise<types.commonRepoResType> {
const { project_id, milestone_id } = params;
return request({
url: `/api/v1/projects/${project_id}/milestones/${milestone_id}`,
method: 'get'
});
}
// 获取项目动态
export function getRepoEvents(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v1/projects/${params.repoId}/events`,
method: 'get',
params
})
);
}
// 获取项目贡献者
export function getRepoContributors(
params: types.commonRepoReqType
): catchRt<CommonWithPageReqType<types.ContributorReqType[]>> {
return reqCatchV2(() =>
request({
url: `/api/v2/projects/${params.repoId}/repository/contributors`,
method: 'get',
params
})
);
}
// 获取用户在项目中的权限
export function getRepoRole(params: { repoId: string }) {
return request(
{
url: `/api/v2/projects/${params.repoId}/role`,
method: 'get'
},
{
customError: true
}
);
}
// 获取项目成员
export function getRepoMember(params: {
repoId: string;
page?: number;
per_page?: number;
query?: string;
}): Promise<any> {
const { repoId, ...param } = params;
return request(
{
url: `/api/v1/projects/${repoId}/members/all`,
method: 'get',
params: Object.assign({ page: 1, per_page: 10 }, param)
},
{
customError: true
}
);
}
/** 获取项目下等待邀请的成员列表 */
export function getRepoInviteMember(params: { repoId: string; page?: Number; per_page?: number }): Promise<any> {
const { repoId, ...pager } = params;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/members/invite`,
params: Object.assign({ page: 1, per_page: 100 }, pager)
})
);
}
/** 项目设置项目成员中邀请成员 */
export function toInviteUser(data: { repoId: string; conf: Record<string, any> }) {
const { repoId, conf } = data;
return reqCatch(() =>
request({
url: `/api/v1/invitation/${repoId}/invite`,
method: 'post',
data: {
...conf,
source_type: '1' // 0 组织 1 项目
}
})
);
}
/** 项目设置撤销邀请 */
export function retractRepoInvite(data: { repoId: string; username: string }) {
const { repoId, username } = data;
return reqCatch(() =>
request({
url: `/api/v1/invitation/${repoId}/1/members/${username}/revoke`,
method: 'delete'
})
);
}
/** 项目设置退出项目 */
export function exitRepo(data: { repoId: string;[x: string]: any }) {
const { repoId } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/leave`,
method: 'delete'
})
);
}
/** 项目设置移除用户 */
export function removeRepoUser(data: { repoId: string; username: string }) {
const { repoId, username } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/members/${username}`,
method: 'delete'
})
);
}
/** 组织成员设置权限 */
export function setRepoUserLevel(data: { repoId: string; username: string; access_level: '30' | '10' }) {
const { repoId, username, access_level } = data;
return reqCatch(() =>
request({
url: `/api/v1/projects/${repoId}/members/${username}`,
method: 'put',
data: { access_level }
})
);
}
// 获取GitIgnore列表
export function getGitIgnoreList(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/internal/templates/gitignore_keys`,
method: 'get',
params
});
}
// 获取LICENSE列表
export function getLicenseList(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/internal/templates/license_keys`,
method: 'get',
params
});
}
// 文件详情页-文件搜索加载repo所有文件
export function getRepoFileList(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/repository/file_list`,
method: 'get',
params
});
}
// 获取项目的通知状态
export function getRepoNotice(params: types.commonRepoReqType): catchRt<types.RepoNoticeReqType> {
return reqCatchV2(() =>
request({
url: `/api/v1/projects/${params.repoId}/watch`,
method: 'get',
params: { project_id: params.repoId }
})
);
}
// 修改项目的通知状态
export function updateRepoNotice(data: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v1/projects/${data.repoId}/watch`,
method: 'put',
data
})
);
}
// 查询项目状态
export function getRepoStatus(params: types.commonRepoReqType): Promise<types.commonRepoResType> {
return request({
url: `/api/v2/projects/${params.repoId}/fork_status`,
method: 'get',
params
});
}
// 查询项目导入状态
export function getRepoImportStatus(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/projects/${params.repoId}/import_status`,
method: 'get',
params
})
);
}
/** wiki列表 */
export function getWikiList(params: types.WikiListReqType): catchRt<CommonWithPageReqType<types.WikiListResType[]>> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/list`,
method: 'get',
params
})
);
}
/** wiki创建 */
export function createdWiki(data: types.RepoWikiReqType): catchRt<string> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/create`,
method: 'post',
data
})
);
}
/** wiki编辑 */
export function updateWiki(data: types.RepoWikiReqType): catchRt<string> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/update`,
method: 'put',
data
})
);
}
/** wiki删除 */
export function deleteWiki(data: { repo_path: string; file_path: string }): catchRt<number> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/delete`,
method: 'delete',
data
})
);
}
/** wiki详情 */
export function getWikiDetail(params: { repo_path: string; file_path: string }): catchRt<types.WikiFileResType> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/detail`,
method: 'get',
params
})
);
}
/** wiki导航 */
export function wikiPages(data: { repo_path: string }): Promise<types.commonRepoResType> {
return request({
url: `/api/v1/wiki/pages`,
method: 'post',
data
});
}
/** wiki的commit历史 */
export function wikiCommitHistory(
params: types.RepoWikiHistoryReqType
): catchRt<CommonWithPageReqType<types.WikiHistoryResType[]>> {
return reqCatchV2(() =>
request({
url: `/api/v1/wiki/commit_histroy`,
method: 'get',
params
})
);
}
/** 获取仓库下载压缩包 */
export function getArchives(params: types.archiveType): Promise<types.archiveType> {
return request({
url: `/api/v4/projects/${params.repoId}/repository/archive`,
method: 'get',
params
});
}
// 项目迁移
export function repoMigrate(data: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/mirror/v1/project/myGithub`,
method: 'post',
data
})
);
}
// 迁移批量导入
export function migrateImport(data: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/mirror/v1/project/import`,
method: 'post',
data
})
);
}
// 上次的批量导入
export function recentMigrate(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/mirror/v1/project/myLastGithub`,
method: 'get',
params
})
);
}
/** 创建项目成员邀请链接 **/
export function createRepoMemberLink(data: { repoId: string } & types.MemberInviteLinkProps) {
const { repoId, ...config } = data;
return reqCatch(() =>
request({
url: `/api/v1/project/${repoId}/invite/link`,
method: 'post',
data: config
})
);
}
/** 删除项目成员邀请链接 */
export function deleteMemberInviteLink(repoId: string, inviteId: string) {
return reqCatch(() =>
request({
url: `/api/v1/project/${repoId}/${inviteId}/invite/link`,
method: 'delete'
})
);
}
/** 查询项目成员邀请链接列表 */
export function getMemberInviteLinks(params: { repoId: string; page?: number; per_page?: number }) {
const { repoId, ...pager } = params;
return reqCatch(() =>
request({
url: `/api/v1/${repoId}/invite/link`,
params: Object.assign({ page: 1, per_page: 10 }, pager)
})
);
}
/** 修改项目成员邀请链接 **/
export function updateRepoMemberLink(data: { repoId: string; inviteId: string } & types.MemberInviteLinkProps) {
const { repoId, inviteId, ...config } = data;
return reqCatch(() =>
request({
url: `/api/v1/project/${repoId}/${inviteId}/invite/link`,
method: 'put',
data: config
})
);
}
/** 接受项目邀请链接 */
export function acceptRepoInvite(invite_code: string) {
return reqCatch(() =>
request({
url: `/api/v1/${invite_code}/invite/accept`
})
);
}
/** 查看项目邀请链接待接受成员列表 */
export function getAcceptRepoMember(params: { repoId: string; page?: number; per_page?: number }) {
const { repoId, ...pager } = params;
return reqCatch(() =>
request({
url: `/api/v1/${repoId}/invite/accept/member`,
params: Object.assign({ page: 1, per_page: 10 }, pager)
})
);
}
/** 审核链接访问的成员 */
export function checkRepoLinkMember(data: {
repoId: string;
id: number;
access_level: string;
member_expires_at?: string;
audit: '0' | '2';
}) {
const { repoId, id, ...conf } = data;
return reqCatch(() =>
request({
url: `/api/v1/project/${repoId}/${id}/invite/audit`,
method: 'put',
data: conf
})
);
}
/** 删除链接访问的成员 */
export function removeRepoLinkMember(repoId: string, id: number) {
return reqCatch(() =>
request({
url: `/api/v1/project/${repoId}/${id}/invite/audit`,
method: 'delete'
})
);
}
/** 新增仓库镜像 */
export function createRepoMirror(data: { url: string; repoId: string }) {
const { repoId, ...conf } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/repo_remote_mirror`,
method: 'post',
data: conf
})
);
}
/** 获取仓库镜象 */
export function getRepoMirrorInfo(repoId: string) {
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/repo_remote_mirror`
})
);
}
/** 删除仓库信息 */
export function delRepoMirrorInfo(repoId: string) {
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/repo_remote_mirror`,
method: 'delete'
})
);
}
/** 修改仓库镜像 */
export function updateMirrorInfo(data: { repoId: string; mirroring_enabled: boolean }) {
const { repoId, ...conf } = data;
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/repo_remote_mirror`,
method: 'put',
data: conf
})
);
}
/** 邀请链接查询是否被邀请过 */
export function checkInvited(invite_code: string) {
return reqCatch(() =>
request({
url: `/api/v1/${invite_code}/invite/accept/before`
})
);
}
/** 查询是否已被邀请 */
export function checkInvitedStatus(source_id: string, username: string) {
return reqCatch(() =>
request({
url: `/api/v1/${source_id}/invite/accept/byUserName`,
params: {
username
}
})
);
}
/** 获取项目首页的topic数据 */
export function getRepoTopic(repoId: string) {
return reqCatch(() =>
request({
url: `/api/v2/topics/project/${repoId}`
})
);
}
/** 更新topic列表 */
export function updateRepoTopic(repoId: string, topics: string[]) {
return reqCatch(() =>
request({
url: `/api/v2/topics/project/${repoId}`,
method: 'put',
data: topics
})
);
}
/** 搜索topic */
export function searchRepoTopic(search: string) {
return reqCatch(() =>
request({
url: `/api/v2/topics/search`,
params: {
search,
page: 1,
per_page: 100
}
})
);
}
// 获取近28天star数量
export function getRepoStarsChart(projectId: number): Promise<any> {
return request({
url: `/api/mirror/v1/project/starDailyCount`,
method: 'get',
params: {
projectId
}
});
}
// 获取项目贡献者
export function getRepoSearch(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v1/projects/search/page`,
method: 'get',
params
})
);
}
// 获取topic详情
export function getTopicDetail(topicId: string): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/${topicId}`,
method: 'get'
})
);
}
export function getTopicDetailByName(topicName: string): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/byName/${topicName}`,
method: 'get'
})
);
}
// 根据关键字搜索topic
export function getTopicSearch(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/search`,
method: 'get',
params
})
);
}
// 根据topic与语言过滤项目分页列表
export function getTopicRepos(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/${params.id}/projects`,
method: 'get',
params
})
);
}
// 当前用户star当前topic
export function starTopic(topicId: string): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/${topicId}/user/star`,
method: 'put'
})
);
}
// 当前用户star当前topic
export function unstarTopic(topicId: string): catchRt<types.commonRepoResType> {
return reqCatchV2(() =>
request({
url: `/api/v2/topics/${topicId}/user/unStar`,
method: 'put'
})
);
}
// 本地部署设置
export function deploySetting(repoId: string, data: object): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/common/setting`,
method: 'put',
data
})
);
}
// 获取项目下载克隆数据
export function getRepoClone(repoId: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${repoId}/repository/download_statistics`,
method: 'get'
})
);
}
// 获取分支差异数对比
export function getBranchDiff(project_id: string, branch: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/repository/diverged`,
method: 'get',
params: {
branch: branch
}
})
);
}
// 判断代码是否存在冲突
export function getIsConflict(params: types.commonRepoReqType): Promise<any> {
const { project_id, branch_name, other_project_id, other_branch_name } = params;
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/branches/${branch_name}/exist_conflict/${other_project_id}/${other_branch_name}`,
method: 'get'
})
);
}
// 同步分支代码
export function syncBranchCode(project_id: string, branch: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/sync_repo`,
method: 'put',
data: {
branch: branch
}
})
);
}
// 获取可选择的cla列表
export function getClaList(params: types.commonRepoReqType): catchRt<types.commonRepoResType> {
return reqCatch(() =>
request({
url: `/api/v2/cla/projectClaList`,
method: 'get',
params
})
);
}
// 判断是否可同步
export function isEnableSyncCode(project_id: string, branch: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/sync_repo`,
method: 'get',
params: {
branch: branch
}
})
);
}
// 获取MR相关的用户列表签署cla的情况
export function getClaSignUser(repo_id: number, merge_request_iid: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/cla/${repo_id}/merge_requests/${merge_request_iid}/cla_sign_users`,
method: 'get'
})
);
}
// 仓库设置清理仓库
export function clearRepoSetting(project_id: string): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${project_id}/housekeeping`,
method: 'post',
data: {}
})
);
}
// 获取项目列表
export function getRepoList(params: object): Promise<any> {
return request({
url: `/api/v2/projects`,
method: 'get',
params
});
}
// 从pr设置中获取审查及测试人信息
export function getPrSetting(data: types.commonRepoReqType): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${data.repoId}/pr_review/setting`,
method: 'get'
})
);
}
// 预览
export function getDiscussionPreview(params: types.DiscussionPreviewProps): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v1/discussion/preview`,
method: 'get',
params
})
);
}
// 设置pr审查及测试人信息
export function setPrSetting(data: types.commonRepoReqType): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${data.repoId}/pr_review/setting`,
method: 'put',
data: data.params
})
);
}
// 获取设置中可选的审查及测试人列表
export function getPrApproval(data: types.commonRepoReqType): Promise<any> {
return reqCatch(() =>
request({
url: `/api/v2/projects/${data.repoId}/merge_requests/approval_user`,
method: 'get',
params: data.params
})
);
}
// 获取原始评论数据
export const getOriginalComment = (params: types.DiscussionCommentProps): Promise<any> => {
return reqCatch(() =>
request({
url: `/api/v1/discussion/${params.type}/${params.discussionId}`,
method: 'get',
})
);
}