@kevisual/cnb 0.0.42 → 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.
@@ -20,31 +20,37 @@ export function useNPCEnv() {
20
20
  * @description:对于 @ 知识库角色触发的 NPC 事件,值为 NPC 所属仓库路径,否则为空字符串
21
21
  */
22
22
  npcSlug,
23
+ npcSlugLabel: "对于 @ 知识库角色触发的 NPC 事件,值为 NPC 所属仓库路径,否则为空字符串",
23
24
  /**
24
25
  * @key CNB_NPC_NAME
25
26
  * @description:对于 NPC 事件触发的构建,值为 NPC 角色名,否则为空字符串
26
27
  */
27
28
  npcName,
29
+ npcNameLabel: "对于 NPC 事件触发的构建,值为 NPC 角色名,否则为空字符串",
28
30
  /**
29
31
  * @key CNB_NPC_SHA
30
32
  * @description:对于 @ 知识库角色触发的 NPC 事件,值为 NPC 所属仓库默认分支最新提交的 sha,否则为空字符串
31
33
  */
32
34
  npcSha,
35
+ npcShaLabel: "对于 @ 知识库角色触发的 NPC 事件,值为 NPC 所属仓库默认分支最新提交的 sha,否则为空字符串",
33
36
  /**
34
37
  * @key CNB_NPC_PROMPT
35
38
  * @description:对于 @ 知识库角色触发的 NPC 事件,值为 NPC 角色 Prompt,否则为空字符串
36
39
  */
37
40
  npcPrompt,
41
+ npcPromptLabel: "对于 @ 知识库角色触发的 NPC 事件,值为 NPC 角色 Prompt,否则为空字符串",
38
42
  /**
39
43
  * @key CNB_NPC_AVATAR
40
44
  * @description:对于 @ 知识库角色触发的 NPC 事件,值为 NPC 角色头像,否则为空字符串
41
45
  */
42
46
  npcAvatar,
47
+ npcAvatarLabel: "对于 @ 知识库角色触发的 NPC 事件,值为 NPC 角色头像,否则为空字符串",
43
48
  /**
44
49
  * @key CNB_NPC_ENABLE_THINKING
45
50
  * @description:对于 @npc 事件触发的构建,值为 NPC 角色是否开启思考,否则为空字符串
46
51
  */
47
- npcEnableThinking
52
+ npcEnableThinking,
53
+ npcEnableThinkingLabel: "对于 @npc 事件触发的构建,值为 NPC 角色是否开启思考,否则为空字符串"
48
54
  };
49
55
  }
50
56
 
@@ -69,349 +75,120 @@ export function useCommentEnv() {
69
75
  * @description:对于评论事件触发的构建,值为评论全局唯一 ID,否则为空字符串
70
76
  */
71
77
  commentId,
78
+ commentIdLabel: "对于评论事件触发的构建,值为评论全局唯一 ID,否则为空字符串",
72
79
  /**
73
80
  * @key CNB_COMMENT_BODY
74
81
  * @description:对于评论事件触发的构建,值为评论内容,否则为空字符串
75
82
  */
76
83
  commentBody,
84
+ commentBodyLabel: "对于评论事件触发的构建,值为评论内容,否则为空字符串",
77
85
  /**
78
86
  * @key CNB_COMMENT_TYPE
79
87
  * @description:note 对于 PR 代码评审评论,值为 diff_note;对于 PR 非代码评审评论以及 Issue 评论,值为 note;否则为空字符串
80
88
  */
81
89
  commentType,
90
+ commentTypeLabel: "对于 PR 代码评审评论,值为 diff_note;对于 PR 非代码评审评论以及 Issue 评论,值为 note;否则为空字符串",
82
91
  /**
83
92
  * @key CNB_COMMENT_FILE_PATH
84
93
  * @description:对于 PR 代码评审评论,值为评论所在文件,否则为空字符串
85
94
  */
86
95
  commentFilePath,
96
+ commentFilePathLabel: "对于 PR 代码评审评论,值为评论所在文件,否则为空字符串",
87
97
  /**
88
98
  * @key CNB_COMMENT_RANGE
89
99
  * @description:对于 PR 代码评审评论,值为评论所在代码行。如,单行为 L12,多行为 L13-L16,否则为空字符串
90
100
  */
91
101
  commentRange,
102
+ commentRangeLabel: "对于 PR 代码评审评论,值为评论所在代码行。如,单行为 L12,多行为 L13-L16,否则为空字符串",
92
103
  /**
93
104
  * @key CNB_REVIEW_ID
94
105
  * @description:对于 PR 代码评审,值为评审 ID,否则为空字符串
95
106
  */
96
- reviewId
107
+ reviewId,
108
+ reviewIdLabel: "对于 PR 代码评审,值为评审 ID,否则为空字符串"
97
109
  };
98
110
  }
99
111
 
100
- // CNB_BUILD_ID cnb-75b-1jj9hnk99 当前构建的流水号,全局唯一
101
- // CNB_BUILD_WEB_URL https://cnb.cool/kevision/dev-cnb/-/build/logs/cnb-75b-1jj9hnk99 当前构建的日志地址
102
- // CNB_BUILD_START_TIME 2026-03-09T14:59:01.550Z 当前构建的开始时间,UTC 格式,示例 2025-08-21T09:13:45.803Z
103
- // CNB_BUILD_USER xiongxiao 当前构建的触发者用户名
104
- // CNB_BUILD_USER_NICKNAME 小熊猫呜呜呜 当前构建的触发者昵称
105
- // CNB_BUILD_USER_EMAIL kevisual@xiongxiao.me 当前构建的触发者邮箱
106
- // CNB_BUILD_USER_ID 1935321989751226368 当前构建的触发者 id
107
- // CNB_BUILD_USER_NPC_SLUG 当前构建若为 NPC 触发,则为 NPC 所属仓库的路径
108
- // CNB_BUILD_USER_NPC_NAME 当前构建若为 NPC 触发,则为 NPC 角色名
109
- // CNB_BUILD_STAGE_NAME 初始化开发机 当前构建的 stage 名称
110
- // CNB_BUILD_JOB_NAME 初始化开发机 当前构建的 job 名称
111
- // CNB_BUILD_JOB_KEY job-0 当前构建的 job key,同 stage 下唯一
112
- // CNB_BUILD_WORKSPACE /workspace/ 自定义 shell 脚本执行的工作空间根目录
113
- // CNB_BUILD_FAILED_MSG 流水线构建失败的错误信息,可在 failStages 中使用
114
- // CNB_BUILD_FAILED_STAGE_NAME 流水线构建失败的 stage 的名称,可在 failStages 中使用
115
- // CNB_PIPELINE_NAME pipeline-1 当前 pipeline 的 name,没声明时为空
116
- // CNB_PIPELINE_KEY pipeline-1 当前 pipeline 的索引 key,例如 pipeline-0
117
- // CNB_PIPELINE_ID cnb-75b-1jj9hnk99-001 当前 pipeline 的 id,全局唯一字符串
118
- // CNB_PIPELINE_DOCKER_IMAGE docker.cnb.cool/kevisual/dev-env:latest 当前 pipeline 所使用的 docker image,如:alpine:latest
119
- // CNB_PIPELINE_STATUS 当前流水线的构建状态,可在 endStages 中查看,其可能的值包括:success、error、cancel
120
- // CNB_PIPELINE_MAX_RUN_TIME 72000000 流水线最大运行时间,单位为毫秒
121
- // CNB_RUNNER_IP 10.235.16.3 当前 pipeline 所在 Runner 的 ip
122
- // CNB_CPUS 16 当前构建流水线可以使用的最大 CPU 核数
123
- // CNB_MEMORY 32 当前构建流水线可以使用的最大内存大小,单位为 GiB
124
- // CNB_IS_RETRY false 当前构建是否由 rebuild 触发
125
- // HUSKY_SKIP_INSTALL 1 兼容 ci 环境下 husky
126
- export const useBuildEnv = () => {
127
- const buildId = useKey("CNB_BUILD_ID");
128
- const buildWebUrl = useKey("CNB_BUILD_WEB_URL");
129
- const buildStartTime = useKey("CNB_BUILD_START_TIME");
130
- const buildUser = useKey("CNB_BUILD_USER");
131
- const buildUserNickname = useKey("CNB_BUILD_USER_NICKNAME");
132
- const buildUserEmail = useKey("CNB_BUILD_USER_EMAIL");
133
- const buildUserId = useKey("CNB_BUILD_USER_ID");
134
- const buildUserNpcSlug = useKey("CNB_BUILD_USER_NPC_SLUG");
135
- const buildUserNpcName = useKey("CNB_BUILD_USER_NPC_NAME");
136
- const buildStageName = useKey("CNB_BUILD_STAGE_NAME");
137
- const buildJobName = useKey("CNB_BUILD_JOB_NAME");
138
- const buildJobKey = useKey("CNB_BUILD_JOB_KEY");
139
- const buildWorkspace = useKey("CNB_BUILD_WORKSPACE");
140
- const buildFailedMsg = useKey("CNB_BUILD_FAILED_MSG");
141
- const buildFailedStageName = useKey("CNB_BUILD_FAILED_STAGE_NAME");
142
- const pipelineName = useKey("CNB_PIPELINE_NAME");
143
- const pipelineKey = useKey("CNB_PIPELINE_KEY");
144
- const pipelineId = useKey("CNB_PIPELINE_ID");
145
- const pipelineDockerImage = useKey("CNB_PIPELINE_DOCKER_IMAGE");
146
- const pipelineStatus = useKey("CNB_PIPELINE_STATUS");
147
- const pipelineMaxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME");
148
- const runnerIp = useKey("CNB_RUNNER_IP");
149
- const cpus = useKey("CNB_CPUS");
150
- const memory = useKey("CNB_MEMORY");
151
- const isRetry = useKey("CNB_IS_RETRY");
152
- const huskySkipInstall = useKey("HUSKY_SKIP_INSTALL");
112
+ // CNB_ISSUE_ID Issue 全局唯一 ID
113
+ // CNB_ISSUE_IID Issue 仓库编号
114
+ // CNB_ISSUE_TITLE Issue 标题
115
+ // CNB_ISSUE_DESCRIPTION Issue 描述
116
+ // CNB_ISSUE_OWNER Issue 作者
117
+ // CNB_ISSUE_STATE Issue 状态
118
+ // CNB_ISSUE_IS_RESOLVED Issue 是否已解决
119
+ // CNB_ISSUE_ASSIGNEES Issue 处理人列表
120
+ // CNB_ISSUE_LABELS Issue 标签列表
121
+ // CNB_ISSUE_PRIORITY Issue 优先级
122
+ export const useIssueEnv = () => {
123
+ const issueId = useKey("CNB_ISSUE_ID");
124
+ const issueIid = useKey("CNB_ISSUE_IID");
125
+ const issueTitle = useKey("CNB_ISSUE_TITLE");
126
+ const issueDescription = useKey("CNB_ISSUE_DESCRIPTION");
127
+ const issueOwner = useKey("CNB_ISSUE_OWNER");
128
+ const issueState = useKey("CNB_ISSUE_STATE");
129
+ const issueIsResolved = useKey("CNB_ISSUE_IS_RESOLVED");
130
+ const issueAssignees = useKey("CNB_ISSUE_ASSIGNEES");
131
+ const issuePriority = useKey("CNB_ISSUE_PRIORITY");
153
132
 
154
133
  return {
155
134
  /**
156
- * @key CNB_BUILD_ID
157
- * @description:当前构建的流水号,全局唯一
135
+ * @key CNB_ISSUE_ID
136
+ * @description:Issue 全局唯一 ID
158
137
  */
159
- buildId,
138
+ issueId,
139
+ issueIdLabel: "Issue 全局唯一 ID",
160
140
  /**
161
- * @key CNB_BUILD_WEB_URL
162
- * @description:当前构建的日志地址
141
+ * @key CNB_ISSUE_IID
142
+ * @description:Issue 仓库编号
163
143
  */
164
- buildWebUrl,
144
+ issueIid,
145
+ issueIidLabel: "Issue 仓库编号",
165
146
  /**
166
- * @key CNB_BUILD_START_TIME
167
- * @description:当前构建的开始时间,UTC 格式
147
+ * @key CNB_ISSUE_TITLE
148
+ * @description:Issue 标题
168
149
  */
169
- buildStartTime,
150
+ issueTitle,
151
+ issueTitleLabel: "Issue 标题",
170
152
  /**
171
- * @key CNB_BUILD_USER
172
- * @description:当前构建的触发者用户名
153
+ * @key CNB_ISSUE_DESCRIPTION
154
+ * @description:Issue 描述
173
155
  */
174
- buildUser,
156
+ issueDescription,
157
+ issueDescriptionLabel: "Issue 描述",
175
158
  /**
176
- * @key CNB_BUILD_USER_NICKNAME
177
- * @description:当前构建的触发者昵称
159
+ * @key CNB_ISSUE_OWNER
160
+ * @description:Issue 作者
178
161
  */
179
- buildUserNickname,
162
+ issueOwner,
163
+ issueOwnerLabel: "Issue 作者",
180
164
  /**
181
- * @key CNB_BUILD_USER_EMAIL
182
- * @description:当前构建的触发者邮箱
165
+ * @key CNB_ISSUE_STATE
166
+ * @description:Issue 状态
183
167
  */
184
- buildUserEmail,
168
+ issueState,
169
+ issueStateLabel: "Issue 状态",
185
170
  /**
186
- * @key CNB_BUILD_USER_ID
187
- * @description:当前构建的触发者 id
171
+ * @key CNB_ISSUE_IS_RESOLVED
172
+ * @description:Issue 是否已解决
188
173
  */
189
- buildUserId,
174
+ issueIsResolved,
175
+ issueIsResolvedLabel: "Issue 是否已解决",
190
176
  /**
191
- * @key CNB_BUILD_USER_NPC_SLUG
192
- * @description:当前构建若为 NPC 触发,则为 NPC 所属仓库的路径
177
+ * @key CNB_ISSUE_ASSIGNEES
178
+ * @description:Issue 处理人列表
193
179
  */
194
- buildUserNpcSlug,
180
+ issueAssignees,
181
+ issueAssigneesLabel: "Issue 处理人列表",
195
182
  /**
196
- * @key CNB_BUILD_USER_NPC_NAME
197
- * @description:当前构建若为 NPC 触发,则为 NPC 角色名
183
+ * @key CNB_ISSUE_PRIORITY
184
+ * @description:Issue 优先级
198
185
  */
199
- buildUserNpcName,
200
- /**
201
- * @key CNB_BUILD_STAGE_NAME
202
- * @description:当前构建的 stage 名称
203
- */
204
- buildStageName,
205
- /**
206
- * @key CNB_BUILD_JOB_NAME
207
- * @description:当前构建的 job 名称
208
- */
209
- buildJobName,
210
- /**
211
- * @key CNB_BUILD_JOB_KEY
212
- * @description:当前构建的 job key,同 stage 下唯一
213
- */
214
- buildJobKey,
215
- /**
216
- * @key CNB_BUILD_WORKSPACE
217
- * @description:自定义 shell 脚本执行的工作空间根目录
218
- */
219
- buildWorkspace,
220
- /**
221
- * @key CNB_BUILD_FAILED_MSG
222
- * @description:流水线构建失败的错误信息
223
- */
224
- buildFailedMsg,
225
- /**
226
- * @key CNB_BUILD_FAILED_STAGE_NAME
227
- * @description:流水线构建失败的 stage 的名称
228
- */
229
- buildFailedStageName,
230
- /**
231
- * @key CNB_PIPELINE_NAME
232
- * @description:当前 pipeline 的 name
233
- */
234
- pipelineName,
235
- /**
236
- * @key CNB_PIPELINE_KEY
237
- * @description:当前 pipeline 的索引 key
238
- */
239
- pipelineKey,
240
- /**
241
- * @key CNB_PIPELINE_ID
242
- * @description:当前 pipeline 的 id
243
- */
244
- pipelineId,
245
- /**
246
- * @key CNB_PIPELINE_DOCKER_IMAGE
247
- * @description:当前 pipeline 所使用的 docker image
248
- */
249
- pipelineDockerImage,
250
- /**
251
- * @key CNB_PIPELINE_STATUS
252
- * @description:当前流水线的构建状态,可能的值包括:success、error、cancel
253
- */
254
- pipelineStatus,
255
- /**
256
- * @key CNB_PIPELINE_MAX_RUN_TIME
257
- * @description:流水线最大运行时间,单位为毫秒
258
- */
259
- pipelineMaxRunTime,
260
- /**
261
- * @key CNB_RUNNER_IP
262
- * @description:当前 pipeline 所在 Runner 的 ip
263
- */
264
- runnerIp,
265
- /**
266
- * @key CNB_CPUS
267
- * @description:当前构建流水线可以使用的最大 CPU 核数
268
- */
269
- cpus,
270
- /**
271
- * @key CNB_MEMORY
272
- * @description:当前构建流水线可以使用的最大内存大小,单位为 GiB
273
- */
274
- memory,
275
- /**
276
- * @key CNB_IS_RETRY
277
- * @description:当前构建是否由 rebuild 触发
278
- */
279
- isRetry,
280
- /**
281
- * @key HUSKY_SKIP_INSTALL
282
- * @description:兼容 ci 环境下 husky
283
- */
284
- huskySkipInstall
186
+ issuePriority,
187
+ issuePriorityLabel: "Issue 优先级"
285
188
  };
286
189
  }
287
190
 
288
- // CNB_PULL_REQUEST false 对于由 pull_request、pull_request.update、pull_request.target 触发的构建,值为 true,否则为 false
289
- // CNB_PULL_REQUEST_LIKE false 对于由 合并类事件 触发的构建,值为 true,否则为 false
290
- // CNB_PULL_REQUEST_PROPOSER 对于由 合并类事件 触发的构建,值为提出 PR 者名称,否则为空字符串
291
- // CNB_PULL_REQUEST_TITLE 对于由 合并类事件 触发的构建,值为提 PR 时候填写的标题,否则为空字符串
292
- // CNB_PULL_REQUEST_BRANCH 对于由 合并类事件 触发的构建,值为发起 PR 的源分支名称,否则为空字符串
293
- // CNB_PULL_REQUEST_SHA 对于由 合并类事件 触发的构建,值为当前 PR 源分支最新的提交 sha,否则为空字符串
294
- // CNB_PULL_REQUEST_TARGET_SHA 对于由 合并类事件 触发的构建,值为当前 PR 目标分支最新的提交 sha,否则为空字符串
295
- // CNB_PULL_REQUEST_MERGE_SHA 对于由 pull_request.merged 触发的构建,值为合并后的 sha;对于 pull_request 等触发的构建,值为预合并后的 sha,否则为空字符串
296
- // CNB_PULL_REQUEST_SLUG 对于由 合并类事件 触发的构建,值为源仓库的仓库 slug,如 group_slug/repo_name,否则为空字符串
297
- // CNB_PULL_REQUEST_ACTION 对于由 合并类事件 触发的构建,可能的值有:created(新建PR)、code_update(源分支push)、status_update(评审通过或CI状态变更),否则为空字符串
298
- // CNB_PULL_REQUEST_ID 对于由 合并类事件 触发的构建,值为当前或者关联 PR 的全局唯一 id,否则为空字符串
299
- export const usePullRequestEnv = () => {
300
- const pullRequest = useKey("CNB_PULL_REQUEST");
301
- const pullRequestLike = useKey("CNB_PULL_REQUEST_LIKE");
302
- const pullRequestProposer = useKey("CNB_PULL_REQUEST_PROPOSER");
303
- const pullRequestTitle = useKey("CNB_PULL_REQUEST_TITLE");
304
- const pullRequestBranch = useKey("CNB_PULL_REQUEST_BRANCH");
305
- const pullRequestSha = useKey("CNB_PULL_REQUEST_SHA");
306
- const pullRequestTargetSha = useKey("CNB_PULL_REQUEST_TARGET_SHA");
307
- const pullRequestMergeSha = useKey("CNB_PULL_REQUEST_MERGE_SHA");
308
- const pullRequestSlug = useKey("CNB_PULL_REQUEST_SLUG");
309
- const pullRequestAction = useKey("CNB_PULL_REQUEST_ACTION");
310
- const pullRequestId = useKey("CNB_PULL_REQUEST_ID");
311
191
 
312
- return {
313
- /**
314
- * @key CNB_PULL_REQUEST
315
- * @description:对于由 pull_request、pull_request.update、pull_request.target 触发的构建,值为 true,否则为 false
316
- */
317
- pullRequest,
318
- /**
319
- * @key CNB_PULL_REQUEST_LIKE
320
- * @description:对于由 合并类事件 触发的构建,值为 true,否则为 false
321
- */
322
- pullRequestLike,
323
- /**
324
- * @key CNB_PULL_REQUEST_PROPOSER
325
- * @description:对于由 合并类事件 触发的构建,值为提出 PR 者名称,否则为空字符串
326
- */
327
- pullRequestProposer,
328
- /**
329
- * @key CNB_PULL_REQUEST_TITLE
330
- * @description:对于由 合并类事件 触发的构建,值为提 PR 时候填写的标题,否则为空字符串
331
- */
332
- pullRequestTitle,
333
- /**
334
- * @key CNB_PULL_REQUEST_BRANCH
335
- * @description:对于由 合并类事件 触发的构建,值为发起 PR 的源分支名称,否则为空字符串
336
- */
337
- pullRequestBranch,
338
- /**
339
- * @key CNB_PULL_REQUEST_SHA
340
- * @description:对于由 合并类事件 触发的构建,值为当前 PR 源分支最新的提交 sha,否则为空字符串
341
- */
342
- pullRequestSha,
343
- /**
344
- * @key CNB_PULL_REQUEST_TARGET_SHA
345
- * @description:对于由 合并类事件 触发的构建,值为当前 PR 目标分支最新的提交 sha,否则为空字符串
346
- */
347
- pullRequestTargetSha,
348
- /**
349
- * @key CNB_PULL_REQUEST_MERGE_SHA
350
- * @description:对于由 pull_request.merged 触发的构建,值为合并后的 sha;对于 pull_request 等触发的构建,值为预合并后的 sha,否则为空字符串
351
- */
352
- pullRequestMergeSha,
353
- /**
354
- * @key CNB_PULL_REQUEST_SLUG
355
- * @description:对于由 合并类事件 触发的构建,值为源仓库的仓库 slug,如 group_slug/repo_name,否则为空字符串
356
- */
357
- pullRequestSlug,
358
- /**
359
- * @key CNB_PULL_REQUEST_ACTION
360
- * @description:对于由 合并类事件 触发的构建,可能的值有:created(新建PR)、code_update(源分支push)、status_update(评审通过或CI状态变更),否则为空字符串
361
- */
362
- pullRequestAction,
363
- /**
364
- * @key CNB_PULL_REQUEST_ID
365
- * @description:对于由 合并类事件 触发的构建,值为当前或者关联 PR 的全局唯一 id,否则为空字符串
366
- */
367
- pullRequestId
368
- };
369
- }
370
-
371
- // CNB_REPO_SLUG kevision/dev-cnb 目标仓库路径,格式为 group_slug / repo_name,group_slug / sub_gourp_slug /.../repo_name
372
- // CNB_REPO_SLUG_LOWERCASE kevision/dev-cnb 目标仓库路径小写格式
373
- // CNB_REPO_NAME dev-cnb 目标仓库名称
374
- // CNB_REPO_NAME_LOWERCASE dev-cnb 目标仓库名称小写格式
375
- // CNB_REPO_ID 2026263219584110592 目标仓库的 id
376
- // CNB_REPO_URL_HTTPS 目标仓库 https 地址
377
- export const useRepoInfoEnv = () => {
378
- const repoSlug = useKey("CNB_REPO_SLUG");
379
- const repoSlugLowercase = useKey("CNB_REPO_SLUG_LOWERCASE");
380
- const repoName = useKey("CNB_REPO_NAME");
381
- const repoNameLowercase = useKey("CNB_REPO_NAME_LOWERCASE");
382
- const repoId = useKey("CNB_REPO_ID");
383
- const repoUrlHttps = useKey("CNB_REPO_URL_HTTPS");
384
-
385
- return {
386
- /**
387
- * @key CNB_REPO_SLUG
388
- * @description:目标仓库路径,格式为 group_slug/repo_name,group_slug/sub_group_slug/.../repo_name
389
- */
390
- repoSlug,
391
- /**
392
- * @key CNB_REPO_SLUG_LOWERCASE
393
- * @description:目标仓库路径小写格式
394
- */
395
- repoSlugLowercase,
396
- /**
397
- * @key CNB_REPO_NAME
398
- * @description:目标仓库名称
399
- */
400
- repoName,
401
- /**
402
- * @key CNB_REPO_NAME_LOWERCASE
403
- * @description:目标仓库名称小写格式
404
- */
405
- repoNameLowercase,
406
- /**
407
- * @key CNB_REPO_ID
408
- * @description:目标仓库的 id
409
- */
410
- repoId,
411
- /**
412
- * @key CNB_REPO_URL_HTTPS
413
- * @description:目标仓库 https 地址
414
- */
415
- repoUrlHttps
416
- };
417
- }
192
+ export * from './build-env.ts'
193
+ export * from './pr-env.ts'
194
+ export * from './repo-env.ts'
@@ -0,0 +1,95 @@
1
+ import { useKey } from "@kevisual/context";
2
+
3
+ // CNB_PULL_REQUEST false 对于由 pull_request、pull_request.update、pull_request.target 触发的构建,值为 true,否则为 false
4
+ // CNB_PULL_REQUEST_LIKE false 对于由 合并类事件 触发的构建,值为 true,否则为 false
5
+ // CNB_PULL_REQUEST_PROPOSER 对于由 合并类事件 触发的构建,值为提出 PR 者名称,否则为空字符串
6
+ // CNB_PULL_REQUEST_TITLE 对于由 合并类事件 触发的构建,值为提 PR 时候填写的标题,否则为空字符串
7
+ // CNB_PULL_REQUEST_BRANCH 对于由 合并类事件 触发的构建,值为发起 PR 的源分支名称,否则为空字符串
8
+ // CNB_PULL_REQUEST_SHA 对于由 合并类事件 触发的构建,值为当前 PR 源分支最新的提交 sha,否则为空字符串
9
+ // CNB_PULL_REQUEST_TARGET_SHA 对于由 合并类事件 触发的构建,值为当前 PR 目标分支最新的提交 sha,否则为空字符串
10
+ // CNB_PULL_REQUEST_MERGE_SHA 对于由 pull_request.merged 触发的构建,值为合并后的 sha;对于 pull_request 等触发的构建,值为预合并后的 sha,否则为空字符串
11
+ // CNB_PULL_REQUEST_SLUG 对于由 合并类事件 触发的构建,值为源仓库的仓库 slug,如 group_slug/repo_name,否则为空字符串
12
+ // CNB_PULL_REQUEST_ACTION 对于由 合并类事件 触发的构建,可能的值有:created(新建PR)、code_update(源分支push)、status_update(评审通过或CI状态变更),否则为空字符串
13
+ // CNB_PULL_REQUEST_ID 对于由 合并类事件 触发的构建,值为当前或者关联 PR 的全局唯一 id,否则为空字符串
14
+ export const usePullRequestEnv = () => {
15
+ const pullRequest = useKey("CNB_PULL_REQUEST");
16
+ const pullRequestLike = useKey("CNB_PULL_REQUEST_LIKE");
17
+ const pullRequestProposer = useKey("CNB_PULL_REQUEST_PROPOSER");
18
+ const pullRequestTitle = useKey("CNB_PULL_REQUEST_TITLE");
19
+ const pullRequestBranch = useKey("CNB_PULL_REQUEST_BRANCH");
20
+ const pullRequestSha = useKey("CNB_PULL_REQUEST_SHA");
21
+ const pullRequestTargetSha = useKey("CNB_PULL_REQUEST_TARGET_SHA");
22
+ const pullRequestMergeSha = useKey("CNB_PULL_REQUEST_MERGE_SHA");
23
+ const pullRequestSlug = useKey("CNB_PULL_REQUEST_SLUG");
24
+ const pullRequestAction = useKey("CNB_PULL_REQUEST_ACTION");
25
+ const pullRequestId = useKey("CNB_PULL_REQUEST_ID");
26
+
27
+ return {
28
+ /**
29
+ * @key CNB_PULL_REQUEST
30
+ * @description:对于由 pull_request、pull_request.update、pull_request.target 触发的构建,值为 true,否则为 false
31
+ */
32
+ pullRequest,
33
+ pullRequestLabel: "对于由 pull_request、pull_request.update、pull_request.target 触发的构建,值为 true,否则为 false",
34
+ /**
35
+ * @key CNB_PULL_REQUEST_LIKE
36
+ * @description:对于由 合并类事件 触发的构建,值为 true,否则为 false
37
+ */
38
+ pullRequestLike,
39
+ pullRequestLikeLabel: "对于由 合并类事件 触发的构建,值为 true,否则为 false",
40
+ /**
41
+ * @key CNB_PULL_REQUEST_PROPOSER
42
+ * @description:对于由 合并类事件 触发的构建,值为提出 PR 者名称,否则为空字符串
43
+ */
44
+ pullRequestProposer,
45
+ pullRequestProposerLabel: "对于由 合并类事件 触发的构建,值为提出 PR 者名称,否则为空字符串",
46
+ /**
47
+ * @key CNB_PULL_REQUEST_TITLE
48
+ * @description:对于由 合并类事件 触发的构建,值为提 PR 时候填写的标题,否则为空字符串
49
+ */
50
+ pullRequestTitle,
51
+ pullRequestTitleLabel: "对于由 合并类事件 触发的构建,值为提 PR 时候填写的标题,否则为空字符串",
52
+ /**
53
+ * @key CNB_PULL_REQUEST_BRANCH
54
+ * @description:对于由 合并类事件 触发的构建,值为发起 PR 的源分支名称,否则为空字符串
55
+ */
56
+ pullRequestBranch,
57
+ pullRequestBranchLabel: "对于由 合并类事件 触发的构建,值为发起 PR 的源分支名称,否则为空字符串",
58
+ /**
59
+ * @key CNB_PULL_REQUEST_SHA
60
+ * @description:对于由 合并类事件 触发的构建,值为当前 PR 源分支最新的提交 sha,否则为空字符串
61
+ */
62
+ pullRequestSha,
63
+ pullRequestShaLabel: "对于由 合并类事件 触发的构建,值为当前 PR 源分支最新的提交 sha,否则为空字符串",
64
+ /**
65
+ * @key CNB_PULL_REQUEST_TARGET_SHA
66
+ * @description:对于由 合并类事件 触发的构建,值为当前 PR 目标分支最新的提交 sha,否则为空字符串
67
+ */
68
+ pullRequestTargetSha,
69
+ pullRequestTargetShaLabel: "对于由 合并类事件 触发的构建,值为当前 PR 目标分支最新的提交 sha,否则为空字符串",
70
+ /**
71
+ * @key CNB_PULL_REQUEST_MERGE_SHA
72
+ * @description:对于由 pull_request.merged 触发的构建,值为合并后的 sha;对于 pull_request 等触发的构建,值为预合并后的 sha,否则为空字符串
73
+ */
74
+ pullRequestMergeSha,
75
+ pullRequestMergeShaLabel: "对于由 pull_request.merged 触发的构建,值为合并后的 sha;对于 pull_request 等触发的构建,值为预合并后的 sha,否则为空字符串",
76
+ /**
77
+ * @key CNB_PULL_REQUEST_SLUG
78
+ * @description:对于由 合并类事件 触发的构建,值为源仓库的仓库 slug,如 group_slug/repo_name,否则为空字符串
79
+ */
80
+ pullRequestSlug,
81
+ pullRequestSlugLabel: "对于由 合并类事件 触发的构建,值为源仓库的仓库 slug,如 group_slug/repo_name,否则为空字符串",
82
+ /**
83
+ * @key CNB_PULL_REQUEST_ACTION
84
+ * @description:对于由 合并类事件 触发的构建,可能的值有:created(新建PR)、code_update(源分支push)、status_update(评审通过或CI状态变更),否则为空字符串
85
+ */
86
+ pullRequestAction,
87
+ pullRequestActionLabel: "对于由 合并类事件 触发的构建,可能的值有:created(新建PR)、code_update(源分支push)、status_update(评审通过或CI状态变更),否则为空字符串",
88
+ /**
89
+ * @key CNB_PULL_REQUEST_ID
90
+ * @description:对于由 合并类事件 触发的构建,值为当前或者关联 PR 的全局唯一 id,否则为空字符串
91
+ */
92
+ pullRequestId,
93
+ pullRequestIdLabel: "对于由 合并类事件 触发的构建,值为当前或者关联 PR 的全局唯一 id,否则为空字符串"
94
+ };
95
+ }
@@ -0,0 +1,56 @@
1
+ import { useKey } from "@kevisual/context";
2
+
3
+ // CNB_REPO_SLUG kevision/dev-cnb 目标仓库路径,格式为 group_slug / repo_name,group_slug / sub_gourp_slug /.../repo_name
4
+ // CNB_REPO_SLUG_LOWERCASE kevision/dev-cnb 目标仓库路径小写格式
5
+ // CNB_REPO_NAME dev-cnb 目标仓库名称
6
+ // CNB_REPO_NAME_LOWERCASE dev-cnb 目标仓库名称小写格式
7
+ // CNB_REPO_ID 2026263219584110592 目标仓库的 id
8
+ // CNB_REPO_URL_HTTPS 目标仓库 https 地址
9
+ export const useRepoInfoEnv = () => {
10
+ const repoSlug = useKey("CNB_REPO_SLUG");
11
+ const repoSlugLowercase = useKey("CNB_REPO_SLUG_LOWERCASE");
12
+ const repoName = useKey("CNB_REPO_NAME");
13
+ const repoNameLowercase = useKey("CNB_REPO_NAME_LOWERCASE");
14
+ const repoId = useKey("CNB_REPO_ID");
15
+ const repoUrlHttps = useKey("CNB_REPO_URL_HTTPS");
16
+
17
+ return {
18
+ /**
19
+ * @key CNB_REPO_SLUG
20
+ * @description:目标仓库路径,格式为 group_slug/repo_name,group_slug/sub_group_slug/.../repo_name
21
+ */
22
+ repoSlug,
23
+ repoSlugLabel: "目标仓库路径,格式为 group_slug/repo_name,group_slug/sub_group_slug/.../repo_name",
24
+ /**
25
+ * @key CNB_REPO_SLUG_LOWERCASE
26
+ * @description:目标仓库路径小写格式
27
+ */
28
+ repoSlugLowercase,
29
+ repoSlugLowercaseLabel: "目标仓库路径小写格式",
30
+ /**
31
+ * @key CNB_REPO_NAME
32
+ * @description:目标仓库名称
33
+ */
34
+ repoName,
35
+ repoNameLabel: "目标仓库名称",
36
+ /**
37
+ * @key CNB_REPO_NAME_LOWERCASE
38
+ * @description:目标仓库名称小写格式
39
+ */
40
+ repoNameLowercase,
41
+ repoNameLowercaseLabel: "目标仓库名称小写格式",
42
+ /**
43
+ * @key CNB_REPO_ID
44
+ * @description:目标仓库的 id
45
+ */
46
+ repoId,
47
+ repoIdLabel: "目标仓库的 id",
48
+ /**
49
+ * @key CNB_REPO_URL_HTTPS
50
+ * @description:目标仓库 https 地址
51
+ */
52
+ repoUrlHttps,
53
+ repoUrlHttpsLabel: "目标仓库 https 地址"
54
+ };
55
+ }
56
+
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
  }