zhaoyingbo 18a95387ee
All checks were successful
CI Monitor CI/CD / build-image (push) Successful in 33s
CI Monitor CI/CD / deploy (push) Successful in 37s
chore: 更新lint-staged和commitlint配置
2024-07-25 01:09:24 +00:00

61 lines
1.5 KiB
TypeScript

import { Gitlab } from "../../types/gitlab"
import netTool from "../netTool"
import { GITLAB_AUTH_HEADER, GITLAB_BASE_URL, gitlabReqWarp } from "./tools"
/**
* 代表设置 GitLab 徽章的参数。
*/
export type BadgeSetParams = Omit<Gitlab.Badge, "kind" | "name"> & {
badge_id?: number
}
/**
* 为特定项目检索 GitLab 徽章。
* @param project_id 项目的 ID。
* @returns 一个承诺,解析为 GitLab 徽章的数组。
*/
const get = async (project_id: number) => {
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/badges`
return gitlabReqWarp<Gitlab.Badge[]>(
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
[]
)
}
/**
* 设置 GitLab 徽章。
* @param badge 徽章参数。
* @returns 一个承诺,解析为更新后的徽章。
*/
const set = async (badge: BadgeSetParams) => {
const URL = `${GITLAB_BASE_URL}/projects/${badge.id}/badges/${badge.badge_id}`
return gitlabReqWarp<Gitlab.Badge>(
() => netTool.put(URL, badge, {}, GITLAB_AUTH_HEADER),
null
)
}
/**
* 添加 GitLab 徽章。
* @param badge 徽章参数。
* @returns 一个承诺,解析为添加的徽章。
*/
const add = async (badge: BadgeSetParams) => {
const URL = `${GITLAB_BASE_URL}/projects/${badge.id}/badges`
return gitlabReqWarp<Gitlab.Badge>(
() => netTool.post(URL, badge, {}, GITLAB_AUTH_HEADER),
null
)
}
/**
* 代表一系列与徽章相关的函数。
*/
const badge = {
get,
set,
add,
}
export default badge