UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

97 lines (96 loc) 2.76 kB
/** Webhook 条目 */ export interface WebhookItem { id: number; url: string; [k: string]: unknown; } /** 创建 Webhook 的选项 */ export interface CreateWebhookOptions { /** 是否监听 push 事件 */ push_events?: boolean; /** 是否监听 merge_requests 事件 */ merge_requests_events?: boolean; /** 是否监听 issues 事件 */ issues_events?: boolean; /** 是否监听 note 评论事件 */ note_events?: boolean; /** 是否监听 tag push 事件 */ tag_push_events?: boolean; /** 是否监听 review 事件 */ review_events?: boolean; /** 是否校验 SSL */ enable_ssl_verification?: boolean; /** 用于校验的 secret token(工蜂会在 X-Gitlab-Token 请求头中携带) */ token?: string; } /** * 创建 Webhook * * 对应工蜂 API:POST /api/v3/projects/:id/hooks * * @param {object} options 输入配置 * @param {string | number} options.projectName 项目名称或项目 ID * @param {string} options.webhookUrl 回调 URL * @param {string} options.privateToken 密钥 * @param {CreateWebhookOptions} [options.events] 事件配置,默认只开 merge_requests_events * @param {string} [options.baseUrl] baseUrl * @returns {Promise<WebhookItem>} Webhook 条目 * @example * * createWebhook({ * projectName: 'group/sub/repo', * webhookUrl: 'https://my-server.com/hooks/tgit', * privateToken: 'xxxxx', * events: { * merge_requests_events: true, * note_events: true, * }, * }).then((hook) => { * console.log(hook.id); * }) */ export declare function createWebhook({ projectName, webhookUrl, privateToken, events, baseUrl, }: { projectName: string | number; webhookUrl: string; privateToken: string; events?: CreateWebhookOptions; baseUrl?: string; }): Promise<WebhookItem>; /** * 获取项目的 Webhook 列表 * * 对应工蜂 API:GET /api/v3/projects/:id/hooks * @example * * getHooks({ * projectName: 'group/sub/repo', * privateToken: 'xxxxx', * }).then((list) => { * list.forEach(h => console.log(h.id, h.url)); * }) */ export declare function getHooks({ projectName, privateToken, baseUrl, }: { projectName: string | number; privateToken: string; baseUrl?: string; }): Promise<WebhookItem[]>; /** * 删除 Webhook * * 对应工蜂 API:DELETE /api/v3/projects/:id/hooks/:hookId * @example * * deleteWebhook({ * projectName: 'group/sub/repo', * hookId: 12345, * privateToken: 'xxxxx', * }).then((resp) => { * * }) */ export declare function deleteWebhook({ projectName, hookId, privateToken, baseUrl, }: { projectName: string | number; hookId: number | string; privateToken: string; baseUrl?: string; }): Promise<unknown>;