All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s
61 lines
1.7 KiB
TypeScript
61 lines
1.7 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 {number} project_id - 项目的 ID。
|
|
* @returns {Promise<Gitlab.Badge[]>} 一个承诺,解析为 GitLab 徽章的数组。
|
|
*/
|
|
const get = async (project_id: number): Promise<Gitlab.Badge[]> => {
|
|
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/badges`
|
|
return gitlabReqWarp<Gitlab.Badge[]>(
|
|
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
|
[]
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 设置 GitLab 徽章。
|
|
* @param {BadgeSetParams} badge - 徽章参数。
|
|
* @returns {Promise<Gitlab.Badge | null>} 一个承诺,解析为更新后的徽章。
|
|
*/
|
|
const set = async (badge: BadgeSetParams): Promise<Gitlab.Badge | null> => {
|
|
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 {BadgeSetParams} badge - 徽章参数。
|
|
* @returns {Promise<Gitlab.Badge | null>} 一个承诺,解析为添加的徽章。
|
|
*/
|
|
const add = async (badge: BadgeSetParams): Promise<Gitlab.Badge | null> => {
|
|
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
|