@kevisual/cnb 0.0.43 → 0.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/modules/cnb-manager.ts +2 -0
- package/agent/routes/cnb-manager/index.ts +3 -2
- package/dist/cli.js +16 -6
- package/dist/opencode.js +16 -6
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +16 -6
- package/package.json +4 -4
- package/readme.md +1 -0
- package/src/repo/index.ts +14 -1
|
@@ -67,6 +67,7 @@ export class CNBManager {
|
|
|
67
67
|
if (res.code === 200) {
|
|
68
68
|
const cookie = res.data?.data?.CNB_COOKIE
|
|
69
69
|
const token = res.data?.data?.CNB_API_KEY
|
|
70
|
+
console.log('从配置中心获取 CNB 配置', { cookie, token })
|
|
70
71
|
if (token) {
|
|
71
72
|
return this.addCNB({ username, token, cookie })
|
|
72
73
|
}
|
|
@@ -94,6 +95,7 @@ export class CNBManager {
|
|
|
94
95
|
const kevisualToken = ctx.query?.token;
|
|
95
96
|
const item = await this.getCNB({ username, kevisualToken });
|
|
96
97
|
if (!item) {
|
|
98
|
+
console.error('CNB 配置项不存在', username, item)
|
|
97
99
|
ctx.throw(400, '不存在的 CNB 配置项,请检查 登录 Token 是否正确,或添加 CNB 配置')
|
|
98
100
|
}
|
|
99
101
|
return item;
|
|
@@ -9,7 +9,7 @@ app.route({
|
|
|
9
9
|
middleware: ['auth'],
|
|
10
10
|
|
|
11
11
|
}).define(async (ctx) => {
|
|
12
|
-
const tokenUser = ctx.tokenUser;
|
|
12
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
13
13
|
if (!tokenUser) {
|
|
14
14
|
ctx.throw(401, '未授权');
|
|
15
15
|
}
|
|
@@ -29,7 +29,8 @@ app.route({
|
|
|
29
29
|
description: '获取我的cnb配置',
|
|
30
30
|
middleware: ['auth'],
|
|
31
31
|
}).define(async (ctx) => {
|
|
32
|
-
const
|
|
32
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
33
|
+
const username = tokenUser?.username;
|
|
33
34
|
const token = ctx.query?.token;
|
|
34
35
|
if (!username) {
|
|
35
36
|
ctx.throw(400, '未授权');
|
package/dist/cli.js
CHANGED
|
@@ -24105,6 +24105,8 @@ class KnowledgeBase extends CNBCore {
|
|
|
24105
24105
|
}
|
|
24106
24106
|
|
|
24107
24107
|
// src/repo/index.ts
|
|
24108
|
+
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
24109
|
+
|
|
24108
24110
|
class Repo extends CNBCore {
|
|
24109
24111
|
constructor(options) {
|
|
24110
24112
|
super(options);
|
|
@@ -24140,6 +24142,11 @@ class Repo extends CNBCore {
|
|
|
24140
24142
|
const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
|
24141
24143
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
24142
24144
|
data.parent_commit_sha = preCommitSha;
|
|
24145
|
+
} else if (data.parent_commit_sha) {
|
|
24146
|
+
if (!data.new_branch) {
|
|
24147
|
+
const date5 = import_dayjs.default().format("MMDDHHmm");
|
|
24148
|
+
data.new_branch = `refs/heads/${date5}`;
|
|
24149
|
+
}
|
|
24143
24150
|
}
|
|
24144
24151
|
const url3 = `${this.hackURL}/${repo}/-/git/commits`;
|
|
24145
24152
|
const postData = {
|
|
@@ -46014,6 +46021,7 @@ class CNBManager {
|
|
|
46014
46021
|
if (res.code === 200) {
|
|
46015
46022
|
const cookie = res.data?.data?.CNB_COOKIE;
|
|
46016
46023
|
const token = res.data?.data?.CNB_API_KEY;
|
|
46024
|
+
console.log("从配置中心获取 CNB 配置", { cookie, token });
|
|
46017
46025
|
if (token) {
|
|
46018
46026
|
return this.addCNB({ username, token, cookie });
|
|
46019
46027
|
}
|
|
@@ -46036,6 +46044,7 @@ class CNBManager {
|
|
|
46036
46044
|
const kevisualToken = ctx.query?.token;
|
|
46037
46045
|
const item = await this.getCNB({ username, kevisualToken });
|
|
46038
46046
|
if (!item) {
|
|
46047
|
+
console.error("CNB 配置项不存在", username, item);
|
|
46039
46048
|
ctx.throw(400, "不存在的 CNB 配置项,请检查 登录 Token 是否正确,或添加 CNB 配置");
|
|
46040
46049
|
}
|
|
46041
46050
|
return item;
|
|
@@ -60059,7 +60068,7 @@ app.route({
|
|
|
60059
60068
|
}).addTo(app);
|
|
60060
60069
|
|
|
60061
60070
|
// agent/routes/cnb-board/live/live-content.ts
|
|
60062
|
-
var
|
|
60071
|
+
var import_dayjs2 = __toESM(require_dayjs_min(), 1);
|
|
60063
60072
|
import os2 from "node:os";
|
|
60064
60073
|
import { execSync as execSync2 } from "node:child_process";
|
|
60065
60074
|
var getLiveMdContent = (opts) => {
|
|
@@ -60273,8 +60282,8 @@ var createOSInfo = (more = false) => {
|
|
|
60273
60282
|
description: "当前目录磁盘使用情况"
|
|
60274
60283
|
});
|
|
60275
60284
|
if (startTimer) {
|
|
60276
|
-
const buildStartTime =
|
|
60277
|
-
const buildStartTimestamp =
|
|
60285
|
+
const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
|
|
60286
|
+
const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
|
|
60278
60287
|
const buildUptime = Date.now() - buildStartTimestamp;
|
|
60279
60288
|
const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
|
|
60280
60289
|
const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
|
|
@@ -60290,7 +60299,7 @@ var createOSInfo = (more = false) => {
|
|
|
60290
60299
|
description: `构建已运行时间: ${buildUptimeStr}`
|
|
60291
60300
|
});
|
|
60292
60301
|
if (maxRunTime > 0) {
|
|
60293
|
-
const now =
|
|
60302
|
+
const now = import_dayjs2.default();
|
|
60294
60303
|
const today4am = now.hour(4).minute(0).second(0).millisecond(0);
|
|
60295
60304
|
let timeTo4 = today4am.valueOf() - now.valueOf();
|
|
60296
60305
|
if (timeTo4 < 0) {
|
|
@@ -60844,7 +60853,7 @@ app.route({
|
|
|
60844
60853
|
description: "清理我的cnb-manager记录",
|
|
60845
60854
|
middleware: ["auth"]
|
|
60846
60855
|
}).define(async (ctx) => {
|
|
60847
|
-
const tokenUser = ctx.tokenUser;
|
|
60856
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
60848
60857
|
if (!tokenUser) {
|
|
60849
60858
|
ctx.throw(401, "未授权");
|
|
60850
60859
|
}
|
|
@@ -60863,7 +60872,8 @@ app.route({
|
|
|
60863
60872
|
description: "获取我的cnb配置",
|
|
60864
60873
|
middleware: ["auth"]
|
|
60865
60874
|
}).define(async (ctx) => {
|
|
60866
|
-
const
|
|
60875
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
60876
|
+
const username = tokenUser?.username;
|
|
60867
60877
|
const token2 = ctx.query?.token;
|
|
60868
60878
|
if (!username) {
|
|
60869
60879
|
ctx.throw(400, "未授权");
|
package/dist/opencode.js
CHANGED
|
@@ -22012,6 +22012,8 @@ class KnowledgeBase extends CNBCore {
|
|
|
22012
22012
|
}
|
|
22013
22013
|
|
|
22014
22014
|
// src/repo/index.ts
|
|
22015
|
+
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
22016
|
+
|
|
22015
22017
|
class Repo extends CNBCore {
|
|
22016
22018
|
constructor(options) {
|
|
22017
22019
|
super(options);
|
|
@@ -22047,6 +22049,11 @@ class Repo extends CNBCore {
|
|
|
22047
22049
|
const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
|
22048
22050
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
22049
22051
|
data.parent_commit_sha = preCommitSha;
|
|
22052
|
+
} else if (data.parent_commit_sha) {
|
|
22053
|
+
if (!data.new_branch) {
|
|
22054
|
+
const date5 = import_dayjs.default().format("MMDDHHmm");
|
|
22055
|
+
data.new_branch = `refs/heads/${date5}`;
|
|
22056
|
+
}
|
|
22050
22057
|
}
|
|
22051
22058
|
const url3 = `${this.hackURL}/${repo}/-/git/commits`;
|
|
22052
22059
|
const postData = {
|
|
@@ -43921,6 +43928,7 @@ class CNBManager {
|
|
|
43921
43928
|
if (res.code === 200) {
|
|
43922
43929
|
const cookie = res.data?.data?.CNB_COOKIE;
|
|
43923
43930
|
const token = res.data?.data?.CNB_API_KEY;
|
|
43931
|
+
console.log("从配置中心获取 CNB 配置", { cookie, token });
|
|
43924
43932
|
if (token) {
|
|
43925
43933
|
return this.addCNB({ username, token, cookie });
|
|
43926
43934
|
}
|
|
@@ -43943,6 +43951,7 @@ class CNBManager {
|
|
|
43943
43951
|
const kevisualToken = ctx.query?.token;
|
|
43944
43952
|
const item = await this.getCNB({ username, kevisualToken });
|
|
43945
43953
|
if (!item) {
|
|
43954
|
+
console.error("CNB 配置项不存在", username, item);
|
|
43946
43955
|
ctx.throw(400, "不存在的 CNB 配置项,请检查 登录 Token 是否正确,或添加 CNB 配置");
|
|
43947
43956
|
}
|
|
43948
43957
|
return item;
|
|
@@ -57966,7 +57975,7 @@ app.route({
|
|
|
57966
57975
|
}).addTo(app);
|
|
57967
57976
|
|
|
57968
57977
|
// agent/routes/cnb-board/live/live-content.ts
|
|
57969
|
-
var
|
|
57978
|
+
var import_dayjs2 = __toESM(require_dayjs_min(), 1);
|
|
57970
57979
|
import os2 from "node:os";
|
|
57971
57980
|
import { execSync as execSync2 } from "node:child_process";
|
|
57972
57981
|
var getLiveMdContent = (opts) => {
|
|
@@ -58180,8 +58189,8 @@ var createOSInfo = (more = false) => {
|
|
|
58180
58189
|
description: "当前目录磁盘使用情况"
|
|
58181
58190
|
});
|
|
58182
58191
|
if (startTimer) {
|
|
58183
|
-
const buildStartTime =
|
|
58184
|
-
const buildStartTimestamp =
|
|
58192
|
+
const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
|
|
58193
|
+
const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
|
|
58185
58194
|
const buildUptime = Date.now() - buildStartTimestamp;
|
|
58186
58195
|
const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
|
|
58187
58196
|
const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
|
|
@@ -58197,7 +58206,7 @@ var createOSInfo = (more = false) => {
|
|
|
58197
58206
|
description: `构建已运行时间: ${buildUptimeStr}`
|
|
58198
58207
|
});
|
|
58199
58208
|
if (maxRunTime > 0) {
|
|
58200
|
-
const now =
|
|
58209
|
+
const now = import_dayjs2.default();
|
|
58201
58210
|
const today4am = now.hour(4).minute(0).second(0).millisecond(0);
|
|
58202
58211
|
let timeTo4 = today4am.valueOf() - now.valueOf();
|
|
58203
58212
|
if (timeTo4 < 0) {
|
|
@@ -58751,7 +58760,7 @@ app.route({
|
|
|
58751
58760
|
description: "清理我的cnb-manager记录",
|
|
58752
58761
|
middleware: ["auth"]
|
|
58753
58762
|
}).define(async (ctx) => {
|
|
58754
|
-
const tokenUser = ctx.tokenUser;
|
|
58763
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
58755
58764
|
if (!tokenUser) {
|
|
58756
58765
|
ctx.throw(401, "未授权");
|
|
58757
58766
|
}
|
|
@@ -58770,7 +58779,8 @@ app.route({
|
|
|
58770
58779
|
description: "获取我的cnb配置",
|
|
58771
58780
|
middleware: ["auth"]
|
|
58772
58781
|
}).define(async (ctx) => {
|
|
58773
|
-
const
|
|
58782
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
58783
|
+
const username = tokenUser?.username;
|
|
58774
58784
|
const token2 = ctx.query?.token;
|
|
58775
58785
|
if (!username) {
|
|
58776
58786
|
ctx.throw(400, "未授权");
|
package/dist/routes.d.ts
CHANGED
|
@@ -282,6 +282,12 @@ declare class Repo extends CNBCore {
|
|
|
282
282
|
createRepo(data: CreateRepoData): Promise<any>;
|
|
283
283
|
deleteRepoCookie(repo: string): Promise<any>;
|
|
284
284
|
deleteRepo(repo: string): Promise<any>;
|
|
285
|
+
/**
|
|
286
|
+
* 使用cookie创建提交,如果没有指定parent_commit_sha,则会自动获取最新的提交作为父提交
|
|
287
|
+
* @param repo
|
|
288
|
+
* @param data
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
285
291
|
createCommit(repo: string, data: CreateCommitData): Promise<any>;
|
|
286
292
|
createBlobs(repo: string, data: {
|
|
287
293
|
content: string;
|
package/dist/routes.js
CHANGED
|
@@ -22012,6 +22012,8 @@ class KnowledgeBase extends CNBCore {
|
|
|
22012
22012
|
}
|
|
22013
22013
|
|
|
22014
22014
|
// src/repo/index.ts
|
|
22015
|
+
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
22016
|
+
|
|
22015
22017
|
class Repo extends CNBCore {
|
|
22016
22018
|
constructor(options) {
|
|
22017
22019
|
super(options);
|
|
@@ -22047,6 +22049,11 @@ class Repo extends CNBCore {
|
|
|
22047
22049
|
const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
|
22048
22050
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
22049
22051
|
data.parent_commit_sha = preCommitSha;
|
|
22052
|
+
} else if (data.parent_commit_sha) {
|
|
22053
|
+
if (!data.new_branch) {
|
|
22054
|
+
const date5 = import_dayjs.default().format("MMDDHHmm");
|
|
22055
|
+
data.new_branch = `refs/heads/${date5}`;
|
|
22056
|
+
}
|
|
22050
22057
|
}
|
|
22051
22058
|
const url3 = `${this.hackURL}/${repo}/-/git/commits`;
|
|
22052
22059
|
const postData = {
|
|
@@ -43921,6 +43928,7 @@ class CNBManager {
|
|
|
43921
43928
|
if (res.code === 200) {
|
|
43922
43929
|
const cookie = res.data?.data?.CNB_COOKIE;
|
|
43923
43930
|
const token = res.data?.data?.CNB_API_KEY;
|
|
43931
|
+
console.log("从配置中心获取 CNB 配置", { cookie, token });
|
|
43924
43932
|
if (token) {
|
|
43925
43933
|
return this.addCNB({ username, token, cookie });
|
|
43926
43934
|
}
|
|
@@ -43943,6 +43951,7 @@ class CNBManager {
|
|
|
43943
43951
|
const kevisualToken = ctx.query?.token;
|
|
43944
43952
|
const item = await this.getCNB({ username, kevisualToken });
|
|
43945
43953
|
if (!item) {
|
|
43954
|
+
console.error("CNB 配置项不存在", username, item);
|
|
43946
43955
|
ctx.throw(400, "不存在的 CNB 配置项,请检查 登录 Token 是否正确,或添加 CNB 配置");
|
|
43947
43956
|
}
|
|
43948
43957
|
return item;
|
|
@@ -57966,7 +57975,7 @@ app.route({
|
|
|
57966
57975
|
}).addTo(app);
|
|
57967
57976
|
|
|
57968
57977
|
// agent/routes/cnb-board/live/live-content.ts
|
|
57969
|
-
var
|
|
57978
|
+
var import_dayjs2 = __toESM(require_dayjs_min(), 1);
|
|
57970
57979
|
import os2 from "node:os";
|
|
57971
57980
|
import { execSync as execSync2 } from "node:child_process";
|
|
57972
57981
|
var getLiveMdContent = (opts) => {
|
|
@@ -58180,8 +58189,8 @@ var createOSInfo = (more = false) => {
|
|
|
58180
58189
|
description: "当前目录磁盘使用情况"
|
|
58181
58190
|
});
|
|
58182
58191
|
if (startTimer) {
|
|
58183
|
-
const buildStartTime =
|
|
58184
|
-
const buildStartTimestamp =
|
|
58192
|
+
const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
|
|
58193
|
+
const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
|
|
58185
58194
|
const buildUptime = Date.now() - buildStartTimestamp;
|
|
58186
58195
|
const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
|
|
58187
58196
|
const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
|
|
@@ -58197,7 +58206,7 @@ var createOSInfo = (more = false) => {
|
|
|
58197
58206
|
description: `构建已运行时间: ${buildUptimeStr}`
|
|
58198
58207
|
});
|
|
58199
58208
|
if (maxRunTime > 0) {
|
|
58200
|
-
const now =
|
|
58209
|
+
const now = import_dayjs2.default();
|
|
58201
58210
|
const today4am = now.hour(4).minute(0).second(0).millisecond(0);
|
|
58202
58211
|
let timeTo4 = today4am.valueOf() - now.valueOf();
|
|
58203
58212
|
if (timeTo4 < 0) {
|
|
@@ -58751,7 +58760,7 @@ app.route({
|
|
|
58751
58760
|
description: "清理我的cnb-manager记录",
|
|
58752
58761
|
middleware: ["auth"]
|
|
58753
58762
|
}).define(async (ctx) => {
|
|
58754
|
-
const tokenUser = ctx.tokenUser;
|
|
58763
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
58755
58764
|
if (!tokenUser) {
|
|
58756
58765
|
ctx.throw(401, "未授权");
|
|
58757
58766
|
}
|
|
@@ -58770,7 +58779,8 @@ app.route({
|
|
|
58770
58779
|
description: "获取我的cnb配置",
|
|
58771
58780
|
middleware: ["auth"]
|
|
58772
58781
|
}).define(async (ctx) => {
|
|
58773
|
-
const
|
|
58782
|
+
const tokenUser = ctx.state?.tokenUser;
|
|
58783
|
+
const username = tokenUser?.username;
|
|
58774
58784
|
const token2 = ctx.query?.token;
|
|
58775
58785
|
if (!username) {
|
|
58776
58786
|
ctx.throw(400, "未授权");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/cnb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"basename": "/root/cnb",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"bin": {
|
|
20
|
-
"cnb": "
|
|
21
|
-
"cloud": "
|
|
20
|
+
"cnb": "bin/index.js",
|
|
21
|
+
"cloud": "bin/index.js"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
@@ -74,4 +74,4 @@
|
|
|
74
74
|
"./src/*": "./src/*",
|
|
75
75
|
"./agent/*": "./agent/*"
|
|
76
76
|
}
|
|
77
|
-
}
|
|
77
|
+
}
|
package/readme.md
CHANGED
package/src/repo/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
|
|
2
|
-
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
3
|
export class Repo extends CNBCore {
|
|
4
4
|
constructor(options: CNBCoreOptions) {
|
|
5
5
|
super(options);
|
|
@@ -30,6 +30,12 @@ export class Repo extends CNBCore {
|
|
|
30
30
|
const url = `/${repo}`;
|
|
31
31
|
return this.delete({ url });
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 使用cookie创建提交,如果没有指定parent_commit_sha,则会自动获取最新的提交作为父提交
|
|
35
|
+
* @param repo
|
|
36
|
+
* @param data
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
33
39
|
async createCommit(repo: string, data: CreateCommitData): Promise<any> {
|
|
34
40
|
const commitList = await this.getCommitList(repo, {
|
|
35
41
|
page: 1,
|
|
@@ -41,6 +47,12 @@ export class Repo extends CNBCore {
|
|
|
41
47
|
const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
|
42
48
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
43
49
|
data.parent_commit_sha = preCommitSha;
|
|
50
|
+
} else if (data.parent_commit_sha) {
|
|
51
|
+
// 如果指定了parent_commi_sha;
|
|
52
|
+
if (!data.new_branch) {
|
|
53
|
+
const date = dayjs().format('MMDDHHmm');
|
|
54
|
+
data.new_branch = `refs/heads/${date}`;
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
const url = `${this.hackURL}/${repo}/-/git/commits`;
|
|
46
58
|
const postData: CreateCommitData = {
|
|
@@ -52,6 +64,7 @@ export class Repo extends CNBCore {
|
|
|
52
64
|
new_branch: data.new_branch || 'refs/heads/main',
|
|
53
65
|
};
|
|
54
66
|
if (!postData.parent_commit_sha) {
|
|
67
|
+
// 如果没有父提交sha,则说明是第一次提交,可以删除parent_commit_sha和base_branch字段
|
|
55
68
|
delete postData.parent_commit_sha;
|
|
56
69
|
delete postData.base_branch;
|
|
57
70
|
}
|