This commit is contained in:
2026-01-05 10:50:37 +08:00
parent 2707286d7d
commit 2724f09a5b
6 changed files with 121 additions and 150 deletions

52
src/build/index.ts Normal file
View File

@@ -0,0 +1,52 @@
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
type Options = CNBCoreOptions<{
group?: string;
}>
export class Build extends CNBCore {
group: string;
constructor(options: Options) {
super({ token: options.token, cookie: options.cookie });
this.group = options.group || '';
}
startBuild(repo: string, data: StartBuildData): Promise<any> {
const group = this.group || '';
const url = `/${group}/${repo}/-/build/start`;
let postData: StartBuildData = {
...data,
branch: data.branch || 'main',
};
return this.post({ url, data: postData });
}
}
type StartBuildData = {
/**
* 触发分支,默认为主分支
*/
branch?: string;
/**
* 指定配置文件内容yaml 格式
*/
config?: string;
/**
* 环境变量,对象格式
*/
env?: Record<string, string>;
/**
* 事件名,必须是 api_trigger 或以 api_trigger_ 开头,默认为 api_trigger
*/
event?: string;
/**
* commit id ,优先级比 tag 高,默认为分支最新提交记录
*/
sha?: string;
/**
* 是否等待构建正式触发为false时会立刻返回 sn 和 buildLogUrl
*/
sync?: string;
/**
* 触发 tag优先级比 branch 高
*/
tag?: string;
}