Compare commits

...

5 Commits

Author SHA1 Message Date
5e43eb2db7 update 2025-12-04 23:38:52 +08:00
1644310bf5 updatw 2025-12-04 20:54:40 +08:00
501ceede27 update 2025-12-04 20:38:08 +08:00
780172e9b4 fix 2025-12-04 20:12:15 +08:00
3cb666bc8f update 2025-12-04 20:08:04 +08:00
9 changed files with 147 additions and 15804 deletions

View File

@@ -1,13 +0,0 @@
# .cnb.yml
$:
vscode:
- docker:
image: docker.cnb.cool/kevisual/node24:latest
services:
- vscode
- docker
imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
# 开发环境启动后会执行的任务
# stages:
# - name: pnpm install
# script: pnpm install

43
.cnb.yml Normal file
View File

@@ -0,0 +1,43 @@
# .cnb.yml
$:
vscode:
- docker:
image: docker.cnb.cool/kevisual/node24:latest
services:
- vscode
- docker
imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
# 开发环境启动后会执行的任务
# stages:
# - name: pnpm install
# script: pnpm install
main:
web_trigger_sync_to_gitea:
- services:
- docker
imports:
- https://cnb.cool/kevisual/env/-/blob/main/env.yml
stages:
- name: 'show username'
script: echo "GITEA_USERNAME is ${GITEA_USERNAME} and GITEA_PASSWORD is ${GITEA_PASSWORD}"
- name: sync to gitea
image: tencentcom/git-sync
settings:
target_url: https://git.xiongxiao.me/kevisual/cnb.git
auth_type: https
username: "oauth2"
password: ${GITEA_TOKEN}
git_user: "abearxiong"
git_email: "xiongxiao@xiongxiao.me"
sync_mode: rebase
branch: main
"**":
web_trigger_test:
- stages:
- name: 执行任务
script: echo "job"

11
.cnb/web_trigger.yml Normal file
View File

@@ -0,0 +1,11 @@
# .cnb/web_trigger.yml
branch:
# 如下按钮在分支名以 release 开头的分支详情页面显示
- reg: "^main"
buttons:
- name: 同步代码到gitea
desc: 同步代码到gitea
event: web_trigger_sync_to_gitea
- name: 同步gitea代码到当前仓库
desc: 同步gitea代码到当前仓库
event: web_trigger_sync_from_gitea

1
docs/index.html Normal file
View File

@@ -0,0 +1 @@
this is a test page

View File

@@ -4,3 +4,8 @@
1. 从cnb同步到本地gitea 1. 从cnb同步到本地gitea
2. 从本地gitea同步到cnb 2. 从本地gitea同步到cnb
## 启动环境
https://docs.cnb.cool/zh/workspaces/custom-dev-env.html

View File

@@ -27,6 +27,10 @@ export interface ListParams {
status?: 'running' | 'closed'; status?: 'running' | 'closed';
} }
/**
* 云原生开发环境管理模块
* https://api.cnb.cool/#/operations/GetWorkspaceDetail
*/
export class Workspace extends CNBCore { export class Workspace extends CNBCore {
constructor(token: string) { constructor(token: string) {
super({ token }); super({ token });
@@ -137,8 +141,10 @@ export type ResultList<T> = {
export interface WorkspaceInfo { export interface WorkspaceInfo {
/** 分支名例如main */ /** 分支名例如main */
branch: string; branch: string;
/** 业务 ID */
business_id: string;
/** 备份的 commit 数 */ /** 备份的 commit 数 */
commit_count: number; commit_count: number | null;
/** 开发环境创建时间例如2024-12-02T03:20:22.000Z */ /** 开发环境创建时间例如2024-12-02T03:20:22.000Z */
create_time: string; create_time: string;
/** 开发环境持续时间单位ms非实时更新 */ /** 开发环境持续时间单位ms非实时更新 */
@@ -147,24 +153,36 @@ export interface WorkspaceInfo {
file_count: number; file_count: number;
/** 备份的文件列表,仅前五个备份文件相对路径 */ /** 备份的文件列表,仅前五个备份文件相对路径 */
file_list: string; file_list: string;
/** 是否为预览环境0: 否1: 是 */
is_preview: number;
/** JetBrains IDE 列表 */
jetbrainsList: any[];
/** 环境销毁时远程最新的 commit short hash */ /** 环境销毁时远程最新的 commit short hash */
latest_sha: string; latest_sha: string | null;
/** 创建环境的子流水线 id */ /** 创建环境的子流水线 id */
pipeline_id: string; pipeline_id: string;
/** 备份的 stash 数 */ /** 备份的 stash 数 */
remote_stash_count: number; remote_stash_count: number | null;
/** 仓库 ID */
repo_id: string;
/** 仓库地址 */ /** 仓库地址 */
repo_url: string; repo_url: string;
/** 恢复备份代码的流水线 id如果有值表示备份代码已被恢复重建环境时会恢复备份代码 */ /** 恢复备份代码的流水线 id如果有值表示备份代码已被恢复重建环境时会恢复备份代码 */
restore_id: string; restore_id: string | null;
/** 单个 stash 标识1: 是0: 否 */
single_stash: number;
/** 仓库路径例如groupname/reponame */ /** 仓库路径例如groupname/reponame */
slug: string; slug: string;
/** 创建开发环境的流水线 sn */ /** 创建开发环境的流水线 sn */
sn: string; sn: string;
/** 开发环境是否支持 ssh 链接 */ /** 开发环境是否支持 ssh 链接 */
ssh: boolean; ssh: boolean;
/** 本地 stash 数 */
stash_count: number;
/** 工作区状态running: 开发环境已启动closed开发环境已关闭 */ /** 工作区状态running: 开发环境已启动closed开发环境已关闭 */
status: string; status: string;
/** 用户名 */
user_name: string;
/** 开发环境默认工作区路径 */ /** 开发环境默认工作区路径 */
workspace: string; workspace: string;
} }

15781
swagger.json

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,26 @@
import { CNB } from "../src"; import { CNB } from "../src";
import dotenv from "dotenv"; import dotenv from "dotenv";
dotenv.config(); dotenv.config();
const cnb = new CNB(process.env.CNB_TOKEN || ""); export const cnb = new CNB(process.env.CNB_TOKEN || "");
const worksaceList = await cnb.workspace.list(); // const worksaceList = await cnb.workspace.list({ status: 'running' });
// console.log("worksaceList", worksaceList); // console.log("worksaceList", worksaceList);
const sn = 'cnb-0eg-1jbkjj615-001' // const sn = 'cnb-o18-1jbklfuoh'
const worksace = await cnb.workspace.getDetail('kevisual/node24', sn)
console.log("worksace", worksace); // const worksace = await cnb.workspace.getDetail('kevisual/cnb', sn)
// console.log("worksace", worksace);
// const stop = await cnb.workspace.stopWorkspace({ sn })
// console.log("stop", stop);
// exebqzp8sc
// const start = await cnb.workspace.startWorkspace('kevisual/cnb', {
// branch: 'main',
// });
// console.log("start", start);

47
test/timeout-start.ts Normal file
View File

@@ -0,0 +1,47 @@
import { cnb } from "./common"
async function runWorkspaceStart() {
const startTime = Date.now();
const duration = 30 * 60 * 1000; // 30 minutes in milliseconds
const interval = 5 * 60 * 1000; // 5 minutes in milliseconds
let attemptCount = 0;
console.log(`Starting workspace start test at ${new Date().toLocaleString()}`);
console.log(`Will run every 5 minutes for 30 minutes total`);
const runInterval = async () => {
const currentTime = Date.now();
const elapsed = currentTime - startTime;
attemptCount++;
console.log(`\n=== Attempt ${attemptCount} at ${new Date().toLocaleString()} ===`);
try {
const start = await cnb.workspace.startWorkspace('kevisual/cnb', {
branch: 'main',
});
console.log(`Success: ${JSON.stringify(start, null, 2)}`);
} catch (error) {
console.error(`Error: ${error}`);
}
// Check if we should continue
if (elapsed + interval < duration) {
setTimeout(runInterval, interval);
} else {
console.log(`\nTest completed at ${new Date().toLocaleString()}`);
console.log(`Total attempts: ${attemptCount}`);
}
};
// Set timeout to stop after 30 minutes
setTimeout(() => {
console.log(`\nTimeout reached at ${new Date().toLocaleString()}`);
console.log(`Test terminated after 30 minutes`);
}, duration);
// Start the first run immediately
runInterval();
}
runWorkspaceStart().catch(console.error);