plugin-git-manager 1.2.27 → 1.3.1
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/README.md +151 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/941.1793e67472872992.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +396 -297
- package/dist/locale/vi-VN.json +384 -292
- package/dist/locale/zh-CN.json +150 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review-cutover.js +137 -0
- package/dist/server/actions/review.js +150 -51
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +57 -20
- package/dist/server/poller.js +95 -74
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +76 -0
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +429 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +352 -303
- package/src/client/components/ReviewHistory.tsx +796 -566
- package/src/client/components/RunReviewButton.tsx +57 -173
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client/workflowRoutes.ts +42 -0
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +396 -297
- package/src/locale/vi-VN.json +384 -292
- package/src/locale/zh-CN.json +150 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +760 -752
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +76 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review-cutover.ts +121 -0
- package/src/server/actions/review.ts +1498 -1369
- package/src/server/actions/role-permissions.ts +331 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +334 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +218 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +120 -108
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +14 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +409 -361
- package/src/server/poller.ts +365 -352
- package/src/server/repository-access.ts +803 -773
- package/src/server/request-method-policy.ts +56 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
package/src/locale/zh-CN.json
CHANGED
|
@@ -1,51 +1,150 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Git Manager": "Git 管理器",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"Subtree
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
1
|
+
{
|
|
2
|
+
"Git Manager": "Git 管理器",
|
|
3
|
+
"Invalid merge request": "合并请求无效",
|
|
4
|
+
"Legacy review is not available": "旧审查不可用",
|
|
5
|
+
"No review content to post": "没有可发布的审查内容",
|
|
6
|
+
"Permission denied": "权限不足",
|
|
7
|
+
"Repository not found": "找不到仓库",
|
|
8
|
+
"Review cutover has not been confirmed": "尚未确认审查切换",
|
|
9
|
+
"Review is not awaiting approval": "审查不处于等待批准状态",
|
|
10
|
+
"Review not found": "找不到审查记录",
|
|
11
|
+
"Reviewed commit is unavailable": "审查的提交不可用",
|
|
12
|
+
"Review content cannot change while publication is unresolved": "发布结果未确定时不能修改审查内容",
|
|
13
|
+
"post_unknown": "发布结果未知",
|
|
14
|
+
"posting": "正在发布",
|
|
15
|
+
"retrying": "正在重试",
|
|
16
|
+
"Merge request base changed after review": "合并请求的基准在审查后发生变化",
|
|
17
|
+
"Legacy review source is invalid": "旧审查的源信息无效",
|
|
18
|
+
"Only completed legacy merge request reviews can be published": "只能发布已完成的旧合并请求审查",
|
|
19
|
+
"Legacy review is not awaiting publication recovery": "旧审查不处于等待发布恢复状态",
|
|
20
|
+
"Legacy review base requires explicit confirmation": "必须明确确认旧审查的基准",
|
|
21
|
+
"Legacy review has no publication hold": "旧审查没有发布锁定",
|
|
22
|
+
"The original review base cannot be verified. Compare the review with the current merge request before continuing.": "无法验证原始审查的基准。继续之前,请将审查内容与当前合并请求进行比较。",
|
|
23
|
+
"A matching comment was found, but its attempt cannot be confirmed": "找到匹配的评论,但无法确认它属于哪次发布尝试",
|
|
24
|
+
"A matching marked comment was found; confirm the previous attempt stopped to finalize it": "找到带标记的匹配评论;请确认上一次发布尝试已停止以完成记录",
|
|
25
|
+
"Legacy publication hold released": "已释放旧审查发布锁定",
|
|
26
|
+
"Publication outcome is still unknown": "发布结果仍未知",
|
|
27
|
+
"Release legacy publication hold": "释放旧审查发布锁定",
|
|
28
|
+
"Review branch": "审查分支",
|
|
29
|
+
"Branch": "分支",
|
|
30
|
+
"Allow Skill Registry export": "允许 Skill Registry 导出",
|
|
31
|
+
"Subtree Splits": "Subtree 拆分",
|
|
32
|
+
"Add subtree configuration": "添加 subtree 配置",
|
|
33
|
+
"Edit subtree configuration": "编辑 subtree 配置",
|
|
34
|
+
"Subtree configuration created": "已创建 subtree 配置",
|
|
35
|
+
"Subtree configuration updated": "已更新 subtree 配置",
|
|
36
|
+
"Delete this subtree configuration?": "删除此 subtree 配置?",
|
|
37
|
+
"Name": "名称",
|
|
38
|
+
"Repository": "仓库",
|
|
39
|
+
"Source": "源",
|
|
40
|
+
"Source branch": "源分支",
|
|
41
|
+
"Source folder": "源文件夹",
|
|
42
|
+
"Target branch": "目标分支",
|
|
43
|
+
"Remote name": "远程名称",
|
|
44
|
+
"Default policy": "默认策略",
|
|
45
|
+
"Push after run": "运行后推送",
|
|
46
|
+
"Enabled": "已启用",
|
|
47
|
+
"Last status": "最近状态",
|
|
48
|
+
"Actions": "操作",
|
|
49
|
+
"Run": "运行",
|
|
50
|
+
"Edit": "编辑",
|
|
51
|
+
"Delete": "删除",
|
|
52
|
+
"Deleted": "已删除",
|
|
53
|
+
"Run subtree split": "运行 subtree 拆分",
|
|
54
|
+
"Preview": "预览",
|
|
55
|
+
"Fast-forward only": "仅快进",
|
|
56
|
+
"Replace target": "替换目标分支",
|
|
57
|
+
"Merge histories": "合并历史",
|
|
58
|
+
"Replace target may discard target-only commits": "替换目标分支可能丢弃仅存在于目标分支的提交",
|
|
59
|
+
"Type the target branch name to confirm": "输入目标分支名称以确认",
|
|
60
|
+
"Push target branch after success": "成功后推送目标分支",
|
|
61
|
+
"Target branch does not exist": "目标分支不存在",
|
|
62
|
+
"Subtree split completed": "Subtree 拆分完成",
|
|
63
|
+
"Subtree relationship: target-missing": "目标分支不存在",
|
|
64
|
+
"Subtree relationship: already-up-to-date": "目标分支已是最新",
|
|
65
|
+
"Subtree relationship: fast-forward": "目标分支可以快进",
|
|
66
|
+
"Subtree relationship: diverged": "目标分支已分叉",
|
|
67
|
+
"Run history": "运行历史",
|
|
68
|
+
"Started at": "开始时间",
|
|
69
|
+
"Policy": "策略",
|
|
70
|
+
"Status": "状态",
|
|
71
|
+
"Split SHA": "拆分 SHA",
|
|
72
|
+
"Target before": "更新前目标",
|
|
73
|
+
"Target after": "更新后目标",
|
|
74
|
+
"Error": "错误",
|
|
75
|
+
"Execution mode": "执行模式",
|
|
76
|
+
"App process": "应用进程",
|
|
77
|
+
"Credential-bearing URLs are not allowed": "URL 中不允许包含用户名或凭据",
|
|
78
|
+
"Git Repository": "Git 仓库",
|
|
79
|
+
"Git Merge Request": "Git 合并请求",
|
|
80
|
+
"Git Commit": "Git 提交",
|
|
81
|
+
"Method not allowed": "不允许的请求方法",
|
|
82
|
+
"Invalid repository or account URL": "仓库或账号 URL 无效",
|
|
83
|
+
"Only HTTPS repository and account URLs are allowed": "仓库和账号 URL 只允许使用 HTTPS",
|
|
84
|
+
"Repository URL must match the Git account origin": "仓库 URL 必须与 Git 账号使用相同的协议、主机和端口",
|
|
85
|
+
"GitHub accounts currently require github.com": "GitHub 账号目前仅支持 github.com",
|
|
86
|
+
"Invalid local path": "本地路径无效",
|
|
87
|
+
"Invalid local path: path traversal detected or path is outside the allowed base directory": "本地路径无效:检测到路径穿越或路径位于允许的基础目录之外",
|
|
88
|
+
"queued": "排队中",
|
|
89
|
+
"Review new commits automatically": "自动审查新提交",
|
|
90
|
+
"Only applies to automatic merge request reviews": "仅适用于自动合并请求审查",
|
|
91
|
+
"Edit the AI employee, model and prompt in the bound workflow": "在绑定的工作流中编辑 AI 员工、模型和提示词",
|
|
92
|
+
"Reconfigure the workflow after changing post mode": "更改发布模式后请重新配置工作流",
|
|
93
|
+
"Use the workflow approval task for this review": "请使用工作流审批任务处理此审查",
|
|
94
|
+
"Open workflow": "打开工作流",
|
|
95
|
+
"Open workflow tasks": "打开工作流任务",
|
|
96
|
+
"Open workflow execution": "打开工作流执行记录",
|
|
97
|
+
"Review queued": "审查已加入队列",
|
|
98
|
+
"New commits detected. A new review will be queued.": "检测到新提交。新的审查将加入队列。",
|
|
99
|
+
"A new review will be queued and existing history will be kept.": "新的审查将加入队列,并保留现有历史记录。",
|
|
100
|
+
"Worker and AI stop confirmation is required": "必须确认工作进程和 AI 均已停止",
|
|
101
|
+
"Legacy review cancellation confirmation is required": "必须确认取消旧审查",
|
|
102
|
+
"Legacy review identifier is required": "必须提供旧审查标识",
|
|
103
|
+
"AI stop confirmation is required": "必须确认 AI 已停止",
|
|
104
|
+
"No enabled review flow found": "未找到已启用的审查流程",
|
|
105
|
+
"Source branch does not match review flow": "源分支不符合审查流程",
|
|
106
|
+
"Flow does not permit manual review": "此流程不允许手动审查",
|
|
107
|
+
"Review flow has not been bound to a workflow": "审查流程尚未绑定工作流",
|
|
108
|
+
"Review workflow setup is incomplete": "审查工作流配置尚未完成",
|
|
109
|
+
"Review workflow is not enabled": "审查工作流未启用",
|
|
110
|
+
"Review requires an authenticated actor": "审查需要经过身份验证的用户",
|
|
111
|
+
"Review actor roles are unavailable or changed": "审查用户的角色不可用或已更改",
|
|
112
|
+
"Review actor does not have repository access": "审查用户无权访问仓库",
|
|
113
|
+
"Git review workflow integration is unavailable": "Git 审查工作流集成不可用",
|
|
114
|
+
"Unable to resolve an immutable Git commit": "无法解析不可变的 Git 提交",
|
|
115
|
+
"Checkout origin is missing or unsupported": "检出仓库的 origin 不存在或不受支持",
|
|
116
|
+
"Checkout origin project could not be verified": "无法验证检出仓库的 origin 项目",
|
|
117
|
+
"Checkout origin does not match the configured project": "检出仓库的 origin 与配置的项目不匹配",
|
|
118
|
+
"Merge request head changed before review admission": "加入审查队列前合并请求的最新提交已更改",
|
|
119
|
+
"Git provider request failed ({{status}})": "Git 服务请求失败({{status}})",
|
|
120
|
+
"No configured approver can access this repository": "没有配置的审批人可以访问此仓库",
|
|
121
|
+
"Queued review cancellation confirmation is required": "必须确认取消排队中的审查",
|
|
122
|
+
"Outbound post stop confirmation is required": "必须确认之前的发布请求已停止",
|
|
123
|
+
"Review publication confirmed": "已确认审查评论发布",
|
|
124
|
+
"No matching comment found; confirm the previous post stopped before retrying": "未找到匹配的评论;重试前请确认之前的发布请求已停止",
|
|
125
|
+
"A previous publication attempt may still be running; ask an administrator to recover it": "之前的发布操作可能仍在运行,请联系管理员恢复",
|
|
126
|
+
"Failed to reconcile review publication": "无法核对审查评论发布状态",
|
|
127
|
+
"Check publication": "检查发布状态",
|
|
128
|
+
"Has the previous outbound post stopped and settled?": "之前的发布请求是否已停止并处理完毕?",
|
|
129
|
+
"Retry publication": "重试发布",
|
|
130
|
+
"Another review is active for this project": "此项目已有审查正在进行",
|
|
131
|
+
"A publication attempt may still be running": "之前的发布操作可能仍在运行",
|
|
132
|
+
"Invalid publication confirmation": "发布确认无效",
|
|
133
|
+
"Review is not settled or is no longer available": "审查尚未完成或已不可用",
|
|
134
|
+
"Review execution is not terminal": "审查执行尚未结束",
|
|
135
|
+
"Review cannot be published": "无法发布此审查",
|
|
136
|
+
"Approved review content changed": "已批准的审查内容已更改",
|
|
137
|
+
"Review approval verifier is unavailable": "审查审批验证器不可用",
|
|
138
|
+
"Review publication receipt is unavailable": "审查发布回执不可用",
|
|
139
|
+
"Review publication cannot be retried": "无法重试发布审查",
|
|
140
|
+
"Review publication state changed": "审查发布状态已更改",
|
|
141
|
+
"Merge request head changed after review": "审查后合并请求的最新提交已更改",
|
|
142
|
+
"Review comment marker is ambiguous": "审查评论标识不明确",
|
|
143
|
+
"Unable to verify Git account identity": "无法验证 Git 账号身份",
|
|
144
|
+
"Repository credentials or project changed": "仓库凭据或项目已更改",
|
|
145
|
+
"Resolve publication or reset the stopped post attempt before recovery": "恢复之前请先核对发布状态,或确认发布请求已停止后重置该请求",
|
|
146
|
+
"Refresh publication status before recovery": "恢复前请刷新发布状态",
|
|
147
|
+
"Matching comment found; another publication attempt still owns the review": "已找到匹配评论;另一个发布操作仍占用该审查",
|
|
148
|
+
"Review publication claim changed": "审查发布占用已更改;请刷新并检查当前操作",
|
|
149
|
+
"Review project reservation changed": "审查项目占用已更改"
|
|
150
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Context } from '@nocobase/actions';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { getRepo } from '../actions/git-actions';
|
|
5
|
-
|
|
6
|
-
describe('Git Manager git actions', () => {
|
|
7
|
-
it('uses the repository ID from the request body over the URL parameter', async () => {
|
|
8
|
-
const repository = { id: 20 };
|
|
9
|
-
const findOne = vi.fn().mockResolvedValue(repository);
|
|
10
|
-
const context = {
|
|
11
|
-
action: { params: { repositoryId: 10 } },
|
|
12
|
-
request: { body: { repositoryId: 20 } },
|
|
13
|
-
db: {
|
|
14
|
-
getRepository: vi.fn().mockReturnValue({ findOne }),
|
|
15
|
-
},
|
|
16
|
-
throw: vi.fn(),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const result = await getRepo(context as unknown as Context);
|
|
20
|
-
|
|
21
|
-
expect(findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
22
|
-
expect(result).toBe(repository);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { getRepo } from '../actions/git-actions';
|
|
5
|
+
|
|
6
|
+
describe('Git Manager git actions', () => {
|
|
7
|
+
it('uses the repository ID from the request body over the URL parameter', async () => {
|
|
8
|
+
const repository = { id: 20 };
|
|
9
|
+
const findOne = vi.fn().mockResolvedValue(repository);
|
|
10
|
+
const context = {
|
|
11
|
+
action: { params: { repositoryId: 10 } },
|
|
12
|
+
request: { body: { repositoryId: 20 } },
|
|
13
|
+
db: {
|
|
14
|
+
getRepository: vi.fn().mockReturnValue({ findOne }),
|
|
15
|
+
},
|
|
16
|
+
throw: vi.fn(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const result = await getRepo(context as unknown as Context);
|
|
20
|
+
|
|
21
|
+
expect(findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
22
|
+
expect(result).toBe(repository);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execFileSync } from 'child_process';
|
|
11
|
+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, symlinkSync, unlinkSync } from 'fs';
|
|
12
|
+
import { tmpdir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import type { Context } from '@nocobase/actions';
|
|
15
|
+
import type { SimpleGit } from 'simple-git';
|
|
16
|
+
import { createGit, credentialEnvironment, validateLocalPath, withAuth } from '../actions/git-actions';
|
|
17
|
+
import { mergeRequests } from '../actions/gitlab-api';
|
|
18
|
+
import { getRepoAccount } from '../utils/get-repo-account';
|
|
19
|
+
|
|
20
|
+
const repoUrl = 'https://trusted.invalid/team/project.git';
|
|
21
|
+
const fakePat = 'test-only-secret';
|
|
22
|
+
const record = (values: Record<string, unknown>) => ({ get: (key: string) => values[key] });
|
|
23
|
+
|
|
24
|
+
function database(url = repoUrl, baseUrl: string | null = 'https://trusted.invalid', provider = 'gitlab') {
|
|
25
|
+
const repo = record({ gitAccountId: 1, repoUrl: url });
|
|
26
|
+
return {
|
|
27
|
+
repo,
|
|
28
|
+
db: {
|
|
29
|
+
getRepository: (name: string) => ({
|
|
30
|
+
findOne: async () => (name === 'gitAccounts' ? record({ baseUrl, provider, pat: fakePat }) : repo),
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('Git credential destination', () => {
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.unstubAllGlobals();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it.each([
|
|
42
|
+
['https://different.invalid/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
43
|
+
['http://trusted.invalid/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
44
|
+
['https://trusted.invalid:444/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
45
|
+
['https://selfhost.invalid/team/r', null, 'gitlab'],
|
|
46
|
+
['https://enterprise.invalid/team/r', 'https://enterprise.invalid', 'github'],
|
|
47
|
+
])('rejects an untrusted credential destination %s', async (url, baseUrl, provider) => {
|
|
48
|
+
const { db, repo } = database(url, baseUrl, provider);
|
|
49
|
+
await expect(getRepoAccount(db, repo)).rejects.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each([
|
|
53
|
+
[repoUrl, 'https://trusted.invalid', 'gitlab'],
|
|
54
|
+
['https://gitlab.com/team/r', null, 'gitlab'],
|
|
55
|
+
['https://github.com/team/r', null, 'github'],
|
|
56
|
+
])('accepts an explicitly bound or public default origin %s', async (url, baseUrl, provider) => {
|
|
57
|
+
const { db, repo } = database(url, baseUrl, provider);
|
|
58
|
+
await expect(getRepoAccount(db, repo)).resolves.toMatchObject({ pat: fakePat });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('blocks the API request before sending a token to a mismatched repository host', async () => {
|
|
62
|
+
const fetchMock = vi.fn();
|
|
63
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
64
|
+
const { db } = database('https://different.invalid/team/r');
|
|
65
|
+
await expect(
|
|
66
|
+
mergeRequests({ db, action: { params: { repositoryId: 1 } } } as unknown as Context, async () => {}),
|
|
67
|
+
).rejects.toThrow('Repository URL must match');
|
|
68
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it.each([
|
|
72
|
+
[repoUrl, 'https://trusted.invalid', 'gitlab'],
|
|
73
|
+
['https://github.com/team/r', null, 'github'],
|
|
74
|
+
])('disables redirects for authenticated provider API requests', async (url, baseUrl, provider) => {
|
|
75
|
+
const fetchMock = vi.fn().mockResolvedValue({ ok: true, headers: new Headers(), json: async () => [] });
|
|
76
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
77
|
+
const { db } = database(url, baseUrl, provider);
|
|
78
|
+
await mergeRequests({ db, action: { params: { repositoryId: 1 } } } as unknown as Context, async () => {});
|
|
79
|
+
expect(fetchMock).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ redirect: 'error' }));
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('Git filesystem and process credentials', () => {
|
|
84
|
+
let fixture: string;
|
|
85
|
+
let base: string;
|
|
86
|
+
const originalBase = process.env.GIT_REPOS_BASE_PATH;
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
fixture = mkdtempSync(join(tmpdir(), 'git-manager-security-'));
|
|
90
|
+
base = join(fixture, 'base');
|
|
91
|
+
mkdirSync(base);
|
|
92
|
+
process.env.GIT_REPOS_BASE_PATH = base;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
vi.restoreAllMocks();
|
|
97
|
+
if (originalBase === undefined) delete process.env.GIT_REPOS_BASE_PATH;
|
|
98
|
+
else process.env.GIT_REPOS_BASE_PATH = originalBase;
|
|
99
|
+
rmSync(fixture, { recursive: true, force: true });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('rejects base itself, traversal, junction escapes and new clones below a junction', () => {
|
|
103
|
+
const outside = join(fixture, 'outside');
|
|
104
|
+
mkdirSync(outside);
|
|
105
|
+
const alias = join(base, 'alias');
|
|
106
|
+
symlinkSync(outside, alias, 'junction');
|
|
107
|
+
try {
|
|
108
|
+
for (const candidate of ['.', '../outside', 'alias', 'alias/new/clone']) {
|
|
109
|
+
expect(() => validateLocalPath(candidate)).toThrow('Invalid local path');
|
|
110
|
+
}
|
|
111
|
+
expect(validateLocalPath('nested/new')).toBe(join(base, 'nested/new'));
|
|
112
|
+
} finally {
|
|
113
|
+
unlinkSync(alias);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('releases the lock when the initial remote setup fails', async () => {
|
|
118
|
+
const git = {
|
|
119
|
+
env: vi.fn(),
|
|
120
|
+
remote: vi.fn().mockRejectedValueOnce(new Error('setup failed')).mockResolvedValue(''),
|
|
121
|
+
};
|
|
122
|
+
const operation = vi.fn().mockResolvedValue('done');
|
|
123
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, operation)).rejects.toThrow(
|
|
124
|
+
'setup failed',
|
|
125
|
+
);
|
|
126
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, operation)).resolves.toBe('done');
|
|
127
|
+
expect(operation).toHaveBeenCalledTimes(1);
|
|
128
|
+
expect(git.env.mock.calls.at(-1)?.[0]).not.toHaveProperty('GIT_CONFIG_COUNT');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('releases the lock even if credential setup fails', async () => {
|
|
132
|
+
const git = {
|
|
133
|
+
env: vi.fn().mockImplementationOnce(() => {
|
|
134
|
+
throw new Error('env failed');
|
|
135
|
+
}),
|
|
136
|
+
remote: vi.fn(),
|
|
137
|
+
};
|
|
138
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, async () => true)).rejects.toThrow(
|
|
139
|
+
'env failed',
|
|
140
|
+
);
|
|
141
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, async () => true)).resolves.toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('never writes PAT or the authorization header into Git config, including on operation failure', async () => {
|
|
145
|
+
execFileSync('git', ['init', base], { stdio: 'ignore' });
|
|
146
|
+
const git = createGit(base);
|
|
147
|
+
await git.addRemote('origin', repoUrl);
|
|
148
|
+
const authorization = Buffer.from(`oauth2:${fakePat}`).toString('base64');
|
|
149
|
+
await expect(
|
|
150
|
+
withAuth(git, base, repoUrl, fakePat, async () => {
|
|
151
|
+
const config = readFileSync(join(base, '.git/config'), 'utf8');
|
|
152
|
+
expect(config).not.toContain(fakePat);
|
|
153
|
+
expect(config).not.toContain(authorization);
|
|
154
|
+
throw new Error(`failure ${fakePat} ${authorization}`);
|
|
155
|
+
}),
|
|
156
|
+
).rejects.toThrow('failure *** ***');
|
|
157
|
+
expect(readFileSync(join(base, '.git/config'), 'utf8')).not.toContain(fakePat);
|
|
158
|
+
await expect(withAuth(git, base, repoUrl, fakePat, async () => 'recovered')).resolves.toBe('recovered');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('scopes the auth header to the trusted repository and disables Git redirects', () => {
|
|
162
|
+
const env = credentialEnvironment(repoUrl, fakePat);
|
|
163
|
+
const config = (url: string) =>
|
|
164
|
+
execFileSync('git', ['config', '--get-urlmatch', 'http', url], { env, encoding: 'utf8' });
|
|
165
|
+
expect(config(`${repoUrl}/info/refs`)).toContain('Authorization: Basic');
|
|
166
|
+
expect(config('https://different.invalid/team/project.git/info/refs')).not.toContain('Authorization: Basic');
|
|
167
|
+
expect(config('https://trusted.invalid/other/project.git/info/refs')).not.toContain('Authorization: Basic');
|
|
168
|
+
expect(config(repoUrl)).toContain('http.followredirects false');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { isGitConfigurationUrlMutation } from '../plugin';
|
|
4
|
-
|
|
5
|
-
describe('Git Manager generic URL mutation policy', () => {
|
|
6
|
-
it('covers direct and association collection create/update routes', () => {
|
|
7
|
-
expect(isGitConfigurationUrlMutation('gitRepositories', 'create')).toBe(true);
|
|
8
|
-
expect(isGitConfigurationUrlMutation('gitAccounts', 'update')).toBe(true);
|
|
9
|
-
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'update')).toBe(true);
|
|
10
|
-
expect(isGitConfigurationUrlMutation('gitRepositories.10.gitAccount', 'create')).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('does not treat a read or a custom Git Manager action as a generic URL mutation', () => {
|
|
14
|
-
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'list')).toBe(false);
|
|
15
|
-
expect(isGitConfigurationUrlMutation('gitManager', 'clone')).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { isGitConfigurationUrlMutation } from '../plugin';
|
|
4
|
+
|
|
5
|
+
describe('Git Manager generic URL mutation policy', () => {
|
|
6
|
+
it('covers direct and association collection create/update routes', () => {
|
|
7
|
+
expect(isGitConfigurationUrlMutation('gitRepositories', 'create')).toBe(true);
|
|
8
|
+
expect(isGitConfigurationUrlMutation('gitAccounts', 'update')).toBe(true);
|
|
9
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'update')).toBe(true);
|
|
10
|
+
expect(isGitConfigurationUrlMutation('gitRepositories.10.gitAccount', 'create')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('does not treat a read or a custom Git Manager action as a generic URL mutation', () => {
|
|
14
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'list')).toBe(false);
|
|
15
|
+
expect(isGitConfigurationUrlMutation('gitManager', 'clone')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Application } from '@nocobase/server';
|
|
11
|
+
import { getPollerStatus, pollAllRepos, startPoller, stopPoller } from '../poller';
|
|
12
|
+
|
|
13
|
+
function mockApp(find = vi.fn().mockResolvedValue([])) {
|
|
14
|
+
return { db: { getRepository: () => ({ find }) }, log: {} } as unknown as Application;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('Poller application isolation', () => {
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.useRealTimers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('starts one timer per application and stops only the requested application', async () => {
|
|
23
|
+
vi.useFakeTimers();
|
|
24
|
+
const firstFind = vi.fn().mockResolvedValue([]);
|
|
25
|
+
const secondFind = vi.fn().mockResolvedValue([]);
|
|
26
|
+
const first = mockApp(firstFind);
|
|
27
|
+
const second = mockApp(secondFind);
|
|
28
|
+
try {
|
|
29
|
+
startPoller(first);
|
|
30
|
+
startPoller(first);
|
|
31
|
+
startPoller(second);
|
|
32
|
+
expect(vi.getTimerCount()).toBe(2);
|
|
33
|
+
await vi.advanceTimersByTimeAsync(5 * 60 * 1000);
|
|
34
|
+
expect(firstFind).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
36
|
+
stopPoller(second);
|
|
37
|
+
expect(getPollerStatus(first).running).toBe(true);
|
|
38
|
+
expect(getPollerStatus(second).running).toBe(false);
|
|
39
|
+
await vi.advanceTimersByTimeAsync(5 * 60 * 1000);
|
|
40
|
+
expect(firstFind).toHaveBeenCalledTimes(2);
|
|
41
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
42
|
+
} finally {
|
|
43
|
+
stopPoller(first);
|
|
44
|
+
stopPoller(second);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('prevents concurrent cycles in one application while allowing another application', async () => {
|
|
49
|
+
let finish = () => {};
|
|
50
|
+
const pending = new Promise<never[]>((resolve) => {
|
|
51
|
+
finish = () => resolve([]);
|
|
52
|
+
});
|
|
53
|
+
const firstFind = vi.fn().mockReturnValue(pending);
|
|
54
|
+
const secondFind = vi.fn().mockResolvedValue([]);
|
|
55
|
+
const first = mockApp(firstFind);
|
|
56
|
+
const second = mockApp(secondFind);
|
|
57
|
+
const running = pollAllRepos(first);
|
|
58
|
+
try {
|
|
59
|
+
await pollAllRepos(first);
|
|
60
|
+
await pollAllRepos(second);
|
|
61
|
+
expect(firstFind).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(getPollerStatus(first).polling).toBe(true);
|
|
64
|
+
expect(getPollerStatus(second).polling).toBe(false);
|
|
65
|
+
} finally {
|
|
66
|
+
finish();
|
|
67
|
+
await running;
|
|
68
|
+
}
|
|
69
|
+
expect(getPollerStatus(first).polling).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { Context } from '@nocobase/actions';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
vi.mock('../poller', () => ({
|
|
5
|
-
pollAllRepos: vi.fn(),
|
|
6
|
-
pollOneRepo: vi.fn(),
|
|
7
|
-
getPollerStatus: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
import { pollNow } from '../actions/poller';
|
|
11
|
-
import { pollAllRepos, pollOneRepo } from '../poller';
|
|
12
|
-
|
|
13
|
-
describe('Git Manager poll action', () => {
|
|
14
|
-
it('uses a repository ID sent in the request body instead of polling every repository', async () => {
|
|
15
|
-
const repository = { id: 10 };
|
|
16
|
-
vi.mocked(pollOneRepo).mockResolvedValue({ scanned: 1, triggered: 0 });
|
|
17
|
-
const context = {
|
|
18
|
-
action: { params: {} },
|
|
19
|
-
request: { body: { repositoryId: 10 } },
|
|
20
|
-
app: {},
|
|
21
|
-
db: {
|
|
22
|
-
getRepository: vi.fn().mockReturnValue({
|
|
23
|
-
findOne: vi.fn().mockResolvedValue(repository),
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
throw: vi.fn(),
|
|
27
|
-
body: undefined as unknown,
|
|
28
|
-
};
|
|
29
|
-
const next = vi.fn().mockResolvedValue(undefined);
|
|
30
|
-
|
|
31
|
-
await pollNow(context as unknown as Context, next);
|
|
32
|
-
|
|
33
|
-
expect(pollOneRepo).toHaveBeenCalledWith(context.app, repository);
|
|
34
|
-
expect(pollAllRepos).not.toHaveBeenCalled();
|
|
35
|
-
expect(context.body).toEqual({ success: true, data: { scanned: 1, triggered: 0 } });
|
|
36
|
-
});
|
|
37
|
-
});
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
vi.mock('../poller', () => ({
|
|
5
|
+
pollAllRepos: vi.fn(),
|
|
6
|
+
pollOneRepo: vi.fn(),
|
|
7
|
+
getPollerStatus: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
import { pollNow } from '../actions/poller';
|
|
11
|
+
import { pollAllRepos, pollOneRepo } from '../poller';
|
|
12
|
+
|
|
13
|
+
describe('Git Manager poll action', () => {
|
|
14
|
+
it('uses a repository ID sent in the request body instead of polling every repository', async () => {
|
|
15
|
+
const repository = { id: 10 };
|
|
16
|
+
vi.mocked(pollOneRepo).mockResolvedValue({ scanned: 1, triggered: 0 });
|
|
17
|
+
const context = {
|
|
18
|
+
action: { params: {} },
|
|
19
|
+
request: { body: { repositoryId: 10 } },
|
|
20
|
+
app: {},
|
|
21
|
+
db: {
|
|
22
|
+
getRepository: vi.fn().mockReturnValue({
|
|
23
|
+
findOne: vi.fn().mockResolvedValue(repository),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
throw: vi.fn(),
|
|
27
|
+
body: undefined as unknown,
|
|
28
|
+
};
|
|
29
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
30
|
+
|
|
31
|
+
await pollNow(context as unknown as Context, next);
|
|
32
|
+
|
|
33
|
+
expect(pollOneRepo).toHaveBeenCalledWith(context.app, repository);
|
|
34
|
+
expect(pollAllRepos).not.toHaveBeenCalled();
|
|
35
|
+
expect(context.body).toEqual({ success: true, data: { scanned: 1, triggered: 0 } });
|
|
36
|
+
});
|
|
37
|
+
});
|