All checks were successful
CI Monitor MIflow / build-image (push) Successful in 2m42s
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { DiscussionSchema } from "@gitbeaker/rest"
|
|
|
|
import netTool from "../netTool"
|
|
import { GITLAB_AUTH_HEADER, GITLAB_BASE_URL, gitlabReqWarp } from "./tools"
|
|
|
|
export interface CreateRangeDiscussionPosition {
|
|
base_sha: string
|
|
start_sha: string
|
|
head_sha: string
|
|
new_path: string
|
|
old_path: string
|
|
position_type: "text"
|
|
new_line: number
|
|
line_range: {
|
|
start: {
|
|
line_code: string
|
|
}
|
|
end: {
|
|
line_code: string
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取合并请求的讨论列表。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @returns {Promise<DiscussionSchema[]>} 返回包含讨论列表的Promise。
|
|
*/
|
|
const getList = async (project_id: number, merge_request_iid: number) => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}/discussions`
|
|
return gitlabReqWarp<DiscussionSchema[]>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
[]
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 创建合并请求的讨论。
|
|
* @param {number} project_id - 项目ID。
|
|
* @param {number} merge_request_iid - 合并请求IID。
|
|
* @param {string} body - 讨论内容。
|
|
* @param {CreateRangeDiscussionPosition} position - 讨论位置。
|
|
* @returns {Promise<DiscussionSchema | null>} 返回包含创建的讨论的Promise。
|
|
*/
|
|
const create2Mr = async (
|
|
project_id: number,
|
|
merge_request_iid: number,
|
|
body: string,
|
|
position: CreateRangeDiscussionPosition
|
|
) => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/merge_requests/${merge_request_iid}/discussions`
|
|
return gitlabReqWarp<DiscussionSchema>(
|
|
() => netTool.post(URL, { body, position }, {}, GITLAB_AUTH_HEADER),
|
|
null
|
|
)
|
|
}
|
|
|
|
const discussions = {
|
|
getList,
|
|
create2Mr,
|
|
}
|
|
|
|
export default discussions
|