@kevisual/cnb 0.0.75 → 0.0.76

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.
@@ -1 +1,2 @@
1
1
  import './issue-label.ts'
2
+ import './tags.ts'
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { app, cnbManager } from '../../app.ts';
3
+
4
+ // 查询仓库的标签列表,并导入到新仓库
5
+ // pnpm cli cnb importTags -- source=kevisual/cnb target=abearxiong/jour-2026-04-13
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'importTags',
9
+ description: '从一个仓库导入标签到另一个仓库',
10
+ middleware: ['auth'],
11
+ metadata: {
12
+ args: {
13
+ source: z.string().describe('源仓库路径, 如 my-user/my-repo'),
14
+ target: z.string().describe('目标仓库路径, 如 my-user/my-repo'),
15
+ },
16
+ }
17
+ }).define(async (ctx) => {
18
+ const cnb = await cnbManager.getContext(ctx);
19
+ const sourceRepo = ctx.query?.source || 'kevisual/cnb';
20
+ const targetRepo = ctx.query?.target;
21
+ if (!targetRepo) {
22
+ ctx.throw(400, '缺少参数 target');
23
+ }
24
+
25
+ // 获取源仓库的标签列表
26
+ const res = await cnb.labels.repoLabel.getAll(sourceRepo);
27
+ if (res.code !== 200) {
28
+ return ctx.forward(res)
29
+ }
30
+ // 将标签列表导入到目标仓库
31
+ const importRes = await cnb.labels.repoLabel.importLabels({
32
+ repo: targetRepo,
33
+ labels: res.data,
34
+ });
35
+ ctx.forward(importRes);
36
+ }).addTo(app);
package/dist/cli-live.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
package/dist/cli.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -19796,15 +19814,15 @@ var __getProtoOf2 = Object.getPrototypeOf;
19796
19814
  var __defProp2 = Object.defineProperty;
19797
19815
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
19798
19816
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19799
- function __accessProp(key) {
19817
+ function __accessProp2(key) {
19800
19818
  return this[key];
19801
19819
  }
19802
- var __toESMCache_node;
19803
- var __toESMCache_esm;
19820
+ var __toESMCache_node2;
19821
+ var __toESMCache_esm2;
19804
19822
  var __toESM2 = (mod, isNodeMode, target) => {
19805
19823
  var canCache = mod != null && typeof mod === "object";
19806
19824
  if (canCache) {
19807
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
19825
+ var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
19808
19826
  var cached = cache.get(mod);
19809
19827
  if (cached)
19810
19828
  return cached;
@@ -19814,7 +19832,7 @@ var __toESM2 = (mod, isNodeMode, target) => {
19814
19832
  for (let key of __getOwnPropNames2(mod))
19815
19833
  if (!__hasOwnProp2.call(to, key))
19816
19834
  __defProp2(to, key, {
19817
- get: __accessProp.bind(mod, key),
19835
+ get: __accessProp2.bind(mod, key),
19818
19836
  enumerable: true
19819
19837
  });
19820
19838
  if (canCache)
@@ -19822,9 +19840,9 @@ var __toESM2 = (mod, isNodeMode, target) => {
19822
19840
  return to;
19823
19841
  };
19824
19842
  var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19825
- var __returnValue = (v) => v;
19826
- function __exportSetter(name, newValue) {
19827
- this[name] = __returnValue.bind(null, newValue);
19843
+ var __returnValue2 = (v) => v;
19844
+ function __exportSetter2(name, newValue) {
19845
+ this[name] = __returnValue2.bind(null, newValue);
19828
19846
  }
19829
19847
  var __export2 = (target, all) => {
19830
19848
  for (var name in all)
@@ -19832,7 +19850,7 @@ var __export2 = (target, all) => {
19832
19850
  get: all[name],
19833
19851
  enumerable: true,
19834
19852
  configurable: true,
19835
- set: __exportSetter.bind(all, name)
19853
+ set: __exportSetter2.bind(all, name)
19836
19854
  });
19837
19855
  };
19838
19856
  var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
@@ -40613,6 +40631,44 @@ class RepoLabel extends CNBCore {
40613
40631
  }
40614
40632
  });
40615
40633
  }
40634
+ async getAll(repo) {
40635
+ let labels = [];
40636
+ const pageSize = 99;
40637
+ for (let page = 1;; page++) {
40638
+ const res = await this.list(repo, { page, page_size: pageSize });
40639
+ if (res.code !== 200) {
40640
+ return { code: res.code, message: res.message, data: labels };
40641
+ }
40642
+ labels = labels.concat(res.data);
40643
+ if (res.data.length < pageSize) {
40644
+ break;
40645
+ }
40646
+ }
40647
+ return { code: 200, data: labels, message: "获取标签列表成功" };
40648
+ }
40649
+ async importLabels(opts) {
40650
+ const labels = opts.labels;
40651
+ const repo = opts.repo;
40652
+ const addLabels = [];
40653
+ for (const label of labels) {
40654
+ try {
40655
+ const res = await this.create(repo, label);
40656
+ if (res.code === 200) {
40657
+ addLabels.push(res.data);
40658
+ } else {
40659
+ if (res.code === 409) {
40660
+ console.warn(`标签已存在 ${label.name},跳过创建`);
40661
+ } else {
40662
+ console.error(`创建标签失败 ${label.name}:`, res.message);
40663
+ }
40664
+ }
40665
+ } catch (e) {
40666
+ console.error(`创建标签失败 ${label.name}:`, e);
40667
+ break;
40668
+ }
40669
+ }
40670
+ return { code: 200, data: { addLabels }, message: "导入标签成功" };
40671
+ }
40616
40672
  create(repo, data) {
40617
40673
  const url3 = `/${repo}/-/labels`;
40618
40674
  return this.post({
@@ -71664,6 +71720,36 @@ app.route({
71664
71720
  ctx.forward(res);
71665
71721
  }).addTo(app);
71666
71722
 
71723
+ // agent/routes/labels/tags.ts
71724
+ app.route({
71725
+ path: "cnb",
71726
+ key: "importTags",
71727
+ description: "从一个仓库导入标签到另一个仓库",
71728
+ middleware: ["auth"],
71729
+ metadata: {
71730
+ args: {
71731
+ source: exports_external2.string().describe("源仓库路径, 如 my-user/my-repo"),
71732
+ target: exports_external2.string().describe("目标仓库路径, 如 my-user/my-repo")
71733
+ }
71734
+ }
71735
+ }).define(async (ctx) => {
71736
+ const cnb = await cnbManager.getContext(ctx);
71737
+ const sourceRepo = ctx.query?.source || "kevisual/cnb";
71738
+ const targetRepo = ctx.query?.target;
71739
+ if (!targetRepo) {
71740
+ ctx.throw(400, "缺少参数 target");
71741
+ }
71742
+ const res = await cnb.labels.repoLabel.getAll(sourceRepo);
71743
+ if (res.code !== 200) {
71744
+ return ctx.forward(res);
71745
+ }
71746
+ const importRes = await cnb.labels.repoLabel.importLabels({
71747
+ repo: targetRepo,
71748
+ labels: res.data
71749
+ });
71750
+ ctx.forward(importRes);
71751
+ }).addTo(app);
71752
+
71667
71753
  // agent/routes/package/registry.ts
71668
71754
  app.route({
71669
71755
  path: "cnb",
@@ -72355,15 +72441,15 @@ var __getProtoOf4 = Object.getPrototypeOf;
72355
72441
  var __defProp5 = Object.defineProperty;
72356
72442
  var __getOwnPropNames4 = Object.getOwnPropertyNames;
72357
72443
  var __hasOwnProp4 = Object.prototype.hasOwnProperty;
72358
- function __accessProp2(key) {
72444
+ function __accessProp3(key) {
72359
72445
  return this[key];
72360
72446
  }
72361
- var __toESMCache_node2;
72362
- var __toESMCache_esm2;
72447
+ var __toESMCache_node3;
72448
+ var __toESMCache_esm3;
72363
72449
  var __toESM4 = (mod, isNodeMode, target) => {
72364
72450
  var canCache = mod != null && typeof mod === "object";
72365
72451
  if (canCache) {
72366
- var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
72452
+ var cache = isNodeMode ? __toESMCache_node3 ??= new WeakMap : __toESMCache_esm3 ??= new WeakMap;
72367
72453
  var cached3 = cache.get(mod);
72368
72454
  if (cached3)
72369
72455
  return cached3;
@@ -72373,7 +72459,7 @@ var __toESM4 = (mod, isNodeMode, target) => {
72373
72459
  for (let key of __getOwnPropNames4(mod))
72374
72460
  if (!__hasOwnProp4.call(to, key))
72375
72461
  __defProp5(to, key, {
72376
- get: __accessProp2.bind(mod, key),
72462
+ get: __accessProp3.bind(mod, key),
72377
72463
  enumerable: true
72378
72464
  });
72379
72465
  if (canCache)
@@ -72381,9 +72467,9 @@ var __toESM4 = (mod, isNodeMode, target) => {
72381
72467
  return to;
72382
72468
  };
72383
72469
  var __commonJS4 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
72384
- var __returnValue2 = (v) => v;
72385
- function __exportSetter2(name21, newValue) {
72386
- this[name21] = __returnValue2.bind(null, newValue);
72470
+ var __returnValue3 = (v) => v;
72471
+ function __exportSetter3(name21, newValue) {
72472
+ this[name21] = __returnValue3.bind(null, newValue);
72387
72473
  }
72388
72474
  var __export4 = (target, all) => {
72389
72475
  for (var name21 in all)
@@ -72391,7 +72477,7 @@ var __export4 = (target, all) => {
72391
72477
  get: all[name21],
72392
72478
  enumerable: true,
72393
72479
  configurable: true,
72394
- set: __exportSetter2.bind(all, name21)
72480
+ set: __exportSetter3.bind(all, name21)
72395
72481
  });
72396
72482
  };
72397
72483
  var __require4 = /* @__PURE__ */ createRequire4(import.meta.url);
package/dist/keep.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
package/dist/npc.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -17703,15 +17721,15 @@ var __getProtoOf2 = Object.getPrototypeOf;
17703
17721
  var __defProp2 = Object.defineProperty;
17704
17722
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
17705
17723
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
17706
- function __accessProp(key) {
17724
+ function __accessProp2(key) {
17707
17725
  return this[key];
17708
17726
  }
17709
- var __toESMCache_node;
17710
- var __toESMCache_esm;
17727
+ var __toESMCache_node2;
17728
+ var __toESMCache_esm2;
17711
17729
  var __toESM2 = (mod, isNodeMode, target) => {
17712
17730
  var canCache = mod != null && typeof mod === "object";
17713
17731
  if (canCache) {
17714
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17732
+ var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
17715
17733
  var cached = cache.get(mod);
17716
17734
  if (cached)
17717
17735
  return cached;
@@ -17721,7 +17739,7 @@ var __toESM2 = (mod, isNodeMode, target) => {
17721
17739
  for (let key of __getOwnPropNames2(mod))
17722
17740
  if (!__hasOwnProp2.call(to, key))
17723
17741
  __defProp2(to, key, {
17724
- get: __accessProp.bind(mod, key),
17742
+ get: __accessProp2.bind(mod, key),
17725
17743
  enumerable: true
17726
17744
  });
17727
17745
  if (canCache)
@@ -17729,9 +17747,9 @@ var __toESM2 = (mod, isNodeMode, target) => {
17729
17747
  return to;
17730
17748
  };
17731
17749
  var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
17732
- var __returnValue = (v) => v;
17733
- function __exportSetter(name, newValue) {
17734
- this[name] = __returnValue.bind(null, newValue);
17750
+ var __returnValue2 = (v) => v;
17751
+ function __exportSetter2(name, newValue) {
17752
+ this[name] = __returnValue2.bind(null, newValue);
17735
17753
  }
17736
17754
  var __export2 = (target, all) => {
17737
17755
  for (var name in all)
@@ -17739,7 +17757,7 @@ var __export2 = (target, all) => {
17739
17757
  get: all[name],
17740
17758
  enumerable: true,
17741
17759
  configurable: true,
17742
- set: __exportSetter.bind(all, name)
17760
+ set: __exportSetter2.bind(all, name)
17743
17761
  });
17744
17762
  };
17745
17763
  var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
@@ -38554,6 +38572,44 @@ class RepoLabel extends CNBCore {
38554
38572
  }
38555
38573
  });
38556
38574
  }
38575
+ async getAll(repo) {
38576
+ let labels = [];
38577
+ const pageSize = 99;
38578
+ for (let page = 1;; page++) {
38579
+ const res = await this.list(repo, { page, page_size: pageSize });
38580
+ if (res.code !== 200) {
38581
+ return { code: res.code, message: res.message, data: labels };
38582
+ }
38583
+ labels = labels.concat(res.data);
38584
+ if (res.data.length < pageSize) {
38585
+ break;
38586
+ }
38587
+ }
38588
+ return { code: 200, data: labels, message: "获取标签列表成功" };
38589
+ }
38590
+ async importLabels(opts) {
38591
+ const labels = opts.labels;
38592
+ const repo = opts.repo;
38593
+ const addLabels = [];
38594
+ for (const label of labels) {
38595
+ try {
38596
+ const res = await this.create(repo, label);
38597
+ if (res.code === 200) {
38598
+ addLabels.push(res.data);
38599
+ } else {
38600
+ if (res.code === 409) {
38601
+ console.warn(`标签已存在 ${label.name},跳过创建`);
38602
+ } else {
38603
+ console.error(`创建标签失败 ${label.name}:`, res.message);
38604
+ }
38605
+ }
38606
+ } catch (e) {
38607
+ console.error(`创建标签失败 ${label.name}:`, e);
38608
+ break;
38609
+ }
38610
+ }
38611
+ return { code: 200, data: { addLabels }, message: "导入标签成功" };
38612
+ }
38557
38613
  create(repo, data) {
38558
38614
  const url3 = `/${repo}/-/labels`;
38559
38615
  return this.post({
@@ -69605,6 +69661,36 @@ app.route({
69605
69661
  ctx.forward(res);
69606
69662
  }).addTo(app);
69607
69663
 
69664
+ // agent/routes/labels/tags.ts
69665
+ app.route({
69666
+ path: "cnb",
69667
+ key: "importTags",
69668
+ description: "从一个仓库导入标签到另一个仓库",
69669
+ middleware: ["auth"],
69670
+ metadata: {
69671
+ args: {
69672
+ source: exports_external2.string().describe("源仓库路径, 如 my-user/my-repo"),
69673
+ target: exports_external2.string().describe("目标仓库路径, 如 my-user/my-repo")
69674
+ }
69675
+ }
69676
+ }).define(async (ctx) => {
69677
+ const cnb = await cnbManager.getContext(ctx);
69678
+ const sourceRepo = ctx.query?.source || "kevisual/cnb";
69679
+ const targetRepo = ctx.query?.target;
69680
+ if (!targetRepo) {
69681
+ ctx.throw(400, "缺少参数 target");
69682
+ }
69683
+ const res = await cnb.labels.repoLabel.getAll(sourceRepo);
69684
+ if (res.code !== 200) {
69685
+ return ctx.forward(res);
69686
+ }
69687
+ const importRes = await cnb.labels.repoLabel.importLabels({
69688
+ repo: targetRepo,
69689
+ labels: res.data
69690
+ });
69691
+ ctx.forward(importRes);
69692
+ }).addTo(app);
69693
+
69608
69694
  // agent/routes/package/registry.ts
69609
69695
  app.route({
69610
69696
  path: "cnb",
@@ -70296,15 +70382,15 @@ var __getProtoOf4 = Object.getPrototypeOf;
70296
70382
  var __defProp5 = Object.defineProperty;
70297
70383
  var __getOwnPropNames4 = Object.getOwnPropertyNames;
70298
70384
  var __hasOwnProp4 = Object.prototype.hasOwnProperty;
70299
- function __accessProp2(key) {
70385
+ function __accessProp3(key) {
70300
70386
  return this[key];
70301
70387
  }
70302
- var __toESMCache_node2;
70303
- var __toESMCache_esm2;
70388
+ var __toESMCache_node3;
70389
+ var __toESMCache_esm3;
70304
70390
  var __toESM4 = (mod, isNodeMode, target) => {
70305
70391
  var canCache = mod != null && typeof mod === "object";
70306
70392
  if (canCache) {
70307
- var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
70393
+ var cache = isNodeMode ? __toESMCache_node3 ??= new WeakMap : __toESMCache_esm3 ??= new WeakMap;
70308
70394
  var cached3 = cache.get(mod);
70309
70395
  if (cached3)
70310
70396
  return cached3;
@@ -70314,7 +70400,7 @@ var __toESM4 = (mod, isNodeMode, target) => {
70314
70400
  for (let key of __getOwnPropNames4(mod))
70315
70401
  if (!__hasOwnProp4.call(to, key))
70316
70402
  __defProp5(to, key, {
70317
- get: __accessProp2.bind(mod, key),
70403
+ get: __accessProp3.bind(mod, key),
70318
70404
  enumerable: true
70319
70405
  });
70320
70406
  if (canCache)
@@ -70322,9 +70408,9 @@ var __toESM4 = (mod, isNodeMode, target) => {
70322
70408
  return to;
70323
70409
  };
70324
70410
  var __commonJS4 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
70325
- var __returnValue2 = (v) => v;
70326
- function __exportSetter2(name21, newValue) {
70327
- this[name21] = __returnValue2.bind(null, newValue);
70411
+ var __returnValue3 = (v) => v;
70412
+ function __exportSetter3(name21, newValue) {
70413
+ this[name21] = __returnValue3.bind(null, newValue);
70328
70414
  }
70329
70415
  var __export4 = (target, all) => {
70330
70416
  for (var name21 in all)
@@ -70332,7 +70418,7 @@ var __export4 = (target, all) => {
70332
70418
  get: all[name21],
70333
70419
  enumerable: true,
70334
70420
  configurable: true,
70335
- set: __exportSetter2.bind(all, name21)
70421
+ set: __exportSetter3.bind(all, name21)
70336
70422
  });
70337
70423
  };
70338
70424
  var __require4 = /* @__PURE__ */ createRequire4(import.meta.url);
@@ -86579,7 +86665,6 @@ var createCliList = (app3) => {
86579
86665
  console.log(table);
86580
86666
  }).addTo(app3, { overwrite: false });
86581
86667
  };
86582
-
86583
86668
  // node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/pick.mjs
86584
86669
  function pick6(obj, keys) {
86585
86670
  const result = {};
package/dist/opencode.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -17703,15 +17721,15 @@ var __getProtoOf2 = Object.getPrototypeOf;
17703
17721
  var __defProp2 = Object.defineProperty;
17704
17722
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
17705
17723
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
17706
- function __accessProp(key) {
17724
+ function __accessProp2(key) {
17707
17725
  return this[key];
17708
17726
  }
17709
- var __toESMCache_node;
17710
- var __toESMCache_esm;
17727
+ var __toESMCache_node2;
17728
+ var __toESMCache_esm2;
17711
17729
  var __toESM2 = (mod, isNodeMode, target) => {
17712
17730
  var canCache = mod != null && typeof mod === "object";
17713
17731
  if (canCache) {
17714
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17732
+ var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
17715
17733
  var cached = cache.get(mod);
17716
17734
  if (cached)
17717
17735
  return cached;
@@ -17721,7 +17739,7 @@ var __toESM2 = (mod, isNodeMode, target) => {
17721
17739
  for (let key of __getOwnPropNames2(mod))
17722
17740
  if (!__hasOwnProp2.call(to, key))
17723
17741
  __defProp2(to, key, {
17724
- get: __accessProp.bind(mod, key),
17742
+ get: __accessProp2.bind(mod, key),
17725
17743
  enumerable: true
17726
17744
  });
17727
17745
  if (canCache)
@@ -17729,9 +17747,9 @@ var __toESM2 = (mod, isNodeMode, target) => {
17729
17747
  return to;
17730
17748
  };
17731
17749
  var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
17732
- var __returnValue = (v) => v;
17733
- function __exportSetter(name, newValue) {
17734
- this[name] = __returnValue.bind(null, newValue);
17750
+ var __returnValue2 = (v) => v;
17751
+ function __exportSetter2(name, newValue) {
17752
+ this[name] = __returnValue2.bind(null, newValue);
17735
17753
  }
17736
17754
  var __export2 = (target, all) => {
17737
17755
  for (var name in all)
@@ -17739,7 +17757,7 @@ var __export2 = (target, all) => {
17739
17757
  get: all[name],
17740
17758
  enumerable: true,
17741
17759
  configurable: true,
17742
- set: __exportSetter.bind(all, name)
17760
+ set: __exportSetter2.bind(all, name)
17743
17761
  });
17744
17762
  };
17745
17763
  var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
@@ -38520,6 +38538,44 @@ class RepoLabel extends CNBCore {
38520
38538
  }
38521
38539
  });
38522
38540
  }
38541
+ async getAll(repo) {
38542
+ let labels = [];
38543
+ const pageSize = 99;
38544
+ for (let page = 1;; page++) {
38545
+ const res = await this.list(repo, { page, page_size: pageSize });
38546
+ if (res.code !== 200) {
38547
+ return { code: res.code, message: res.message, data: labels };
38548
+ }
38549
+ labels = labels.concat(res.data);
38550
+ if (res.data.length < pageSize) {
38551
+ break;
38552
+ }
38553
+ }
38554
+ return { code: 200, data: labels, message: "获取标签列表成功" };
38555
+ }
38556
+ async importLabels(opts) {
38557
+ const labels = opts.labels;
38558
+ const repo = opts.repo;
38559
+ const addLabels = [];
38560
+ for (const label of labels) {
38561
+ try {
38562
+ const res = await this.create(repo, label);
38563
+ if (res.code === 200) {
38564
+ addLabels.push(res.data);
38565
+ } else {
38566
+ if (res.code === 409) {
38567
+ console.warn(`标签已存在 ${label.name},跳过创建`);
38568
+ } else {
38569
+ console.error(`创建标签失败 ${label.name}:`, res.message);
38570
+ }
38571
+ }
38572
+ } catch (e) {
38573
+ console.error(`创建标签失败 ${label.name}:`, e);
38574
+ break;
38575
+ }
38576
+ }
38577
+ return { code: 200, data: { addLabels }, message: "导入标签成功" };
38578
+ }
38523
38579
  create(repo, data) {
38524
38580
  const url3 = `/${repo}/-/labels`;
38525
38581
  return this.post({
@@ -69571,6 +69627,36 @@ app.route({
69571
69627
  ctx.forward(res);
69572
69628
  }).addTo(app);
69573
69629
 
69630
+ // agent/routes/labels/tags.ts
69631
+ app.route({
69632
+ path: "cnb",
69633
+ key: "importTags",
69634
+ description: "从一个仓库导入标签到另一个仓库",
69635
+ middleware: ["auth"],
69636
+ metadata: {
69637
+ args: {
69638
+ source: exports_external2.string().describe("源仓库路径, 如 my-user/my-repo"),
69639
+ target: exports_external2.string().describe("目标仓库路径, 如 my-user/my-repo")
69640
+ }
69641
+ }
69642
+ }).define(async (ctx) => {
69643
+ const cnb = await cnbManager.getContext(ctx);
69644
+ const sourceRepo = ctx.query?.source || "kevisual/cnb";
69645
+ const targetRepo = ctx.query?.target;
69646
+ if (!targetRepo) {
69647
+ ctx.throw(400, "缺少参数 target");
69648
+ }
69649
+ const res = await cnb.labels.repoLabel.getAll(sourceRepo);
69650
+ if (res.code !== 200) {
69651
+ return ctx.forward(res);
69652
+ }
69653
+ const importRes = await cnb.labels.repoLabel.importLabels({
69654
+ repo: targetRepo,
69655
+ labels: res.data
69656
+ });
69657
+ ctx.forward(importRes);
69658
+ }).addTo(app);
69659
+
69574
69660
  // agent/routes/package/registry.ts
69575
69661
  app.route({
69576
69662
  path: "cnb",
@@ -70263,15 +70349,15 @@ var __getProtoOf4 = Object.getPrototypeOf;
70263
70349
  var __defProp5 = Object.defineProperty;
70264
70350
  var __getOwnPropNames4 = Object.getOwnPropertyNames;
70265
70351
  var __hasOwnProp4 = Object.prototype.hasOwnProperty;
70266
- function __accessProp2(key) {
70352
+ function __accessProp3(key) {
70267
70353
  return this[key];
70268
70354
  }
70269
- var __toESMCache_node2;
70270
- var __toESMCache_esm2;
70355
+ var __toESMCache_node3;
70356
+ var __toESMCache_esm3;
70271
70357
  var __toESM4 = (mod, isNodeMode, target) => {
70272
70358
  var canCache = mod != null && typeof mod === "object";
70273
70359
  if (canCache) {
70274
- var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
70360
+ var cache = isNodeMode ? __toESMCache_node3 ??= new WeakMap : __toESMCache_esm3 ??= new WeakMap;
70275
70361
  var cached3 = cache.get(mod);
70276
70362
  if (cached3)
70277
70363
  return cached3;
@@ -70281,7 +70367,7 @@ var __toESM4 = (mod, isNodeMode, target) => {
70281
70367
  for (let key of __getOwnPropNames4(mod))
70282
70368
  if (!__hasOwnProp4.call(to, key))
70283
70369
  __defProp5(to, key, {
70284
- get: __accessProp2.bind(mod, key),
70370
+ get: __accessProp3.bind(mod, key),
70285
70371
  enumerable: true
70286
70372
  });
70287
70373
  if (canCache)
@@ -70289,9 +70375,9 @@ var __toESM4 = (mod, isNodeMode, target) => {
70289
70375
  return to;
70290
70376
  };
70291
70377
  var __commonJS4 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
70292
- var __returnValue2 = (v) => v;
70293
- function __exportSetter2(name21, newValue) {
70294
- this[name21] = __returnValue2.bind(null, newValue);
70378
+ var __returnValue3 = (v) => v;
70379
+ function __exportSetter3(name21, newValue) {
70380
+ this[name21] = __returnValue3.bind(null, newValue);
70295
70381
  }
70296
70382
  var __export4 = (target, all) => {
70297
70383
  for (var name21 in all)
@@ -70299,7 +70385,7 @@ var __export4 = (target, all) => {
70299
70385
  get: all[name21],
70300
70386
  enumerable: true,
70301
70387
  configurable: true,
70302
- set: __exportSetter2.bind(all, name21)
70388
+ set: __exportSetter3.bind(all, name21)
70303
70389
  });
70304
70390
  };
70305
70391
  var __require4 = /* @__PURE__ */ createRequire4(import.meta.url);
package/dist/routes.d.ts CHANGED
@@ -1012,10 +1012,10 @@ declare class Mission extends CNBCore {
1012
1012
  /**
1013
1013
  * 改变任务集可见性
1014
1014
  * @param mission 任务集路径
1015
- * @param visibility 可见性 (PrivatePublic)
1015
+ * @param visibility 可见性 (privatepublic)
1016
1016
  * @returns 操作结果
1017
1017
  */
1018
- setVisibility(mission: string, visibility: 'Private' | 'Public'): Promise<Result<any>>;
1018
+ setVisibility(mission: string, visibility: 'private' | 'public'): Promise<Result<any>>;
1019
1019
  /**
1020
1020
  * 查询任务集资源
1021
1021
  * @param repo 仓库路径
@@ -1034,16 +1034,23 @@ type GetMissionsParams = {
1034
1034
  search?: string;
1035
1035
  };
1036
1036
  type CreateMissionData = {
1037
+ /**
1038
+ * 任务集名称,必填
1039
+ */
1037
1040
  name: string;
1038
1041
  description?: string;
1039
- visibility?: 'Private' | 'Public';
1042
+ visibility?: 'private' | 'public';
1043
+ /**
1044
+ * 关联的仓库列表,格式为 `${group}/${repo}`,如 `my-group/my-repo`
1045
+ */
1046
+ repos: string[];
1040
1047
  };
1041
1048
  type Missions4User = {
1042
1049
  id: string;
1043
1050
  name: string;
1044
1051
  slug_path: string;
1045
1052
  description: string;
1046
- visibility: 'Private' | 'Public';
1053
+ visibility: 'private' | 'public';
1047
1054
  created_at: string;
1048
1055
  updated_at: string;
1049
1056
  web_url: string;
@@ -1151,6 +1158,11 @@ declare class RepoLabel extends CNBCore {
1151
1158
  * @param params 分页和搜索参数
1152
1159
  */
1153
1160
  list(repo: string, params?: ListLabelsParams): Promise<Result<Label[]>>;
1161
+ getAll(repo: string): Promise<Result<Label[]>>;
1162
+ importLabels(opts: {
1163
+ repo: string;
1164
+ labels: PostLabelForm[];
1165
+ }): Promise<Result>;
1154
1166
  /**
1155
1167
  * 创建一个标签
1156
1168
  * @param repo 仓库路径
package/dist/routes.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name in all)
21
39
  __defProp(target, name, {
22
40
  get: all[name],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
43
+ set: __exportSetter.bind(all, name)
26
44
  });
27
45
  };
28
46
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -17703,15 +17721,15 @@ var __getProtoOf2 = Object.getPrototypeOf;
17703
17721
  var __defProp2 = Object.defineProperty;
17704
17722
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
17705
17723
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
17706
- function __accessProp(key) {
17724
+ function __accessProp2(key) {
17707
17725
  return this[key];
17708
17726
  }
17709
- var __toESMCache_node;
17710
- var __toESMCache_esm;
17727
+ var __toESMCache_node2;
17728
+ var __toESMCache_esm2;
17711
17729
  var __toESM2 = (mod, isNodeMode, target) => {
17712
17730
  var canCache = mod != null && typeof mod === "object";
17713
17731
  if (canCache) {
17714
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17732
+ var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
17715
17733
  var cached = cache.get(mod);
17716
17734
  if (cached)
17717
17735
  return cached;
@@ -17721,7 +17739,7 @@ var __toESM2 = (mod, isNodeMode, target) => {
17721
17739
  for (let key of __getOwnPropNames2(mod))
17722
17740
  if (!__hasOwnProp2.call(to, key))
17723
17741
  __defProp2(to, key, {
17724
- get: __accessProp.bind(mod, key),
17742
+ get: __accessProp2.bind(mod, key),
17725
17743
  enumerable: true
17726
17744
  });
17727
17745
  if (canCache)
@@ -17729,9 +17747,9 @@ var __toESM2 = (mod, isNodeMode, target) => {
17729
17747
  return to;
17730
17748
  };
17731
17749
  var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
17732
- var __returnValue = (v) => v;
17733
- function __exportSetter(name, newValue) {
17734
- this[name] = __returnValue.bind(null, newValue);
17750
+ var __returnValue2 = (v) => v;
17751
+ function __exportSetter2(name, newValue) {
17752
+ this[name] = __returnValue2.bind(null, newValue);
17735
17753
  }
17736
17754
  var __export2 = (target, all) => {
17737
17755
  for (var name in all)
@@ -17739,7 +17757,7 @@ var __export2 = (target, all) => {
17739
17757
  get: all[name],
17740
17758
  enumerable: true,
17741
17759
  configurable: true,
17742
- set: __exportSetter.bind(all, name)
17760
+ set: __exportSetter2.bind(all, name)
17743
17761
  });
17744
17762
  };
17745
17763
  var __require2 = /* @__PURE__ */ createRequire2(import.meta.url);
@@ -38520,6 +38538,44 @@ class RepoLabel extends CNBCore {
38520
38538
  }
38521
38539
  });
38522
38540
  }
38541
+ async getAll(repo) {
38542
+ let labels = [];
38543
+ const pageSize = 99;
38544
+ for (let page = 1;; page++) {
38545
+ const res = await this.list(repo, { page, page_size: pageSize });
38546
+ if (res.code !== 200) {
38547
+ return { code: res.code, message: res.message, data: labels };
38548
+ }
38549
+ labels = labels.concat(res.data);
38550
+ if (res.data.length < pageSize) {
38551
+ break;
38552
+ }
38553
+ }
38554
+ return { code: 200, data: labels, message: "获取标签列表成功" };
38555
+ }
38556
+ async importLabels(opts) {
38557
+ const labels = opts.labels;
38558
+ const repo = opts.repo;
38559
+ const addLabels = [];
38560
+ for (const label of labels) {
38561
+ try {
38562
+ const res = await this.create(repo, label);
38563
+ if (res.code === 200) {
38564
+ addLabels.push(res.data);
38565
+ } else {
38566
+ if (res.code === 409) {
38567
+ console.warn(`标签已存在 ${label.name},跳过创建`);
38568
+ } else {
38569
+ console.error(`创建标签失败 ${label.name}:`, res.message);
38570
+ }
38571
+ }
38572
+ } catch (e) {
38573
+ console.error(`创建标签失败 ${label.name}:`, e);
38574
+ break;
38575
+ }
38576
+ }
38577
+ return { code: 200, data: { addLabels }, message: "导入标签成功" };
38578
+ }
38523
38579
  create(repo, data) {
38524
38580
  const url3 = `/${repo}/-/labels`;
38525
38581
  return this.post({
@@ -69571,6 +69627,36 @@ app.route({
69571
69627
  ctx.forward(res);
69572
69628
  }).addTo(app);
69573
69629
 
69630
+ // agent/routes/labels/tags.ts
69631
+ app.route({
69632
+ path: "cnb",
69633
+ key: "importTags",
69634
+ description: "从一个仓库导入标签到另一个仓库",
69635
+ middleware: ["auth"],
69636
+ metadata: {
69637
+ args: {
69638
+ source: exports_external2.string().describe("源仓库路径, 如 my-user/my-repo"),
69639
+ target: exports_external2.string().describe("目标仓库路径, 如 my-user/my-repo")
69640
+ }
69641
+ }
69642
+ }).define(async (ctx) => {
69643
+ const cnb = await cnbManager.getContext(ctx);
69644
+ const sourceRepo = ctx.query?.source || "kevisual/cnb";
69645
+ const targetRepo = ctx.query?.target;
69646
+ if (!targetRepo) {
69647
+ ctx.throw(400, "缺少参数 target");
69648
+ }
69649
+ const res = await cnb.labels.repoLabel.getAll(sourceRepo);
69650
+ if (res.code !== 200) {
69651
+ return ctx.forward(res);
69652
+ }
69653
+ const importRes = await cnb.labels.repoLabel.importLabels({
69654
+ repo: targetRepo,
69655
+ labels: res.data
69656
+ });
69657
+ ctx.forward(importRes);
69658
+ }).addTo(app);
69659
+
69574
69660
  // agent/routes/package/registry.ts
69575
69661
  app.route({
69576
69662
  path: "cnb",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/cnb",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "basename": "/root/cnb",
@@ -77,7 +77,44 @@ export class RepoLabel extends CNBCore {
77
77
  }
78
78
  });
79
79
  }
80
-
80
+ async getAll(repo: string): Promise<Result<Label[]>> {
81
+ let labels: Label[] = [];
82
+ const pageSize = 99;
83
+ for (let page = 1; ; page++) {
84
+ const res = await this.list(repo, { page, page_size: pageSize });
85
+ if (res.code !== 200) {
86
+ return { code: res.code, message: res.message, data: labels };
87
+ }
88
+ labels = labels.concat(res.data);
89
+ if (res.data.length < pageSize) {
90
+ break;
91
+ }
92
+ }
93
+ return { code: 200, data: labels, message: '获取标签列表成功' };
94
+ }
95
+ async importLabels(opts: { repo: string, labels: PostLabelForm[] }): Promise<Result> {
96
+ const labels = opts.labels;
97
+ const repo = opts.repo;
98
+ const addLabels: Label[] = [];
99
+ for (const label of labels) {
100
+ try {
101
+ const res = await this.create(repo, label);
102
+ if (res.code === 200) {
103
+ addLabels.push(res.data);
104
+ } else {
105
+ if (res.code === 409) {
106
+ console.warn(`标签已存在 ${label.name},跳过创建`);
107
+ } else {
108
+ console.error(`创建标签失败 ${label.name}:`, res.message);
109
+ }
110
+ }
111
+ } catch (e) {
112
+ console.error(`创建标签失败 ${label.name}:`, e);
113
+ break;
114
+ }
115
+ }
116
+ return { code: 200, data: { addLabels }, message: '导入标签成功' };
117
+ }
81
118
  /**
82
119
  * 创建一个标签
83
120
  * @param repo 仓库路径
@@ -112,10 +112,10 @@ export class Mission extends CNBCore {
112
112
  /**
113
113
  * 改变任务集可见性
114
114
  * @param mission 任务集路径
115
- * @param visibility 可见性 (PrivatePublic)
115
+ * @param visibility 可见性 (privatepublic)
116
116
  * @returns 操作结果
117
117
  */
118
- setVisibility(mission: string, visibility: 'Private' | 'Public'): Promise<Result<any>> {
118
+ setVisibility(mission: string, visibility: 'private' | 'public'): Promise<Result<any>> {
119
119
  const url = `/${mission}/-/settings/set_visibility`;
120
120
  return this.post({
121
121
  url,
@@ -146,9 +146,16 @@ type GetMissionsParams = {
146
146
  };
147
147
 
148
148
  type CreateMissionData = {
149
+ /**
150
+ * 任务集名称,必填
151
+ */
149
152
  name: string;
150
153
  description?: string;
151
- visibility?: 'Private' | 'Public';
154
+ visibility?: 'private' | 'public';
155
+ /**
156
+ * 关联的仓库列表,格式为 `${group}/${repo}`,如 `my-group/my-repo`
157
+ */
158
+ repos: string[];
152
159
  };
153
160
 
154
161
  type Missions4User = {
@@ -156,7 +163,7 @@ type Missions4User = {
156
163
  name: string;
157
164
  slug_path: string;
158
165
  description: string;
159
- visibility: 'Private' | 'Public';
166
+ visibility: 'private' | 'public';
160
167
  created_at: string;
161
168
  updated_at: string;
162
169
  web_url: string;