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;
}

View File

@@ -1,5 +1,8 @@
export type CNBCoreOptions<T = {}> = {
token: string;
/**
* 对 cnb 界面操作定制模块功能时需要传入 cookie
*/
cookie?: string;
} & T;

View File

@@ -3,23 +3,29 @@ import { Workspace } from "./workspace.ts";
import { KnowledgeBase } from "./knowledge/index.ts";
import { Repo } from "./repo/index.ts";
import { User } from "./user/index.ts";
import { Build } from "./build/index.ts";
type CNBOptions = CNBCoreOptions<{}>;
type CNBOptions = CNBCoreOptions<{
group?: string;
}>;
export class CNB extends CNBCore {
workspace!: Workspace;
knowledgeBase!: KnowledgeBase;
repo!: Repo;
user!: User;
build!: Build;
constructor(options: CNBOptions) {
super({ token: options.token, cookie: options.cookie });
this.init(options);
}
init(options: CNBOptions) {
this.workspace = new Workspace(options.token);
this.knowledgeBase = new KnowledgeBase({ token: options.token, cookie: options.cookie });
this.repo = new Repo({ token: options.token, cookie: options.cookie });
const group = options.group || '';
this.knowledgeBase = new KnowledgeBase({ group: group, token: options.token, cookie: options.cookie });
this.repo = new Repo({ group: group, token: options.token, cookie: options.cookie });
this.user = new User({ token: options.token, cookie: options.cookie });
this.build = new Build({ group: group, token: options.token, cookie: options.cookie });
}
}
@@ -27,3 +33,5 @@ export * from './workspace.ts'
export * from './cnb-core.ts'
export * from './knowledge/index.ts'
export * from './repo/index.ts'
export * from './user/index.ts'
export * from './build/index.ts'