@karoy/dsh-gitlab-workbench 0.0.0-stage → 0.2.2
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/LICENSE +21 -0
- package/README.md +118 -2
- package/cordis.patch.yml +4 -0
- package/dist/client.js +2288 -0
- package/dist/host/gitlab.js +268 -0
- package/dist/host/index.js +54 -0
- package/dist/host/routes.js +567 -0
- package/dist/host/store.js +236 -0
- package/dist/host/types.js +1 -0
- package/docs/DETAIL.md +37 -0
- package/icon.svg +18 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +79 -4
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instances of the GitLab workbench.
|
|
3
|
+
*
|
|
4
|
+
* The instance list is a small JSON document under the DSH home directory; the
|
|
5
|
+
* personal access token never goes there. Each token is stored as a record of
|
|
6
|
+
* the host credential service under `gitlab-workbench/<instance id>`, so the
|
|
7
|
+
* browser half never receives it and the record survives restarts.
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import crypto from 'node:crypto';
|
|
13
|
+
/** The credential scope every record of this plugin is stored under. */
|
|
14
|
+
export const CREDENTIAL_SCOPE = 'gitlab-workbench';
|
|
15
|
+
/** The one shape the credential service accepts for one half of a key. */
|
|
16
|
+
const SEGMENT = /^[a-z][a-z0-9-]*$/;
|
|
17
|
+
const DEFAULT_DIR = path.join(os.homedir(), '.dsh', 'gitlab-workbench');
|
|
18
|
+
/** Report whether a string is a value a credential key segment may carry. */
|
|
19
|
+
function validSegment(value) {
|
|
20
|
+
return typeof value === 'string' && SEGMENT.test(value);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalize an instance root URL.
|
|
24
|
+
*
|
|
25
|
+
* The endpoint is the instance root, not the API root: calls append `/api/v4`.
|
|
26
|
+
* A pasted API URL is accepted and reduced to the root, and a trailing slash is
|
|
27
|
+
* dropped so two spellings of one instance do not create two entries.
|
|
28
|
+
*/
|
|
29
|
+
export function normalizeEndpoint(raw) {
|
|
30
|
+
const text = String(raw ?? '').trim();
|
|
31
|
+
if (text === '')
|
|
32
|
+
throw new Error('Instance URL is required.');
|
|
33
|
+
let url;
|
|
34
|
+
try {
|
|
35
|
+
url = new URL(text);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error('Instance URL is not a valid absolute URL.');
|
|
39
|
+
}
|
|
40
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
41
|
+
throw new Error('Instance URL must use http or https.');
|
|
42
|
+
}
|
|
43
|
+
if (url.username || url.password)
|
|
44
|
+
throw new Error('Instance URL must not contain credentials.');
|
|
45
|
+
let base = `${url.origin}${url.pathname}`.replace(/\/+$/, '');
|
|
46
|
+
base = base.replace(/\/api\/v4$/i, '').replace(/\/+$/, '');
|
|
47
|
+
if (!/^https?:\/\/[^/]+/i.test(base))
|
|
48
|
+
throw new Error('Instance URL is not a valid absolute URL.');
|
|
49
|
+
return base;
|
|
50
|
+
}
|
|
51
|
+
/** Build the credential key of one instance. */
|
|
52
|
+
export function credentialKeyFor(instanceId) {
|
|
53
|
+
if (!validSegment(instanceId))
|
|
54
|
+
throw new TypeError('Invalid instance id for a credential key.');
|
|
55
|
+
return `${CREDENTIAL_SCOPE}/${instanceId}`;
|
|
56
|
+
}
|
|
57
|
+
function loadDocument(file) {
|
|
58
|
+
try {
|
|
59
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
60
|
+
const parsed = JSON.parse(text);
|
|
61
|
+
const instances = Array.isArray(parsed?.instances) ? parsed.instances : [];
|
|
62
|
+
return { version: 1, instances: instances.filter((entry) => entry && validSegment(entry.id)) };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { version: 1, instances: [] };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function saveDocument(file, document) {
|
|
69
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
70
|
+
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
71
|
+
fs.writeFileSync(temp, `${JSON.stringify(document, null, 2)}\n`, { mode: 0o600 });
|
|
72
|
+
fs.renameSync(temp, file);
|
|
73
|
+
}
|
|
74
|
+
/** Resolve the host credential service, which may activate after this plugin. */
|
|
75
|
+
function resolveCredentials(ctx) {
|
|
76
|
+
// `ctx.credentials` may only be read through `inject`; the credential
|
|
77
|
+
// service is optional here (a profile without it still browses), so ask the
|
|
78
|
+
// registry instead of touching the property.
|
|
79
|
+
try {
|
|
80
|
+
const found = ctx.get?.('credentials');
|
|
81
|
+
if (found && typeof found.modifyRecord === 'function')
|
|
82
|
+
return found;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// A service that is not reachable from here is simply absent for now.
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/** Create the instance store. */
|
|
90
|
+
export function createInstanceStore({ ctx, logger, dataDir }) {
|
|
91
|
+
const dir = dataDir ?? DEFAULT_DIR;
|
|
92
|
+
const file = path.join(dir, 'instances.json');
|
|
93
|
+
const document = loadDocument(file);
|
|
94
|
+
/** Last connection check per instance, in memory only. */
|
|
95
|
+
const statuses = new Map();
|
|
96
|
+
const log = (level, message, detail) => {
|
|
97
|
+
const emit = logger?.[level];
|
|
98
|
+
if (typeof emit !== 'function')
|
|
99
|
+
return;
|
|
100
|
+
try {
|
|
101
|
+
emit.call(logger, message, detail);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Diagnostic logging must never break a request.
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const credentials = () => resolveCredentials(ctx);
|
|
108
|
+
async function readToken(id) {
|
|
109
|
+
const service = credentials();
|
|
110
|
+
if (!service || typeof service.readRecord !== 'function')
|
|
111
|
+
return undefined;
|
|
112
|
+
try {
|
|
113
|
+
const record = await service.readRecord(credentialKeyFor(id));
|
|
114
|
+
if (!record || (record.kind !== 'grant' && record.kind !== 'pat'))
|
|
115
|
+
return undefined;
|
|
116
|
+
const payload = record.payload;
|
|
117
|
+
if (!payload || typeof payload.token !== 'string' || payload.token === '')
|
|
118
|
+
return undefined;
|
|
119
|
+
return payload;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
log('warn', `gitlab-workbench: could not read the credential record of ${id}`, {
|
|
123
|
+
error: error?.name ?? String(error),
|
|
124
|
+
});
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function writeToken(id, payload) {
|
|
129
|
+
const service = credentials();
|
|
130
|
+
if (!service || typeof service.modifyRecord !== 'function') {
|
|
131
|
+
throw Object.assign(new Error('The host credential service is unavailable.'), { code: 'credentials_unavailable' });
|
|
132
|
+
}
|
|
133
|
+
// DSH credentials only admit `api-key` and `grant` records; a personal
|
|
134
|
+
// access token is opaque data, so it travels as a grant payload.
|
|
135
|
+
await service.modifyRecord(credentialKeyFor(id), async () => ({ kind: 'grant', payload }));
|
|
136
|
+
}
|
|
137
|
+
async function removeToken(id) {
|
|
138
|
+
const service = credentials();
|
|
139
|
+
if (!service || typeof service.deleteRecord !== 'function')
|
|
140
|
+
return;
|
|
141
|
+
try {
|
|
142
|
+
await service.deleteRecord(credentialKeyFor(id));
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
log('warn', `gitlab-workbench: could not delete the credential record of ${id}`, {
|
|
146
|
+
error: error?.name ?? String(error),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function list() {
|
|
151
|
+
return document.instances.map((entry) => ({ ...entry }));
|
|
152
|
+
}
|
|
153
|
+
function get(id) {
|
|
154
|
+
const found = document.instances.find((entry) => entry.id === id);
|
|
155
|
+
return found ? { ...found } : undefined;
|
|
156
|
+
}
|
|
157
|
+
function add(input) {
|
|
158
|
+
const endpoint = normalizeEndpoint(input.endpoint);
|
|
159
|
+
if (document.instances.some((entry) => entry.endpoint.toLowerCase() === endpoint.toLowerCase())) {
|
|
160
|
+
throw Object.assign(new Error('This instance is already configured.'), { code: 'duplicate_instance' });
|
|
161
|
+
}
|
|
162
|
+
const url = new URL(endpoint);
|
|
163
|
+
const now = new Date().toISOString();
|
|
164
|
+
const instance = {
|
|
165
|
+
id: `inst-${crypto.randomBytes(4).toString('hex')}`,
|
|
166
|
+
label: String(input.label ?? '').trim() || url.host,
|
|
167
|
+
endpoint,
|
|
168
|
+
verifyTls: input.verifyTls !== false,
|
|
169
|
+
...(typeof input.caPem === 'string' && input.caPem.trim() !== '' ? { caPem: input.caPem.trim() } : {}),
|
|
170
|
+
createdAt: now,
|
|
171
|
+
updatedAt: now,
|
|
172
|
+
};
|
|
173
|
+
document.instances.push(instance);
|
|
174
|
+
saveDocument(file, document);
|
|
175
|
+
return { ...instance };
|
|
176
|
+
}
|
|
177
|
+
async function update(id, patch) {
|
|
178
|
+
const instance = document.instances.find((entry) => entry.id === id);
|
|
179
|
+
if (!instance)
|
|
180
|
+
throw Object.assign(new Error('Unknown instance.'), { code: 'unknown_instance', status: 404 });
|
|
181
|
+
if (patch.endpoint !== undefined) {
|
|
182
|
+
const endpoint = normalizeEndpoint(patch.endpoint);
|
|
183
|
+
if (document.instances.some((entry) => entry.id !== id && entry.endpoint.toLowerCase() === endpoint.toLowerCase())) {
|
|
184
|
+
throw Object.assign(new Error('This instance is already configured.'), { code: 'duplicate_instance' });
|
|
185
|
+
}
|
|
186
|
+
if (endpoint !== instance.endpoint) {
|
|
187
|
+
instance.endpoint = endpoint;
|
|
188
|
+
await removeToken(id);
|
|
189
|
+
statuses.delete(id);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (patch.label !== undefined)
|
|
193
|
+
instance.label = String(patch.label).trim() || new URL(instance.endpoint).host;
|
|
194
|
+
if (patch.verifyTls !== undefined)
|
|
195
|
+
instance.verifyTls = patch.verifyTls !== false;
|
|
196
|
+
if (patch.caPem !== undefined) {
|
|
197
|
+
const pem = typeof patch.caPem === 'string' ? patch.caPem.trim() : '';
|
|
198
|
+
if (pem === '')
|
|
199
|
+
delete instance.caPem;
|
|
200
|
+
else
|
|
201
|
+
instance.caPem = pem;
|
|
202
|
+
}
|
|
203
|
+
instance.updatedAt = new Date().toISOString();
|
|
204
|
+
saveDocument(file, document);
|
|
205
|
+
return { ...instance };
|
|
206
|
+
}
|
|
207
|
+
async function remove(id) {
|
|
208
|
+
const index = document.instances.findIndex((entry) => entry.id === id);
|
|
209
|
+
if (index < 0)
|
|
210
|
+
return false;
|
|
211
|
+
document.instances.splice(index, 1);
|
|
212
|
+
saveDocument(file, document);
|
|
213
|
+
statuses.delete(id);
|
|
214
|
+
await removeToken(id);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
function setStatus(id, status) {
|
|
218
|
+
statuses.set(id, { ...status, checkedAt: new Date().toISOString() });
|
|
219
|
+
}
|
|
220
|
+
function getStatus(id) {
|
|
221
|
+
return statuses.get(id);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
list,
|
|
225
|
+
get,
|
|
226
|
+
add,
|
|
227
|
+
update,
|
|
228
|
+
remove,
|
|
229
|
+
readToken,
|
|
230
|
+
writeToken,
|
|
231
|
+
removeToken,
|
|
232
|
+
setStatus,
|
|
233
|
+
getStatus,
|
|
234
|
+
hasCredentials: () => credentials() !== undefined,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# GitLab 工作台
|
|
2
|
+
|
|
3
|
+
在 DSH 左侧栏加入一个 **GitLab** 入口,打开一个全屏工作台,把多个自托管 GitLab 实例的日常操作集中到会话旁边。适配 GitLab Self-Managed 17.x(REST API v4)。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- **多实例**:每个实例保存独立的地址、TLS 设置和个人访问令牌;顶栏切换,项目列表与流水线随之切换。
|
|
8
|
+
- **项目栏**:左侧常驻项目列表,搜索与切换都不离开当前视图。
|
|
9
|
+
- **概览**:开放议题/合并请求、Star/Fork、最近流水线、分支与提交。
|
|
10
|
+
- **流水线**:列表 + 阶段时间线 + 作业、失败作业日志末尾、重试/取消流水线与作业。
|
|
11
|
+
- **合并请求与议题**:列表与详情,附在 GitLab 打开的链接。
|
|
12
|
+
- **文件**:仓库目录树与文本文件查看。
|
|
13
|
+
|
|
14
|
+
## 认证
|
|
15
|
+
|
|
16
|
+
在「实例与令牌」为每个实例填写个人访问令牌:
|
|
17
|
+
|
|
18
|
+
- `read_api`:只读视图;
|
|
19
|
+
- `api`:额外允许重试/取消流水线与作业。
|
|
20
|
+
|
|
21
|
+
令牌只保存在 DSH Host 的凭据服务里(`gitlab-workbench/<实例 id>`),浏览器端不会收到令牌值;所有 GitLab 请求由 Host 代理发出。
|
|
22
|
+
|
|
23
|
+
## 自托管与证书
|
|
24
|
+
|
|
25
|
+
- 实例地址填根地址(例如 `https://gitlab.acme.example.com`),调用会拼上 `/api/v4`。
|
|
26
|
+
- 自签证书或企业 CA:把 CA 证书 PEM 粘到「企业 CA 证书」;仅在明确风险时关闭「校验 TLS 证书」。
|
|
27
|
+
- 实例部署在子路径下(如 `https://host/gitlab`)同样可用。
|
|
28
|
+
|
|
29
|
+
## 限制
|
|
30
|
+
|
|
31
|
+
- 以只读浏览为主;写操作目前只有流水线/作业的重试与取消。
|
|
32
|
+
- 项目工作台以当前选中项目为范围,跨项目收件箱尚未提供。
|
|
33
|
+
- 大文件与二进制文件不在页面内渲染;作业日志只取末尾约 200 KB。
|
|
34
|
+
|
|
35
|
+
## 工程结构
|
|
36
|
+
|
|
37
|
+
Host 半(`src/host`)负责令牌、实例清单与 GitLab REST 调用;Client 半(`src/client`)按 `views/` 拆分面板、项目、概览、流水线、合并请求、议题、文件与设置。`npm run build` 产出 `dist/`(tsc 编译 Host,esbuild 打包 Client,React 外置)。
|
package/icon.svg
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="GitLab workbench">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="glw-bg" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#2b2f3a"/>
|
|
5
|
+
<stop offset="1" stop-color="#171a21"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="glw-accent" x1="0" y1="0" x2="0" y2="1">
|
|
8
|
+
<stop offset="0" stop-color="#fc9d4b"/>
|
|
9
|
+
<stop offset="1" stop-color="#e2632a"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
<rect width="64" height="64" rx="14" fill="url(#glw-bg)"/>
|
|
13
|
+
<path d="M19 18v13.5a9 9 0 0 0 9 9h7" fill="none" stroke="url(#glw-accent)" stroke-width="4.2" stroke-linecap="round"/>
|
|
14
|
+
<circle cx="19" cy="18" r="4.4" fill="url(#glw-accent)"/>
|
|
15
|
+
<circle cx="45" cy="25" r="5.2" fill="#f7f8fa"/>
|
|
16
|
+
<circle cx="36" cy="44" r="5.2" fill="#f7f8fa"/>
|
|
17
|
+
<path d="M45 30.2v3.3a7.5 7.5 0 0 1-7.5 7.5h-1" fill="none" stroke="#f7f8fa" stroke-width="4.2" stroke-linecap="round"/>
|
|
18
|
+
</svg>
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "GitLab workbench",
|
|
4
|
+
"description": "A left-sidebar workbench for several self-managed GitLab instances: projects, branches, commits, files, merge requests, issues and CI/CD pipelines, authenticated with a personal access token per instance.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karoy/dsh-gitlab-workbench",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "GitLab workbench: a left-sidebar entry and a global panel for several self-managed GitLab instances, focused on projects and CI pipelines.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"dsh-plugin",
|
|
10
|
+
"deepseek-harness",
|
|
11
|
+
"gitlab",
|
|
12
|
+
"ci",
|
|
13
|
+
"pipelines",
|
|
14
|
+
"merge-requests"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/lunnlew/dsh-gitlab-workbench.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/lunnlew/dsh-gitlab-workbench#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/lunnlew/dsh-gitlab-workbench/issues"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/host/index.js",
|
|
30
|
+
"./client": "./dist/client.js",
|
|
31
|
+
"./locale/*.json": "./locale/*.json",
|
|
32
|
+
"./icon": "./icon.svg"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"cordis.patch.yml",
|
|
37
|
+
"locale/*.json",
|
|
38
|
+
"docs",
|
|
39
|
+
"icon.svg",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"immediately": true,
|
|
49
|
+
"inject": [
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22",
|
|
57
|
+
"dsh": ">=0.2.2-rc.5"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "npm run build:host && npm run build:client",
|
|
61
|
+
"build:host": "tsc -p tsconfig.host.json",
|
|
62
|
+
"build:client": "node build.mjs",
|
|
63
|
+
"typecheck": "tsc -p tsconfig.client.json --noEmit && tsc -p tsconfig.host.json --noEmit",
|
|
64
|
+
"mock": "node test/mock-gitlab.js 18080",
|
|
65
|
+
"test:host": "node test/host-check.js 18080",
|
|
66
|
+
"test:client": "node test/client-check.cjs",
|
|
67
|
+
"test:e2e": "node test/client-e2e.mjs 18080",
|
|
68
|
+
"test": "npm run build && npm run test:host && npm run test:client && npm run test:e2e",
|
|
69
|
+
"prepack": "npm run build",
|
|
70
|
+
"preview": "node test/preview-server.mjs 18082 18080"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/node": "^22.10.2",
|
|
74
|
+
"@types/react": "^18.3.18",
|
|
75
|
+
"esbuild": "^0.24.2",
|
|
76
|
+
"jsdom": "^24.1.3",
|
|
77
|
+
"react": "^18.3.1",
|
|
78
|
+
"react-dom": "^18.3.1",
|
|
79
|
+
"typescript": "^5.7.2"
|
|
80
|
+
}
|
|
81
|
+
}
|