All checks were successful
CI Monitor MIflow / build-image (push) Successful in 2m42s
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import type {
|
|
ExpandedMergeRequestSchema,
|
|
MergeRequestChangesSchema,
|
|
MergeRequestDiffVersionsSchema,
|
|
MergeRequestNoteSchema,
|
|
} from "@gitbeaker/rest"
|
|
|
|
import netTool from "../netTool"
|
|
import { GITLAB_AUTH_HEADER, GITLAB_BASE_URL, gitlabReqWarp } from "./tools"
|
|
|
|
/**
|
|
* 获取合并请求的评论,支持分页。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @param {number} [page=1] - 页码。
|
|
* @param {number} [per_page=20] - 每页的评论数。
|
|
* @returns {Promise<MergeRequestNoteSchema[]>} 返回包含评论的Promise。
|
|
*/
|
|
const getComments = async (
|
|
project_id: number,
|
|
merge_request_iid: number,
|
|
page: number = 1,
|
|
per_page: number = 20
|
|
): Promise<MergeRequestNoteSchema[]> => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}/notes?page=${page}&per_page=${per_page}`
|
|
return gitlabReqWarp<MergeRequestNoteSchema[]>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
[]
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 获取合并请求的变更。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @returns {Promise<MergeRequestChangesSchema | null>} 返回包含变更的Promise。
|
|
*/
|
|
const getChanges = async (project_id: number, merge_request_iid: number) => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}/changes`
|
|
return gitlabReqWarp<MergeRequestChangesSchema | null>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
null
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 获取合并请求的详细信息。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @returns {Promise<ExpandedMergeRequestSchema | null>} 返回包含详细信息的Promise。
|
|
*/
|
|
const getDetail = async (project_id: number, merge_request_iid: number) => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}`
|
|
return gitlabReqWarp<ExpandedMergeRequestSchema | null>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
null
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 获取合并请求的差异版本。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @returns {Promise<any[]>} 返回包含差异版本的Promise。
|
|
*/
|
|
const getDiffVersions = async (
|
|
project_id: number,
|
|
merge_request_iid: number
|
|
) => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}/versions`
|
|
return gitlabReqWarp<MergeRequestDiffVersionsSchema[]>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
[]
|
|
)
|
|
}
|
|
|
|
const mr = {
|
|
getChanges,
|
|
getDetail,
|
|
getComments,
|
|
getDiffVersions,
|
|
}
|
|
|
|
export default mr
|