@kevisual/cnb 0.0.52 → 0.0.54

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.
@@ -0,0 +1,208 @@
1
+ import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts";
2
+
3
+ /**
4
+ * 标签基础类型
5
+ */
6
+ export type Label = {
7
+ /** 标签 ID */
8
+ id: string;
9
+ /** 标签名称 */
10
+ name: string;
11
+ /** 标签颜色(十六进制颜色码,不含 # 前缀) */
12
+ color: string;
13
+ /** 标签描述 */
14
+ description: string;
15
+ };
16
+
17
+ /**
18
+ * 创建标签的表单数据
19
+ */
20
+ export type PostLabelForm = {
21
+ /** 标签名称 */
22
+ name: string;
23
+ /** 标签颜色(十六进制颜色码,不含 # 前缀) */
24
+ color: string;
25
+ /** 标签描述 */
26
+ description?: string;
27
+ };
28
+
29
+ /**
30
+ * 更新标签的表单数据
31
+ */
32
+ export type PatchLabelForm = {
33
+ /** 标签颜色(十六进制颜色码,不含 # 前缀) */
34
+ color?: string;
35
+ /** 标签描述 */
36
+ description?: string;
37
+ /** 新标签名称 */
38
+ new_name?: string;
39
+ };
40
+
41
+ /**
42
+ * 设置 Issue 标签的表单数据(完全替换)
43
+ */
44
+ export type PutIssueLabelsForm = {
45
+ /** 标签名称数组 */
46
+ labels: string[];
47
+ };
48
+
49
+ /**
50
+ * 新增 Issue 标签的表单数据(追加)
51
+ */
52
+ export type PostIssueLabelsForm = {
53
+ /** 标签名称数组 */
54
+ labels: string[];
55
+ };
56
+
57
+ /**
58
+ * 仓库标签管理
59
+ */
60
+ export class RepoLabel extends CNBCore {
61
+ constructor(options: CNBCoreOptions) {
62
+ super(options);
63
+ }
64
+
65
+ /**
66
+ * 查询仓库的标签列表
67
+ * @param repo 仓库路径
68
+ * @param params 分页和搜索参数
69
+ */
70
+ list(repo: string, params?: ListLabelsParams): Promise<Result<Label[]>> {
71
+ const url = `/${repo}/-/labels`;
72
+ return this.get({
73
+ url,
74
+ params,
75
+ headers: {
76
+ 'Accept': 'application/vnd.cnb.api+json',
77
+ }
78
+ });
79
+ }
80
+
81
+ /**
82
+ * 创建一个标签
83
+ * @param repo 仓库路径
84
+ * @param data 标签数据
85
+ */
86
+ create(repo: string, data: PostLabelForm): Promise<Result<Label>> {
87
+ const url = `/${repo}/-/labels`;
88
+ return this.post({
89
+ url,
90
+ data,
91
+ });
92
+ }
93
+
94
+ /**
95
+ * 更新标签信息
96
+ * @param repo 仓库路径
97
+ * @param name 标签名称
98
+ * @param data 更新数据
99
+ */
100
+ update(repo: string, name: string, data: PatchLabelForm): Promise<Result<Label>> {
101
+ const url = `/${repo}/-/labels/${encodeURIComponent(name)}`;
102
+ return this.patch({
103
+ url,
104
+ data,
105
+ });
106
+ }
107
+
108
+ /**
109
+ * 删除指定的仓库标签
110
+ * @param repo 仓库路径
111
+ * @param name 标签名称
112
+ */
113
+ remove(repo: string, name: string): Promise<Result<void>> {
114
+ const url = `/${repo}/-/labels/${encodeURIComponent(name)}`;
115
+ return this.delete({ url });
116
+ }
117
+ }
118
+
119
+ type ListLabelsParams = {
120
+ /** 分页页码 */
121
+ page?: number;
122
+ /** 分页每页大小 */
123
+ page_size?: number;
124
+ /** 标签搜索关键词 */
125
+ keyword?: string;
126
+ }
127
+
128
+ /**
129
+ * Issue 标签管理
130
+ */
131
+ export class IssueLabel extends CNBCore {
132
+ constructor(options: CNBCoreOptions) {
133
+ super(options);
134
+ }
135
+
136
+ /**
137
+ * 查询 issue 的标签列表
138
+ * @param repo 仓库路径
139
+ * @param number Issue 编号
140
+ * @param params 分页参数
141
+ */
142
+ list(repo: string, number: string | number, params?: ListIssueLabelsParams): Promise<Result<Label[]>> {
143
+ const url = `/${repo}/-/issues/${number}/labels`;
144
+ return this.get({
145
+ url,
146
+ params,
147
+ headers: {
148
+ 'Accept': 'application/vnd.cnb.api+json',
149
+ }
150
+ });
151
+ }
152
+
153
+ /**
154
+ * 设置 issue 标签(完全替换现有标签)
155
+ * @param repo 仓库路径
156
+ * @param number Issue 编号
157
+ * @param data 标签数据
158
+ */
159
+ set(repo: string, number: string | number, data: PutIssueLabelsForm): Promise<Result<Label>> {
160
+ const url = `/${repo}/-/issues/${number}/labels`;
161
+ return this.put({
162
+ url,
163
+ data,
164
+ });
165
+ }
166
+
167
+ /**
168
+ * 新增 issue 标签(追加到现有标签)
169
+ * @param repo 仓库路径
170
+ * @param number Issue 编号
171
+ * @param data 标签数据
172
+ */
173
+ add(repo: string, number: string | number, data: PostIssueLabelsForm): Promise<Result<Label>> {
174
+ const url = `/${repo}/-/issues/${number}/labels`;
175
+ return this.post({
176
+ url,
177
+ data,
178
+ });
179
+ }
180
+
181
+ /**
182
+ * 清空 issue 标签(移除所有标签)
183
+ * @param repo 仓库路径
184
+ * @param number Issue 编号
185
+ */
186
+ clear(repo: string, number: string | number): Promise<Result<void>> {
187
+ const url = `/${repo}/-/issues/${number}/labels`;
188
+ return this.delete({ url });
189
+ }
190
+
191
+ /**
192
+ * 删除 issue 标签(移除指定标签)
193
+ * @param repo 仓库路径
194
+ * @param number Issue 编号
195
+ * @param name 标签名称
196
+ */
197
+ remove(repo: string, number: string | number, name: string): Promise<Result<void>> {
198
+ const url = `/${repo}/-/issues/${number}/labels/${encodeURIComponent(name)}`;
199
+ return this.delete({ url });
200
+ }
201
+ }
202
+
203
+ type ListIssueLabelsParams = {
204
+ /** 分页页码 */
205
+ page?: number;
206
+ /** 分页每页大小 */
207
+ page_size?: number;
208
+ }
@@ -1,4 +1,5 @@
1
1
  import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
2
+ import { queryResources, Selector } from "./modules/resources.ts";
2
3
 
3
4
  export class Mission extends CNBCore {
4
5
  constructor(options: CNBCoreOptions) {
@@ -121,6 +122,15 @@ export class Mission extends CNBCore {
121
122
  params: { visibility },
122
123
  });
123
124
  }
125
+ /**
126
+ * 查询任务集资源
127
+ * @param repo 仓库路径
128
+ * @param selectors 查询条件
129
+ * @returns 资源列表
130
+ */
131
+ queryResources(repo: string, selectors?: Selector[]) {
132
+ return queryResources(this, { repo, selectors });
133
+ }
124
134
  }
125
135
 
126
136
  // ==================== 类型定义 ====================
@@ -0,0 +1,164 @@
1
+ export const fields = [
2
+ {
3
+ "name": "resource_type",
4
+ "interaction_type": "radio",
5
+ "operators": [],
6
+ "value": [
7
+ "issues",
8
+ "pull_requests"
9
+ ]
10
+ },
11
+ {
12
+ "name": "started_at",
13
+ "interaction_type": "time_selector",
14
+ "operators": [
15
+ "equals",
16
+ "before",
17
+ "after",
18
+ "empty",
19
+ "not_empty"
20
+ ],
21
+ "value": []
22
+ },
23
+ {
24
+ "name": "ended_at",
25
+ "interaction_type": "time_selector",
26
+ "operators": [
27
+ "equals",
28
+ "before",
29
+ "after",
30
+ "empty",
31
+ "not_empty"
32
+ ],
33
+ "value": []
34
+ },
35
+ {
36
+ "name": "closed_at",
37
+ "interaction_type": "time_selector",
38
+ "operators": [
39
+ "equals",
40
+ "before",
41
+ "after",
42
+ "empty",
43
+ "not_empty"
44
+ ],
45
+ "value": []
46
+ },
47
+ {
48
+ "name": "assignee",
49
+ "interaction_type": "checkbox",
50
+ "operators": [
51
+ "contains",
52
+ "contains_all",
53
+ "not_contains",
54
+ "equals",
55
+ "not_equals",
56
+ "empty",
57
+ "not_empty"
58
+ ],
59
+ "value": [
60
+ {
61
+ "id": "",
62
+ "user_name": "",
63
+ "nick_name": "",
64
+ "user_type": 0
65
+ },
66
+ {
67
+ "id": "2026622946958528512",
68
+ "user_name": "cnb.cAiAVfFPgKA",
69
+ "nick_name": "里海暗红色",
70
+ "user_type": 0
71
+ },
72
+ {
73
+ "id": "1915352477005254656",
74
+ "user_name": "kevisual",
75
+ "nick_name": "科学和哲学",
76
+ "user_type": 0
77
+ },
78
+ {
79
+ "id": "1935321989751226368",
80
+ "user_name": "xiongxiao",
81
+ "nick_name": "小熊猫呜呜呜",
82
+ "user_type": 0
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "name": "repo",
88
+ "interaction_type": "checkbox",
89
+ "operators": [
90
+ "contains",
91
+ "not_contains"
92
+ ],
93
+ "value": [
94
+ "kevisual/kevisual",
95
+ "kevisual/cnb",
96
+ "abearxiong/blog",
97
+ "abearxiong/abearxiong"
98
+ ]
99
+ },
100
+ {
101
+ "name": "created_at",
102
+ "interaction_type": "time_selector",
103
+ "operators": [
104
+ "equals",
105
+ "before",
106
+ "after"
107
+ ],
108
+ "value": []
109
+ },
110
+ {
111
+ "name": "last_acted_at",
112
+ "interaction_type": "time_selector",
113
+ "operators": [
114
+ "equals",
115
+ "before",
116
+ "after"
117
+ ],
118
+ "value": []
119
+ },
120
+ {
121
+ "name": "priority",
122
+ "interaction_type": "checkbox",
123
+ "operators": [
124
+ "contains",
125
+ "not_contains",
126
+ "empty",
127
+ "not_empty"
128
+ ],
129
+ "value": [
130
+ "-2P",
131
+ "-1P",
132
+ "P0",
133
+ "P1",
134
+ "P2",
135
+ "P3",
136
+ ""
137
+ ]
138
+ },
139
+ {
140
+ "name": "state",
141
+ "interaction_type": "radio",
142
+ "operators": [
143
+ "equals",
144
+ "not_equals"
145
+ ],
146
+ "value": [
147
+ "open",
148
+ "closed"
149
+ ]
150
+ },
151
+ {
152
+ "name": "label",
153
+ "interaction_type": "radio",
154
+ "operators": [
155
+ "equals",
156
+ "not_equals"
157
+ ],
158
+ "value": [
159
+ "AICoding"
160
+ ]
161
+ }
162
+ ] as const;
163
+
164
+ export type FieldName = typeof fields[number]['name'];
@@ -0,0 +1,41 @@
1
+
2
+ // selectors
3
+ // :
4
+ // [{field: "resource_type", operator: "contains", value: ["issues"]},…]
5
+ // 0
6
+ // :
7
+ // {field: "resource_type", operator: "contains", value: ["issues"]}
8
+ // 1
9
+ // :
10
+ // {field: "state", operator: "not_equals", value: ["closed"]}
11
+ // slugName
12
+ // :
13
+ // "kevisual/projects"
14
+
15
+ import { CNBCore } from "@/cnb-core.ts";
16
+ import { FieldName } from "./fields.ts";
17
+
18
+ export type Selector = {
19
+ /**
20
+ * 字段名称,例如 resource_type、state 等
21
+ */
22
+ field: FieldName;
23
+ operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in';
24
+ // value: ["issues"]
25
+ value: any; // 可以是字符串、数组等,具体取决于 operator
26
+ }
27
+
28
+ export const queryResources = async (cnb: CNBCore, opts?: { repo?: string; selectors?: Selector[] }) => {
29
+ const url = `${cnb.hackURL}/${opts?.repo || 'kevisual/projects'}/-/mission-resource/resources`;
30
+ return cnb.post({
31
+ url,
32
+ data: {
33
+ selectors: opts?.selectors,
34
+ slugName: opts?.repo,
35
+ },
36
+ headers:{
37
+ Accept: 'application/vnd.cnb.web+json',
38
+ },
39
+ useCookie: true,
40
+ })
41
+ }