@cnbcool/cnb-cli 1.3.0 → 1.4.0
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/bin/cnb.js +1 -1
- package/dist/index.js +66 -0
- package/package.json +10 -5
- package/cli/core/config/cag.config.js +0 -58
- package/cli/core/core.js +0 -124
- package/cli/core/fetch-response-handler.js +0 -34
- package/cli/core/flat-options.json +0 -8909
- package/cli/core/help.json +0 -38458
- package/cli/core/index.js +0 -40
- package/cli/core/key-mapping.json +0 -538
- package/cli/core/lib/execute-action.js +0 -117
- package/cli/core/lib/extra-help.js +0 -20
- package/cli/core/lib/flat-options-data.js +0 -16
- package/cli/core/lib/format-output.js +0 -85
- package/cli/core/lib/format-params.js +0 -217
- package/cli/core/lib/help-data.js +0 -15
- package/cli/core/lib/key-mapping-data.js +0 -16
- package/cli/core/lib/parsers.js +0 -126
- package/cli/core/lib/print-json.js +0 -24
- package/cli/core/lib/register-fallback.js +0 -15
- package/cli/core/lib/register-modules.js +0 -121
- package/cli/core/lib/summary-extractors.js +0 -181
- package/cli/core/lib/trim-summary.js +0 -17
- package/cli/core/shortcuts.js +0 -276
- package/cli/core/utils/build-nested-field-map.js +0 -35
- package/cli/core/utils/convert-link.js +0 -144
- package/cli/core/utils/flat-key-from-segments.js +0 -14
- package/cli/core/utils/generate-unique-id.js +0 -10
- package/cli/core/utils/match-array-object-field.js +0 -25
- package/cli/core/utils/restore-original-keys.js +0 -24
- package/cli/core/utils/upload.js +0 -237
- package/cli/modules/activities/get-user-activities-by-date.js +0 -75
- package/cli/modules/activities/get-user-repo-activity-details.js +0 -77
- package/cli/modules/activities/top-contributors.js +0 -75
- package/cli/modules/ai/ai-chat-completions.js +0 -69
- package/cli/modules/assets/delete-asset.js +0 -75
- package/cli/modules/assets/get-files.js +0 -75
- package/cli/modules/assets/get-imgs.js +0 -75
- package/cli/modules/assets/list-assets.js +0 -75
- package/cli/modules/badge/get-badge.js +0 -79
- package/cli/modules/badge/list-badge.js +0 -69
- package/cli/modules/badge/upload-badge.js +0 -69
- package/cli/modules/build/build-crontab-sync.js +0 -74
- package/cli/modules/build/build-logs-delete.js +0 -74
- package/cli/modules/build/build-runner-download-log.js +0 -74
- package/cli/modules/build/get-build-logs.js +0 -75
- package/cli/modules/build/get-build-stage.js +0 -78
- package/cli/modules/build/get-build-status.js +0 -74
- package/cli/modules/build/start-build.js +0 -69
- package/cli/modules/build/stop-build.js +0 -74
- package/cli/modules/charge/get-special-amount.js +0 -67
- package/cli/modules/event/get-events.js +0 -73
- package/cli/modules/followers/get-followers-by-user-id.js +0 -75
- package/cli/modules/followers/get-following-by-user-id.js +0 -75
- package/cli/modules/git/create-blob.js +0 -69
- package/cli/modules/git/create-branch-lock.js +0 -74
- package/cli/modules/git/create-branch.js +0 -69
- package/cli/modules/git/create-tag.js +0 -69
- package/cli/modules/git/delete-branch-lock.js +0 -74
- package/cli/modules/git/delete-branch.js +0 -74
- package/cli/modules/git/delete-commit-annotation.js +0 -76
- package/cli/modules/git/delete-commit-asset.js +0 -76
- package/cli/modules/git/delete-tag-annotation.js +0 -74
- package/cli/modules/git/delete-tag.js +0 -74
- package/cli/modules/git/get-archive-commit-changed-files.js +0 -74
- package/cli/modules/git/get-archive-compare-changed-files.js +0 -74
- package/cli/modules/git/get-archive.js +0 -74
- package/cli/modules/git/get-branch.js +0 -74
- package/cli/modules/git/get-commit-annotations-in-batch.js +0 -69
- package/cli/modules/git/get-commit-annotations.js +0 -74
- package/cli/modules/git/get-commit-assets-by-sha.js +0 -74
- package/cli/modules/git/get-commit-assets.js +0 -79
- package/cli/modules/git/get-commit-statuses.js +0 -74
- package/cli/modules/git/get-commit.js +0 -74
- package/cli/modules/git/get-compare-commits.js +0 -74
- package/cli/modules/git/get-content-without-path.js +0 -75
- package/cli/modules/git/get-content.js +0 -77
- package/cli/modules/git/get-head.js +0 -66
- package/cli/modules/git/get-presigned-lfs-download-link.js +0 -77
- package/cli/modules/git/get-raw.js +0 -77
- package/cli/modules/git/get-tag-annotations.js +0 -74
- package/cli/modules/git/get-tag.js +0 -74
- package/cli/modules/git/list-branches.js +0 -75
- package/cli/modules/git/list-commits.js +0 -75
- package/cli/modules/git/list-tags.js +0 -75
- package/cli/modules/git/post-commit-asset-upload-confirmation.js +0 -81
- package/cli/modules/git/post-commit-asset-upload-url.js +0 -77
- package/cli/modules/git/put-commit-annotations.js +0 -77
- package/cli/modules/git/put-tag-annotations.js +0 -77
- package/cli/modules/git-settings/delete-branch-protection.js +0 -74
- package/cli/modules/git-settings/get-branch-protection.js +0 -74
- package/cli/modules/git-settings/get-pipeline-settings.js +0 -66
- package/cli/modules/git-settings/get-pull-request-settings.js +0 -66
- package/cli/modules/git-settings/get-push-limit-settings.js +0 -66
- package/cli/modules/git-settings/list-branch-protections.js +0 -66
- package/cli/modules/git-settings/patch-branch-protection.js +0 -77
- package/cli/modules/git-settings/post-branch-protection.js +0 -69
- package/cli/modules/git-settings/put-pipeline-settings.js +0 -69
- package/cli/modules/git-settings/put-pull-request-settings.js +0 -69
- package/cli/modules/git-settings/put-push-limit-settings.js +0 -69
- package/cli/modules/issues/can-user-be-assigned-to-issue.js +0 -76
- package/cli/modules/issues/create-issue.js +0 -69
- package/cli/modules/issues/delete-issue-assignees.js +0 -77
- package/cli/modules/issues/delete-issue-label.js +0 -76
- package/cli/modules/issues/delete-issue-labels.js +0 -74
- package/cli/modules/issues/get-issue-comment.js +0 -76
- package/cli/modules/issues/get-issue.js +0 -74
- package/cli/modules/issues/list-issue-activities-latest.js +0 -76
- package/cli/modules/issues/list-issue-activities.js +0 -77
- package/cli/modules/issues/list-issue-assignees.js +0 -74
- package/cli/modules/issues/list-issue-comments.js +0 -77
- package/cli/modules/issues/list-issue-labels.js +0 -77
- package/cli/modules/issues/list-issues.js +0 -75
- package/cli/modules/issues/list-user-issues.js +0 -71
- package/cli/modules/issues/patch-issue-assignees.js +0 -77
- package/cli/modules/issues/patch-issue-comment.js +0 -79
- package/cli/modules/issues/post-issue-assignees.js +0 -77
- package/cli/modules/issues/post-issue-comment.js +0 -77
- package/cli/modules/issues/post-issue-file-asset-upload-url.js +0 -77
- package/cli/modules/issues/post-issue-image-asset-upload-url.js +0 -77
- package/cli/modules/issues/post-issue-labels.js +0 -77
- package/cli/modules/issues/put-issue-labels.js +0 -77
- package/cli/modules/issues/update-issue-properties.js +0 -78
- package/cli/modules/issues/update-issue.js +0 -77
- package/cli/modules/knowledge-base/delete-knowledge-base.js +0 -66
- package/cli/modules/knowledge-base/get-knowledge-base-info.js +0 -66
- package/cli/modules/knowledge-base/get-models.js +0 -66
- package/cli/modules/knowledge-base/query-knowledge-base.js +0 -69
- package/cli/modules/knowledge-base/search-npc.js +0 -71
- package/cli/modules/members/add-members-of-group.js +0 -77
- package/cli/modules/members/add-members-of-mission.js +0 -77
- package/cli/modules/members/add-members-of-registry.js +0 -77
- package/cli/modules/members/add-members-of-repo.js +0 -77
- package/cli/modules/members/delete-members-of-group.js +0 -74
- package/cli/modules/members/delete-members-of-repo.js +0 -74
- package/cli/modules/members/delete-outside-collaborators.js +0 -74
- package/cli/modules/members/get-member-access-level-of-group.js +0 -75
- package/cli/modules/members/get-member-access-level-of-repo.js +0 -75
- package/cli/modules/members/list-all-members.js +0 -75
- package/cli/modules/members/list-inherit-members-of-group.js +0 -75
- package/cli/modules/members/list-inherit-members-of-repo.js +0 -75
- package/cli/modules/members/list-member-access-level-of-group.js +0 -74
- package/cli/modules/members/list-member-access-level-of-repo.js +0 -74
- package/cli/modules/members/list-members-of-group.js +0 -75
- package/cli/modules/members/list-members-of-repo.js +0 -75
- package/cli/modules/members/list-outside-collaborators.js +0 -75
- package/cli/modules/members/update-members-of-group.js +0 -77
- package/cli/modules/members/update-members-of-repo.js +0 -77
- package/cli/modules/members/update-outside-collaborators.js +0 -77
- package/cli/modules/missions/create-mission.js +0 -69
- package/cli/modules/missions/delete-mission.js +0 -66
- package/cli/modules/missions/get-group-sub-missions.js +0 -75
- package/cli/modules/missions/get-mission-view-config.js +0 -75
- package/cli/modules/missions/get-mission-view-list.js +0 -66
- package/cli/modules/missions/post-mission-view-config.js +0 -69
- package/cli/modules/missions/post-mission-view-list.js +0 -69
- package/cli/modules/missions/put-mission-view-list.js +0 -69
- package/cli/modules/missions/set-mission-visibility.js +0 -75
- package/cli/modules/organizations/create-organization.js +0 -65
- package/cli/modules/organizations/delete-organization.js +0 -66
- package/cli/modules/organizations/get-group-setting.js +0 -66
- package/cli/modules/organizations/get-group.js +0 -66
- package/cli/modules/organizations/get-groups-by-user-id.js +0 -75
- package/cli/modules/organizations/list-groups.js +0 -75
- package/cli/modules/organizations/list-subgroups.js +0 -75
- package/cli/modules/organizations/list-top-groups.js +0 -71
- package/cli/modules/organizations/transfer-group.js +0 -69
- package/cli/modules/organizations/update-group-setting.js +0 -69
- package/cli/modules/organizations/update-organization.js +0 -69
- package/cli/modules/organizations/upload-logos.js +0 -69
- package/cli/modules/pulls/can-user-be-assigned-to-pull.js +0 -76
- package/cli/modules/pulls/delete-pull-assignees.js +0 -77
- package/cli/modules/pulls/delete-pull-label.js +0 -76
- package/cli/modules/pulls/delete-pull-labels.js +0 -74
- package/cli/modules/pulls/delete-repo-files.js +0 -75
- package/cli/modules/pulls/delete-repo-imgs.js +0 -75
- package/cli/modules/pulls/get-pull-comment.js +0 -76
- package/cli/modules/pulls/get-pull.js +0 -74
- package/cli/modules/pulls/list-pull-assignees.js +0 -74
- package/cli/modules/pulls/list-pull-comments.js +0 -77
- package/cli/modules/pulls/list-pull-commit-statuses.js +0 -74
- package/cli/modules/pulls/list-pull-commits.js +0 -77
- package/cli/modules/pulls/list-pull-files.js +0 -74
- package/cli/modules/pulls/list-pull-labels.js +0 -77
- package/cli/modules/pulls/list-pull-review-comments.js +0 -79
- package/cli/modules/pulls/list-pull-reviews.js +0 -77
- package/cli/modules/pulls/list-pulls-by-numbers.js +0 -75
- package/cli/modules/pulls/list-pulls.js +0 -75
- package/cli/modules/pulls/merge-pull.js +0 -77
- package/cli/modules/pulls/patch-pull-comment.js +0 -79
- package/cli/modules/pulls/patch-pull.js +0 -77
- package/cli/modules/pulls/post-pull-assignees.js +0 -77
- package/cli/modules/pulls/post-pull-comment.js +0 -77
- package/cli/modules/pulls/post-pull-labels.js +0 -77
- package/cli/modules/pulls/post-pull-request-review-reply.js +0 -79
- package/cli/modules/pulls/post-pull-review.js +0 -77
- package/cli/modules/pulls/post-pull.js +0 -69
- package/cli/modules/pulls/put-pull-labels.js +0 -77
- package/cli/modules/pulls/upload-files.js +0 -69
- package/cli/modules/pulls/upload-imgs.js +0 -69
- package/cli/modules/rank/get-language-list.js +0 -71
- package/cli/modules/rank/get-repo-annual-rank.js +0 -71
- package/cli/modules/rank/get-repo-daily-rank.js +0 -71
- package/cli/modules/rank/get-repo-monthly-rank.js +0 -71
- package/cli/modules/rank/get-repo-weekly-rank.js +0 -71
- package/cli/modules/registries/delete-package-tag.js +0 -79
- package/cli/modules/registries/delete-package.js +0 -77
- package/cli/modules/registries/delete-registry.js +0 -66
- package/cli/modules/registries/get-group-sub-registries.js +0 -75
- package/cli/modules/registries/get-package-tag-detail.js +0 -82
- package/cli/modules/registries/get-package-tag-provenance.js +0 -79
- package/cli/modules/registries/get-package.js +0 -77
- package/cli/modules/registries/list-package-tags.js +0 -80
- package/cli/modules/registries/list-packages.js +0 -76
- package/cli/modules/registries/set-registry-visibility.js +0 -75
- package/cli/modules/releases/delete-release-asset.js +0 -76
- package/cli/modules/releases/delete-release.js +0 -74
- package/cli/modules/releases/get-latest-release.js +0 -66
- package/cli/modules/releases/get-release-asset.js +0 -76
- package/cli/modules/releases/get-release-by-id.js +0 -74
- package/cli/modules/releases/get-release-by-tag.js +0 -74
- package/cli/modules/releases/get-releases-asset.js +0 -79
- package/cli/modules/releases/list-releases.js +0 -75
- package/cli/modules/releases/patch-release.js +0 -77
- package/cli/modules/releases/post-release-asset-upload-confirmation.js +0 -81
- package/cli/modules/releases/post-release-asset-upload-url.js +0 -77
- package/cli/modules/releases/post-release.js +0 -69
- package/cli/modules/repo-code-issue/get-code-issue-detail-open-api.js +0 -75
- package/cli/modules/repo-code-issue/list-code-issue-open-api.js +0 -76
- package/cli/modules/repo-contributor/get-repo-contributor-trend.js +0 -75
- package/cli/modules/repo-labels/delete-label.js +0 -74
- package/cli/modules/repo-labels/list-labels.js +0 -75
- package/cli/modules/repo-labels/patch-label.js +0 -77
- package/cli/modules/repo-labels/post-label.js +0 -69
- package/cli/modules/repositories/archive-repo.js +0 -66
- package/cli/modules/repositories/create-repo.js +0 -69
- package/cli/modules/repositories/delete-repo.js +0 -66
- package/cli/modules/repositories/get-by-id.js +0 -66
- package/cli/modules/repositories/get-group-sub-repos.js +0 -75
- package/cli/modules/repositories/get-pinned-repo-by-group.js +0 -66
- package/cli/modules/repositories/get-pinned-repo-by-id.js +0 -66
- package/cli/modules/repositories/get-repos-by-user-name.js +0 -75
- package/cli/modules/repositories/get-repos.js +0 -71
- package/cli/modules/repositories/list-forks-repos.js +0 -75
- package/cli/modules/repositories/set-pinned-repo-by-group.js +0 -69
- package/cli/modules/repositories/set-repo-visibility.js +0 -75
- package/cli/modules/repositories/transfer-repo.js +0 -69
- package/cli/modules/repositories/un-archive-repo.js +0 -66
- package/cli/modules/repositories/update-repo.js +0 -69
- package/cli/modules/search/list-public-repos.js +0 -71
- package/cli/modules/security/get-repo-security-overview.js +0 -75
- package/cli/modules/starring/get-user-all-stared-repos.js +0 -71
- package/cli/modules/starring/get-user-stared-repos.js +0 -75
- package/cli/modules/starring/list-star-users.js +0 -75
- package/cli/modules/users/auto-complete-source.js +0 -71
- package/cli/modules/users/get-user-info-by-name.js +0 -66
- package/cli/modules/users/get-user-info.js +0 -62
- package/cli/modules/users/list-email.js +0 -62
- package/cli/modules/users/list-gpg-keys.js +0 -71
- package/cli/modules/users/update-user-info.js +0 -65
- package/cli/modules/workspace/delete-workspace.js +0 -65
- package/cli/modules/workspace/get-workspace-detail.js +0 -74
- package/cli/modules/workspace/list-workspaces.js +0 -71
- package/cli/modules/workspace/start-workspace.js +0 -69
- package/cli/modules/workspace/workspace-stop.js +0 -65
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.summarizeResponse = summarizeResponse;
|
|
7
|
-
/**
|
|
8
|
-
* 摘要输出
|
|
9
|
-
* 对返回数据量大的快捷命令,默认只输出核心字段,减少 token 消耗
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 摘要提取器配置
|
|
14
|
-
* key: "module/tool",value: 摘要提取函数
|
|
15
|
-
* - 对象响应:直接对 data 应用提取函数
|
|
16
|
-
* - 数组响应:对 data 中每个元素应用提取函数
|
|
17
|
-
*/
|
|
18
|
-
const SUMMARY_EXTRACTORS = {
|
|
19
|
-
// Issue 详情摘要:保留标题、状态、标签和正文
|
|
20
|
-
// 过滤: number, state_reason, assignees, author, created_at, updated_at 等
|
|
21
|
-
'issues/get-issue': item => ({
|
|
22
|
-
title: item.title,
|
|
23
|
-
state: item.state,
|
|
24
|
-
labels: item.labels?.map?.(l => l.name).filter(Boolean) || [],
|
|
25
|
-
body: item.body
|
|
26
|
-
}),
|
|
27
|
-
// Issue 更新摘要:只保留状态变更结果
|
|
28
|
-
// 过滤: title, body, labels, assignees, author, created_at, updated_at 等
|
|
29
|
-
'issues/update-issue': item => ({
|
|
30
|
-
number: item.number,
|
|
31
|
-
state: item.state,
|
|
32
|
-
state_reason: item.state_reason
|
|
33
|
-
}),
|
|
34
|
-
// Issue 评论列表摘要:只保留作者用户名、内容和创建时间
|
|
35
|
-
// 过滤: author 完整对象(avatar/email/freeze/is_npc/nickname), reactions, updated_at
|
|
36
|
-
'issues/list-issue-comments': item => ({
|
|
37
|
-
id: item.id,
|
|
38
|
-
author: item.author?.username,
|
|
39
|
-
body: item.body,
|
|
40
|
-
created_at: item.created_at
|
|
41
|
-
}),
|
|
42
|
-
// Issue 发表评论摘要:只保留评论 ID 和创建时间(body 已在请求中传入,无需重复)
|
|
43
|
-
// 过滤: body(请求已传入), author 完整对象(avatar/email/freeze/is_npc/nickname/username), reactions, updated_at
|
|
44
|
-
'issues/post-issue-comment': item => ({
|
|
45
|
-
id: item.id,
|
|
46
|
-
created_at: item.created_at
|
|
47
|
-
}),
|
|
48
|
-
// Issue 标签列表摘要:保留名称、颜色和描述
|
|
49
|
-
// 过滤: id
|
|
50
|
-
'issues/list-issue-labels': item => ({
|
|
51
|
-
name: item.name,
|
|
52
|
-
color: item.color,
|
|
53
|
-
description: item.description
|
|
54
|
-
}),
|
|
55
|
-
// Issue 添加标签摘要:只保留 ID 和颜色(name 已在请求中传入,无需重复)
|
|
56
|
-
// 过滤: name(请求已传入), description
|
|
57
|
-
'issues/post-issue-labels': item => ({
|
|
58
|
-
id: item.id,
|
|
59
|
-
color: item.color
|
|
60
|
-
}),
|
|
61
|
-
// Issue 处理人列表摘要:保留用户名和昵称
|
|
62
|
-
// 过滤: avatar, email, freeze, is_npc
|
|
63
|
-
'issues/list-issue-assignees': item => ({
|
|
64
|
-
username: item.username,
|
|
65
|
-
nickname: item.nickname
|
|
66
|
-
}),
|
|
67
|
-
// Issue 添加处理人摘要:保留处理人用户名和昵称列表
|
|
68
|
-
// 过滤: assignees 中每个用户的 avatar/email/freeze/is_npc,以及 issue 其他字段
|
|
69
|
-
'issues/post-issue-assignees': item => ({
|
|
70
|
-
number: item.number,
|
|
71
|
-
assignees: item.assignees?.map?.(a => ({
|
|
72
|
-
username: a.username,
|
|
73
|
-
nickname: a.nickname
|
|
74
|
-
})).filter(a => a.username) || []
|
|
75
|
-
}),
|
|
76
|
-
// PR 详情摘要:保留标题、状态、标签、正文和分支信息
|
|
77
|
-
// 过滤: number, author, assignees, reviewers, created_at, updated_at, base/head 完整对象等
|
|
78
|
-
'pulls/get-pull': item => ({
|
|
79
|
-
title: item.title,
|
|
80
|
-
state: item.state,
|
|
81
|
-
labels: item.labels?.map?.(l => l.name).filter(Boolean) || [],
|
|
82
|
-
base: item.base?.ref,
|
|
83
|
-
head: item.head?.ref,
|
|
84
|
-
body: item.body
|
|
85
|
-
}),
|
|
86
|
-
// PR 文件列表摘要:保留文件名、sha、变更状态和增删行数
|
|
87
|
-
// 过滤: patch, blob_url, raw_url, contents_url, previous_filename
|
|
88
|
-
'pulls/list-pull-files': item => ({
|
|
89
|
-
filename: item.filename,
|
|
90
|
-
sha: item.sha,
|
|
91
|
-
status: item.status,
|
|
92
|
-
additions: item.additions,
|
|
93
|
-
deletions: item.deletions
|
|
94
|
-
}),
|
|
95
|
-
// PR 提交列表摘要:只保留 sha 前 8 位和 commit message
|
|
96
|
-
// 过滤: sha 完整值, commit 完整对象(author/committer/tree/verification), parents, url 等
|
|
97
|
-
'pulls/list-pull-commits': item => ({
|
|
98
|
-
sha: typeof item.sha === 'string' ? item.sha.substring(0, 8) : item.sha,
|
|
99
|
-
message: item.commit?.message
|
|
100
|
-
}),
|
|
101
|
-
// PR 评论列表摘要:保留作者用户名和昵称、内容和创建时间
|
|
102
|
-
// 过滤: author 完整对象(avatar/email/freeze/is_npc), reactions, updated_at
|
|
103
|
-
'pulls/list-pull-comments': item => ({
|
|
104
|
-
id: item.id,
|
|
105
|
-
author: item.author?.username,
|
|
106
|
-
nickname: item.author?.nickname,
|
|
107
|
-
body: item.body,
|
|
108
|
-
created_at: item.created_at
|
|
109
|
-
}),
|
|
110
|
-
// PR 发表评论摘要:只保留评论 ID 和创建时间(body 已在请求中传入,无需重复)
|
|
111
|
-
// 过滤: body(请求已传入), author 完整对象(avatar/email/freeze/is_npc/nickname/username), reactions, updated_at
|
|
112
|
-
'pulls/post-pull-comment': item => ({
|
|
113
|
-
id: item.id,
|
|
114
|
-
created_at: item.created_at
|
|
115
|
-
}),
|
|
116
|
-
// PR 标签列表摘要:保留 ID、名称、颜色和描述
|
|
117
|
-
// 过滤: 无
|
|
118
|
-
'pulls/list-pull-labels': item => ({
|
|
119
|
-
id: item.id,
|
|
120
|
-
name: item.name,
|
|
121
|
-
color: item.color,
|
|
122
|
-
description: item.description
|
|
123
|
-
}),
|
|
124
|
-
// PR 添加标签摘要:只保留 ID 和颜色(name 已在请求中传入,无需重复)
|
|
125
|
-
// 过滤: name(请求已传入), description
|
|
126
|
-
'pulls/post-pull-labels': item => ({
|
|
127
|
-
id: item.id,
|
|
128
|
-
color: item.color
|
|
129
|
-
}),
|
|
130
|
-
// PR CI 状态摘要:保留整体状态和各检查项的核心信息(sha 截断为前 8 位)
|
|
131
|
-
// 过滤: sha 完整值, statuses 中每项的 target_url/created_at/updated_at
|
|
132
|
-
'pulls/list-pull-commit-statuses': item => ({
|
|
133
|
-
sha: typeof item.sha === 'string' ? item.sha.substring(0, 8) : item.sha,
|
|
134
|
-
state: item.state,
|
|
135
|
-
statuses: item.statuses?.map?.(s => ({
|
|
136
|
-
context: s.context,
|
|
137
|
-
state: s.state,
|
|
138
|
-
description: s.description
|
|
139
|
-
})) || []
|
|
140
|
-
}),
|
|
141
|
-
// PR 评审列表摘要:保留作者用户名和昵称、状态和内容
|
|
142
|
-
// 过滤: author 完整对象(avatar/email/freeze/is_npc), created_at, updated_at
|
|
143
|
-
'pulls/list-pull-reviews': item => ({
|
|
144
|
-
id: item.id,
|
|
145
|
-
author: item.author?.username,
|
|
146
|
-
nickname: item.author?.nickname,
|
|
147
|
-
state: item.state,
|
|
148
|
-
body: item.body
|
|
149
|
-
}),
|
|
150
|
-
// PR 处理人列表摘要:保留用户名和昵称
|
|
151
|
-
// 过滤: avatar, email, freeze, is_npc
|
|
152
|
-
'pulls/list-pull-assignees': item => ({
|
|
153
|
-
username: item.username,
|
|
154
|
-
nickname: item.nickname
|
|
155
|
-
}),
|
|
156
|
-
// PR 添加处理人摘要:保留处理人用户名和昵称列表
|
|
157
|
-
// 过滤: assignees 中每个用户的 avatar/email/freeze/is_npc,以及 PR 其他字段
|
|
158
|
-
'pulls/post-pull-assignees': item => ({
|
|
159
|
-
number: item.number,
|
|
160
|
-
assignees: item.assignees?.map?.(a => ({
|
|
161
|
-
username: a.username,
|
|
162
|
-
nickname: a.nickname
|
|
163
|
-
})).filter(a => a.username) || []
|
|
164
|
-
})
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 对响应数据应用摘要提取(如果当前 tool 配置了摘要提取器)
|
|
169
|
-
* @param data 原始 data(对象或数组)
|
|
170
|
-
* @param toolKey 当前 tool 标识,格式为 "module/tool"
|
|
171
|
-
* @returns 摘要后的 data,如果无匹配提取器则返回 null
|
|
172
|
-
*/
|
|
173
|
-
function summarizeResponse(data, toolKey) {
|
|
174
|
-
const extractor = SUMMARY_EXTRACTORS[toolKey];
|
|
175
|
-
if (!extractor) return null;
|
|
176
|
-
if (data == null) return data;
|
|
177
|
-
if (Array.isArray(data)) {
|
|
178
|
-
return data.map(extractor);
|
|
179
|
-
}
|
|
180
|
-
return extractor(data);
|
|
181
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.trimSummary = trimSummary;
|
|
7
|
-
/**
|
|
8
|
-
* 去除 summary 中的英文部分(保留中文句号前的内容)
|
|
9
|
-
*/
|
|
10
|
-
function trimSummary(summary) {
|
|
11
|
-
if (!summary) return '';
|
|
12
|
-
// 匹配中文句号"。"后面跟英文的模式,只保留中文部分
|
|
13
|
-
const match = summary.match(/^(.*?[\u4e00-\u9fff].*?)[。.]\s*[A-Z]/);
|
|
14
|
-
if (match) return match[1];
|
|
15
|
-
// 没有匹配到则返回原文
|
|
16
|
-
return summary;
|
|
17
|
-
}
|
package/cli/core/shortcuts.js
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PR_SHORTCUTS = exports.ISSUE_SHORTCUTS = void 0;
|
|
7
|
-
exports.detectEventContext = detectEventContext;
|
|
8
|
-
exports.resolveShortcut = resolveShortcut;
|
|
9
|
-
exports.showShort = showShort;
|
|
10
|
-
/**
|
|
11
|
-
* 快捷命令模块
|
|
12
|
-
*
|
|
13
|
-
* 根据 CNB 环境变量自动检测当前事件类型(Issue / PR),
|
|
14
|
-
* 提供场景化的快捷命令,自动从环境变量注入 path 参数。
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// ============================================================
|
|
18
|
-
// 类型定义
|
|
19
|
-
// ============================================================
|
|
20
|
-
|
|
21
|
-
// ============================================================
|
|
22
|
-
// 环境变量检测
|
|
23
|
-
// ============================================================
|
|
24
|
-
|
|
25
|
-
function detectEventContext() {
|
|
26
|
-
if (process.env.CNB_ISSUE_IID) return 'issue';
|
|
27
|
-
if (process.env.CNB_PULL_REQUEST_IID) return 'pull_request';
|
|
28
|
-
return 'unknown';
|
|
29
|
-
}
|
|
30
|
-
function getRepo() {
|
|
31
|
-
return process.env.CNB_REPO_SLUG || '<CNB_REPO_SLUG>';
|
|
32
|
-
}
|
|
33
|
-
function getIssueNumber() {
|
|
34
|
-
return process.env.CNB_ISSUE_IID || '<CNB_ISSUE_IID>';
|
|
35
|
-
}
|
|
36
|
-
function getPRNumber() {
|
|
37
|
-
return process.env.CNB_PULL_REQUEST_IID || '<CNB_PULL_REQUEST_IID>';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ============================================================
|
|
41
|
-
// 快捷命令定义
|
|
42
|
-
// ============================================================
|
|
43
|
-
|
|
44
|
-
const ISSUE_SHORTCUTS = exports.ISSUE_SHORTCUTS = [{
|
|
45
|
-
shortName: 'get',
|
|
46
|
-
realTool: 'get-issue',
|
|
47
|
-
description: '获取详情'
|
|
48
|
-
}, {
|
|
49
|
-
shortName: 'list-comments',
|
|
50
|
-
realTool: 'list-issue-comments',
|
|
51
|
-
description: '获取评论列表'
|
|
52
|
-
}, {
|
|
53
|
-
shortName: 'comment',
|
|
54
|
-
realTool: 'post-issue-comment',
|
|
55
|
-
description: '评论',
|
|
56
|
-
dataTip: "--body 内容"
|
|
57
|
-
}, {
|
|
58
|
-
shortName: 'close',
|
|
59
|
-
realTool: 'update-issue',
|
|
60
|
-
description: '关闭',
|
|
61
|
-
autoData: {
|
|
62
|
-
state: 'closed',
|
|
63
|
-
state_reason: 'completed'
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
shortName: 'open',
|
|
67
|
-
realTool: 'update-issue',
|
|
68
|
-
description: '打开',
|
|
69
|
-
autoData: {
|
|
70
|
-
state: 'open',
|
|
71
|
-
state_reason: 'reopened'
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
shortName: 'list-labels',
|
|
75
|
-
realTool: 'list-issue-labels',
|
|
76
|
-
description: '查看标签'
|
|
77
|
-
}, {
|
|
78
|
-
shortName: 'add-labels',
|
|
79
|
-
realTool: 'post-issue-labels',
|
|
80
|
-
description: '添加标签',
|
|
81
|
-
dataTip: "--labels bug --labels feature"
|
|
82
|
-
}, {
|
|
83
|
-
shortName: 'list-assignees',
|
|
84
|
-
realTool: 'list-issue-assignees',
|
|
85
|
-
description: '查看处理人'
|
|
86
|
-
}, {
|
|
87
|
-
shortName: 'add-assignees',
|
|
88
|
-
realTool: 'post-issue-assignees',
|
|
89
|
-
description: '添加处理人',
|
|
90
|
-
dataTip: "--assignees username"
|
|
91
|
-
}, {
|
|
92
|
-
shortName: 'upload-file',
|
|
93
|
-
realTool: 'post-issue-file-asset-upload-url',
|
|
94
|
-
description: '上传文件',
|
|
95
|
-
upload: true,
|
|
96
|
-
dataTip: "--file 文件路径"
|
|
97
|
-
}, {
|
|
98
|
-
shortName: 'upload-image',
|
|
99
|
-
realTool: 'post-issue-image-asset-upload-url',
|
|
100
|
-
description: '上传图片',
|
|
101
|
-
upload: true,
|
|
102
|
-
dataTip: "--file 图片路径"
|
|
103
|
-
}];
|
|
104
|
-
const PR_SHORTCUTS = exports.PR_SHORTCUTS = [{
|
|
105
|
-
shortName: 'get',
|
|
106
|
-
realTool: 'get-pull',
|
|
107
|
-
description: '获取详情'
|
|
108
|
-
}, {
|
|
109
|
-
shortName: 'list-files',
|
|
110
|
-
realTool: 'list-pull-files',
|
|
111
|
-
description: '获取文件变更'
|
|
112
|
-
}, {
|
|
113
|
-
shortName: 'list-commits',
|
|
114
|
-
realTool: 'list-pull-commits',
|
|
115
|
-
description: '获取提交记录'
|
|
116
|
-
}, {
|
|
117
|
-
shortName: 'list-comments',
|
|
118
|
-
realTool: 'list-pull-comments',
|
|
119
|
-
description: '获取评论列表'
|
|
120
|
-
}, {
|
|
121
|
-
shortName: 'comment',
|
|
122
|
-
realTool: 'post-pull-comment',
|
|
123
|
-
description: '评论',
|
|
124
|
-
dataTip: "--body 内容"
|
|
125
|
-
}, {
|
|
126
|
-
shortName: 'list-labels',
|
|
127
|
-
realTool: 'list-pull-labels',
|
|
128
|
-
description: '查看标签'
|
|
129
|
-
}, {
|
|
130
|
-
shortName: 'add-labels',
|
|
131
|
-
realTool: 'post-pull-labels',
|
|
132
|
-
description: '添加标签',
|
|
133
|
-
dataTip: "--labels ready --labels approved"
|
|
134
|
-
}, {
|
|
135
|
-
shortName: 'check-status',
|
|
136
|
-
realTool: 'list-pull-commit-statuses',
|
|
137
|
-
description: '查看 CI 状态'
|
|
138
|
-
}, {
|
|
139
|
-
shortName: 'list-reviews',
|
|
140
|
-
realTool: 'list-pull-reviews',
|
|
141
|
-
description: '查看评审列表'
|
|
142
|
-
}, {
|
|
143
|
-
shortName: 'list-assignees',
|
|
144
|
-
realTool: 'list-pull-assignees',
|
|
145
|
-
description: '查看处理人'
|
|
146
|
-
}, {
|
|
147
|
-
shortName: 'upload-file',
|
|
148
|
-
realTool: 'upload-files',
|
|
149
|
-
description: '上传文件',
|
|
150
|
-
repoOnly: true,
|
|
151
|
-
upload: true,
|
|
152
|
-
dataTip: "--file 文件路径"
|
|
153
|
-
}, {
|
|
154
|
-
shortName: 'upload-image',
|
|
155
|
-
realTool: 'upload-imgs',
|
|
156
|
-
description: '上传图片',
|
|
157
|
-
repoOnly: true,
|
|
158
|
-
upload: true,
|
|
159
|
-
dataTip: "--file 图片路径"
|
|
160
|
-
}];
|
|
161
|
-
|
|
162
|
-
// ============================================================
|
|
163
|
-
// --short 帮助输出
|
|
164
|
-
// ============================================================
|
|
165
|
-
|
|
166
|
-
/** 计算字符串的显示宽度(中文/全角占2,英文/半角占1) */
|
|
167
|
-
function displayWidth(str) {
|
|
168
|
-
let width = 0;
|
|
169
|
-
for (const ch of str) {
|
|
170
|
-
const code = ch.codePointAt(0) || 0;
|
|
171
|
-
// CJK、全角字符占2宽度
|
|
172
|
-
width += code >= 0x1100 && (code <= 0x115f || code === 0x2329 || code === 0x232a || code >= 0x2e80 && code <= 0x3247 || code >= 0x3250 && code <= 0x4dbf || code >= 0x4e00 && code <= 0xa4c6 || code >= 0xa960 && code <= 0xa97c || code >= 0xac00 && code <= 0xd7a3 || code >= 0xf900 && code <= 0xfaff || code >= 0xfe10 && code <= 0xfe19 || code >= 0xfe30 && code <= 0xfe6b || code >= 0xff01 && code <= 0xff60 || code >= 0xffe0 && code <= 0xffe6 || code >= 0x1f000 && code <= 0x1fbff || code >= 0x20000 && code <= 0x2fffd || code >= 0x30000 && code <= 0x3fffd) ? 2 : 1;
|
|
173
|
-
}
|
|
174
|
-
return width;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** 用全角空格将字符串补齐到指定显示宽度 */
|
|
178
|
-
function padToWidth(str, targetWidth) {
|
|
179
|
-
const diff = targetWidth - displayWidth(str);
|
|
180
|
-
if (diff <= 0) return str;
|
|
181
|
-
// 每个全角空格占2宽度
|
|
182
|
-
const fullSpaces = Math.floor(diff / 2);
|
|
183
|
-
const halfSpace = diff % 2 === 1 ? ' ' : '';
|
|
184
|
-
return str + ' '.repeat(fullSpaces) + halfSpace;
|
|
185
|
-
}
|
|
186
|
-
function formatShortcutList(shortcuts, cliCmd, moduleName) {
|
|
187
|
-
const maxWidth = Math.max(...shortcuts.map(s => displayWidth(s.description)));
|
|
188
|
-
return shortcuts.map(s => {
|
|
189
|
-
const desc = padToWidth(s.description, maxWidth + 2);
|
|
190
|
-
const cmd = `${cliCmd} ${moduleName} ${s.shortName}`;
|
|
191
|
-
const dataPart = s.dataTip ? ` ${s.dataTip}` : '';
|
|
192
|
-
return ` ${desc} ${cmd}${dataPart}`;
|
|
193
|
-
}).join('\n');
|
|
194
|
-
}
|
|
195
|
-
function showShort() {
|
|
196
|
-
const ctx = detectEventContext();
|
|
197
|
-
const cliCmd = "cnb" || 'cnb';
|
|
198
|
-
const repo = getRepo();
|
|
199
|
-
if (ctx === 'issue' || ctx === 'pull_request') {
|
|
200
|
-
const isIssue = ctx === 'issue';
|
|
201
|
-
const number = isIssue ? getIssueNumber() : getPRNumber();
|
|
202
|
-
const emoji = isIssue ? '📋' : '🔀';
|
|
203
|
-
const label = isIssue ? 'Issue' : 'Pull Request';
|
|
204
|
-
const tag = isIssue ? 'Issue' : 'PR';
|
|
205
|
-
const moduleName = isIssue ? 'issues' : 'pulls';
|
|
206
|
-
const shortcuts = isIssue ? ISSUE_SHORTCUTS : PR_SHORTCUTS;
|
|
207
|
-
const envVars = isIssue ? 'CNB_REPO_SLUG 和 CNB_ISSUE_IID' : 'CNB_REPO_SLUG 和 CNB_PULL_REQUEST_IID';
|
|
208
|
-
const list = formatShortcutList(shortcuts, cliCmd, moduleName);
|
|
209
|
-
console.log(`
|
|
210
|
-
${emoji} 当前场景: ${label} 事件 (${tag} #${number})
|
|
211
|
-
仓库: ${repo}
|
|
212
|
-
|
|
213
|
-
常用快捷命令(path 参数已从环境变量自动获取):
|
|
214
|
-
${list}
|
|
215
|
-
|
|
216
|
-
提示: ${tag} 相关命令会自动使用 ${envVars}
|
|
217
|
-
默认只输出摘要信息,添加 --verbose 可输出全部信息
|
|
218
|
-
`);
|
|
219
|
-
} else {
|
|
220
|
-
const issueList = formatShortcutList(ISSUE_SHORTCUTS, cliCmd, 'issues');
|
|
221
|
-
const prList = formatShortcutList(PR_SHORTCUTS, cliCmd, 'pulls');
|
|
222
|
-
console.log(`
|
|
223
|
-
⚠️ 未检测到 Issue/PR 事件上下文
|
|
224
|
-
(CNB_ISSUE_IID 和 CNB_PULL_REQUEST_IID 均未设置)
|
|
225
|
-
|
|
226
|
-
📋 Issue 场景常用命令:
|
|
227
|
-
${issueList}
|
|
228
|
-
|
|
229
|
-
🔀 PR 场景常用命令:
|
|
230
|
-
${prList}
|
|
231
|
-
|
|
232
|
-
提示: 快捷命令可使用以下环境变量:
|
|
233
|
-
CNB_REPO_SLUG - 仓库路径
|
|
234
|
-
CNB_ISSUE_IID - Issue 编号(Issue 相关快捷命令)
|
|
235
|
-
CNB_PULL_REQUEST_IID - PR 编号(PR 相关快捷命令)
|
|
236
|
-
|
|
237
|
-
默认只输出摘要信息,添加 --v 可输出全部信息
|
|
238
|
-
`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// ============================================================
|
|
243
|
-
// 快捷命令解析
|
|
244
|
-
// ============================================================
|
|
245
|
-
|
|
246
|
-
function buildAutoPath(moduleName, repoOnly) {
|
|
247
|
-
const repo = process.env.CNB_REPO_SLUG || '';
|
|
248
|
-
if (repoOnly) return {
|
|
249
|
-
repo
|
|
250
|
-
};
|
|
251
|
-
const number = moduleName === 'issues' ? process.env.CNB_ISSUE_IID || '' : process.env.CNB_PULL_REQUEST_IID || '';
|
|
252
|
-
return {
|
|
253
|
-
repo,
|
|
254
|
-
number
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* 尝试将用户输入的 module + tool 解析为快捷命令
|
|
260
|
-
*
|
|
261
|
-
* @returns 解析结果,如果不是快捷命令则返回 null
|
|
262
|
-
*/
|
|
263
|
-
function resolveShortcut(moduleName, toolName) {
|
|
264
|
-
if (!moduleName || !toolName) return null;
|
|
265
|
-
const shortcuts = moduleName === 'issues' ? ISSUE_SHORTCUTS : moduleName === 'pulls' ? PR_SHORTCUTS : null;
|
|
266
|
-
if (!shortcuts) return null;
|
|
267
|
-
const matched = shortcuts.find(s => s.shortName === toolName);
|
|
268
|
-
if (!matched) return null;
|
|
269
|
-
return {
|
|
270
|
-
module: moduleName,
|
|
271
|
-
tool: matched.realTool,
|
|
272
|
-
autoPath: buildAutoPath(moduleName, !!matched.repoOnly),
|
|
273
|
-
autoData: matched.autoData || null,
|
|
274
|
-
upload: !!matched.upload
|
|
275
|
-
};
|
|
276
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.buildNestedFieldMap = buildNestedFieldMap;
|
|
7
|
-
/**
|
|
8
|
-
* 递归遍历嵌套对象的 schema,生成所有叶子节点的 flat key 映射
|
|
9
|
-
* @param props 当前层级的 properties
|
|
10
|
-
* @param prefix 当前层级的 CLI flat key 前缀(用 @ 连接),如 "testBody"
|
|
11
|
-
* @param pathKeys 当前层级的 schema 路径数组,如 ["testBody"]
|
|
12
|
-
* @returns Map<flatKey, NestedFieldMapping>
|
|
13
|
-
*/
|
|
14
|
-
function buildNestedFieldMap(props, prefix, pathKeys) {
|
|
15
|
-
const map = new Map();
|
|
16
|
-
for (const [subKey, subProp] of Object.entries(props)) {
|
|
17
|
-
const flatKey = `${prefix}@${subKey}`;
|
|
18
|
-
const currentPath = [...pathKeys, subKey];
|
|
19
|
-
if (subProp.type === 'object' && subProp.properties && Object.keys(subProp.properties).length > 0) {
|
|
20
|
-
// 嵌套对象:继续递归
|
|
21
|
-
const subMap = buildNestedFieldMap(subProp.properties, flatKey, currentPath);
|
|
22
|
-
for (const [k, v] of subMap) {
|
|
23
|
-
map.set(k, v);
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
// 叶子节点:注册 flat key
|
|
27
|
-
const camelKey = flatKey;
|
|
28
|
-
map.set(camelKey, {
|
|
29
|
-
pathKeys: currentPath,
|
|
30
|
-
leafSchema: subProp
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return map;
|
|
35
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = convertLink;
|
|
7
|
-
/**
|
|
8
|
-
* 把文本里的相对路径转换为绝对路径
|
|
9
|
-
* 与 src/helpers/convertLink.ts 逻辑一致
|
|
10
|
-
*
|
|
11
|
-
* @param {String} text 待转换的文本
|
|
12
|
-
* @param {String} repoSlug 仓库路径
|
|
13
|
-
* @param {String} branchOrSha 可选,分支或SHA
|
|
14
|
-
* @returns {String}
|
|
15
|
-
*/
|
|
16
|
-
function convertLink(text, repoSlug, branchOrSha) {
|
|
17
|
-
// 查询所有代码块的位置
|
|
18
|
-
let codeBlockPositions = [];
|
|
19
|
-
let index = 0;
|
|
20
|
-
while (index !== -1) {
|
|
21
|
-
const nextIndex = text.indexOf('```', index);
|
|
22
|
-
if (nextIndex === -1) break;
|
|
23
|
-
codeBlockPositions.push(nextIndex);
|
|
24
|
-
index = nextIndex + 3; // 跳过已匹配的三个反引号
|
|
25
|
-
}
|
|
26
|
-
if (codeBlockPositions.length % 2 !== 0) {
|
|
27
|
-
codeBlockPositions = codeBlockPositions.slice(0, codeBlockPositions.length - 1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 查询所有行内代码块的位置
|
|
31
|
-
let inlineCodeBlockPositions = [];
|
|
32
|
-
index = 0;
|
|
33
|
-
while (index < text.length) {
|
|
34
|
-
const nextIndex = text.indexOf('`', index);
|
|
35
|
-
if (nextIndex === -1) break;
|
|
36
|
-
// 检查是否是单独的反引号(不是代码块的一部分)
|
|
37
|
-
if ((nextIndex === 0 || text.charAt(nextIndex - 1) !== '`') && (nextIndex === text.length - 1 || text.charAt(nextIndex + 1) !== '`')) {
|
|
38
|
-
inlineCodeBlockPositions.push(nextIndex);
|
|
39
|
-
}
|
|
40
|
-
index = nextIndex + 1;
|
|
41
|
-
}
|
|
42
|
-
if (inlineCodeBlockPositions.length % 2 !== 0) {
|
|
43
|
-
inlineCodeBlockPositions = inlineCodeBlockPositions.slice(0, inlineCodeBlockPositions.length - 1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 整理起始和结束位置
|
|
47
|
-
const excludedRanges = [...codeBlockPositions, ...inlineCodeBlockPositions].reduce((result, item, index) => {
|
|
48
|
-
if (index % 2 === 0) {
|
|
49
|
-
return result.concat([[item]]);
|
|
50
|
-
} else {
|
|
51
|
-
result[result.length - 1].push(item);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
|
-
// Helper function to check if an index is within excluded ranges
|
|
57
|
-
const isInExcludedRange = index => {
|
|
58
|
-
return excludedRanges.some(([start, end]) => index >= start && index < end);
|
|
59
|
-
};
|
|
60
|
-
let match;
|
|
61
|
-
|
|
62
|
-
// Collect all replacements with their positions
|
|
63
|
-
const replacements = [];
|
|
64
|
-
|
|
65
|
-
// Match markdown links and images: [alt](url), [](url),  and 
|
|
66
|
-
const markdownLinkRegex = /!?\[([^\]]*)\]\(([^)]+)\)/g;
|
|
67
|
-
while ((match = markdownLinkRegex.exec(text)) !== null) {
|
|
68
|
-
if (!isInExcludedRange(match.index)) {
|
|
69
|
-
// Calculate URL position: match.index + length of "![" + match[1] + "]("
|
|
70
|
-
const prefixLength = (match[0].startsWith('!') ? 1 : 0) + 1 + match[1].length + 2;
|
|
71
|
-
const urlStart = match.index + prefixLength;
|
|
72
|
-
const urlEnd = urlStart + match[2].length;
|
|
73
|
-
const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
|
|
74
|
-
if (newUrl !== match[2]) {
|
|
75
|
-
replacements.push({
|
|
76
|
-
start: urlStart,
|
|
77
|
-
end: urlEnd,
|
|
78
|
-
newUrl
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Match HTML tags: <img src="..."> and <a href="...">
|
|
85
|
-
const htmlTagRegex = /\s(src|href)=["']([^"']+)["']/gi;
|
|
86
|
-
while ((match = htmlTagRegex.exec(text)) !== null) {
|
|
87
|
-
if (!isInExcludedRange(match.index)) {
|
|
88
|
-
const urlStart = match.index + match[0].indexOf(match[2]);
|
|
89
|
-
const urlEnd = urlStart + match[2].length;
|
|
90
|
-
const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
|
|
91
|
-
if (newUrl !== match[2]) {
|
|
92
|
-
replacements.push({
|
|
93
|
-
start: urlStart,
|
|
94
|
-
end: urlEnd,
|
|
95
|
-
newUrl
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Sort replacements by start position in descending order
|
|
102
|
-
replacements.sort((a, b) => b.start - a.start);
|
|
103
|
-
|
|
104
|
-
// Apply replacements from end to start to maintain correct indices
|
|
105
|
-
let result = text;
|
|
106
|
-
for (const {
|
|
107
|
-
start,
|
|
108
|
-
end,
|
|
109
|
-
newUrl
|
|
110
|
-
} of replacements) {
|
|
111
|
-
result = result.substring(0, start) + newUrl + result.substring(end);
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 相对路径转换为绝对路径
|
|
118
|
-
* 与 src/helpers/convertLink.ts 逻辑一致
|
|
119
|
-
*
|
|
120
|
-
* @param {String} link 待转换的链接
|
|
121
|
-
* @param {String} repoSlug 仓库路径
|
|
122
|
-
* @param {String} branchOrSha 分支或SHA,默认为 HEAD
|
|
123
|
-
* @returns {String}
|
|
124
|
-
*/
|
|
125
|
-
function normaliseLink(link, repoSlug, branchOrSha = 'HEAD') {
|
|
126
|
-
const {
|
|
127
|
-
CNB_WEB_ENDPOINT
|
|
128
|
-
} = process.env;
|
|
129
|
-
const baseURL = `${CNB_WEB_ENDPOINT}/${repoSlug}`;
|
|
130
|
-
if (link.startsWith('/-/')) {
|
|
131
|
-
return `${baseURL}${link}`;
|
|
132
|
-
}
|
|
133
|
-
if (link.indexOf('/-/') === -1 && (link.startsWith('../') || link.startsWith('./') || link.startsWith('/') && !link.startsWith('//'))) {
|
|
134
|
-
let chunks = link.split('/');
|
|
135
|
-
// 过滤掉空字符串和 . .. 这些无效路径
|
|
136
|
-
chunks = chunks.filter(chunk => !!chunk && chunk !== '.' && chunk !== '..');
|
|
137
|
-
if (chunks.length === 0) {
|
|
138
|
-
return link;
|
|
139
|
-
}
|
|
140
|
-
chunks.unshift(branchOrSha);
|
|
141
|
-
return `${baseURL}/-/git/raw/${chunks.join('/')}`;
|
|
142
|
-
}
|
|
143
|
-
return link;
|
|
144
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.flatKeyFromSegments = flatKeyFromSegments;
|
|
7
|
-
/**
|
|
8
|
-
* 生成 CLI flat key:按 '@' 连接层级
|
|
9
|
-
* 例如 "testBody@critical_count@id"
|
|
10
|
-
* Commander 不会对 '@' 做 camelCase 转换,所以 key 保持原样
|
|
11
|
-
*/
|
|
12
|
-
function flatKeyFromSegments(str) {
|
|
13
|
-
return str;
|
|
14
|
-
}
|