@nibgat/ncli 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +156 -2
- package/dist/bin/ncli.d.ts +2 -0
- package/dist/bin/ncli.js +9 -0
- package/dist/bin/ncli.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +723 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/buyment.d.ts +2 -0
- package/dist/commands/buyment.js +174 -0
- package/dist/commands/buyment.js.map +1 -0
- package/dist/commands/cloud.d.ts +2 -0
- package/dist/commands/cloud.js +281 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/context.d.ts +25 -0
- package/dist/commands/context.js +92 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/front.d.ts +2 -0
- package/dist/commands/front.js +135 -0
- package/dist/commands/front.js.map +1 -0
- package/dist/commands/git.d.ts +2 -0
- package/dist/commands/git.js +726 -0
- package/dist/commands/git.js.map +1 -0
- package/dist/commands/health.d.ts +2 -0
- package/dist/commands/health.js +99 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/mail.d.ts +2 -0
- package/dist/commands/mail.js +265 -0
- package/dist/commands/mail.js.map +1 -0
- package/dist/commands/pipeline.d.ts +2 -0
- package/dist/commands/pipeline.js +333 -0
- package/dist/commands/pipeline.js.map +1 -0
- package/dist/commands/profile.d.ts +2 -0
- package/dist/commands/profile.js +229 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/runner.d.ts +2 -0
- package/dist/commands/runner.js +266 -0
- package/dist/commands/runner.js.map +1 -0
- package/dist/commands/support.d.ts +2 -0
- package/dist/commands/support.js +133 -0
- package/dist/commands/support.js.map +1 -0
- package/dist/constants/index.d.ts +26 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/http/client.d.ts +46 -0
- package/dist/http/client.js +262 -0
- package/dist/http/client.js.map +1 -0
- package/dist/http/coreApi.d.ts +136 -0
- package/dist/http/coreApi.js +485 -0
- package/dist/http/coreApi.js.map +1 -0
- package/dist/http/gitApi.d.ts +128 -0
- package/dist/http/gitApi.js +255 -0
- package/dist/http/gitApi.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline/detect.d.ts +13 -0
- package/dist/pipeline/detect.js +90 -0
- package/dist/pipeline/detect.js.map +1 -0
- package/dist/pipeline/release.d.ts +36 -0
- package/dist/pipeline/release.js +250 -0
- package/dist/pipeline/release.js.map +1 -0
- package/dist/pipeline/schema.d.ts +10 -0
- package/dist/pipeline/schema.js +155 -0
- package/dist/pipeline/schema.js.map +1 -0
- package/dist/runner/config.d.ts +21 -0
- package/dist/runner/config.js +235 -0
- package/dist/runner/config.js.map +1 -0
- package/dist/runner/server.d.ts +25 -0
- package/dist/runner/server.js +803 -0
- package/dist/runner/server.js.map +1 -0
- package/dist/runner/systemd.d.ts +14 -0
- package/dist/runner/systemd.js +82 -0
- package/dist/runner/systemd.js.map +1 -0
- package/dist/runner/tarExtract.d.ts +4 -0
- package/dist/runner/tarExtract.js +215 -0
- package/dist/runner/tarExtract.js.map +1 -0
- package/dist/security/execSafe.d.ts +20 -0
- package/dist/security/execSafe.js +216 -0
- package/dist/security/execSafe.js.map +1 -0
- package/dist/security/pkce.d.ts +9 -0
- package/dist/security/pkce.js +35 -0
- package/dist/security/pkce.js.map +1 -0
- package/dist/security/redact.d.ts +3 -0
- package/dist/security/redact.js +76 -0
- package/dist/security/redact.js.map +1 -0
- package/dist/security/sanitize.d.ts +18 -0
- package/dist/security/sanitize.js +216 -0
- package/dist/security/sanitize.js.map +1 -0
- package/dist/security/vault.d.ts +34 -0
- package/dist/security/vault.js +291 -0
- package/dist/security/vault.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/output.d.ts +25 -0
- package/dist/ui/output.js +100 -0
- package/dist/ui/output.js.map +1 -0
- package/dist/ui/prompt.d.ts +4 -0
- package/dist/ui/prompt.js +100 -0
- package/dist/ui/prompt.js.map +1 -0
- package/package.json +54 -5
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { DEFAULT_REGISTRY_HOST } from "../constants/index.js";
|
|
4
|
+
import { validateRegistryHost, validateGitRef, parseRepoSpec, validateSlug } from "../security/sanitize.js";
|
|
5
|
+
import { execSafe } from "../security/execSafe.js";
|
|
6
|
+
import { maskSecret } from "../security/redact.js";
|
|
7
|
+
import { runCommandAction } from "./context.js";
|
|
8
|
+
export const registerGitCommands = (program) => {
|
|
9
|
+
const git = program
|
|
10
|
+
.command("git")
|
|
11
|
+
.description("Manage N - Git repositories, releases, webhooks, runners, deployments and OCI registry");
|
|
12
|
+
git
|
|
13
|
+
.command("overview")
|
|
14
|
+
.description("Show N - Git account overview")
|
|
15
|
+
.action(async (_opts, cmd) => {
|
|
16
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
17
|
+
const res = await ctx.gitClient.overview();
|
|
18
|
+
ctx.output.data(res.data);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
git
|
|
22
|
+
.command("quota")
|
|
23
|
+
.description("Show N - Git repository & organization quotas")
|
|
24
|
+
.action(async (_opts, cmd) => {
|
|
25
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
26
|
+
const res = await ctx.gitClient.quota();
|
|
27
|
+
ctx.output.data(res.data);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
// --- Organizations ---
|
|
31
|
+
const orgs = git
|
|
32
|
+
.command("orgs")
|
|
33
|
+
.description("Manage N - Git organizations");
|
|
34
|
+
orgs
|
|
35
|
+
.command("list")
|
|
36
|
+
.description("List organizations")
|
|
37
|
+
.action(async (_opts, cmd) => {
|
|
38
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
39
|
+
const res = await ctx.gitClient.listOrgs();
|
|
40
|
+
const items = (res.data?.organizations || []);
|
|
41
|
+
ctx.output.data(res.data, () => {
|
|
42
|
+
ctx.output.table([
|
|
43
|
+
"SLUG",
|
|
44
|
+
"TITLE",
|
|
45
|
+
"ROLE",
|
|
46
|
+
"REPOS"
|
|
47
|
+
], items.map((o) => [
|
|
48
|
+
String(o.slug || "-"),
|
|
49
|
+
String(o.title || "-"),
|
|
50
|
+
String(o.role || "-"),
|
|
51
|
+
String(o.repoCount ?? "-")
|
|
52
|
+
]));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
orgs
|
|
57
|
+
.command("create <slug>")
|
|
58
|
+
.description("Create an organization")
|
|
59
|
+
.requiredOption("--title <title>", "Organization display title")
|
|
60
|
+
.option("--description <desc>", "Description")
|
|
61
|
+
.option("--website <url>", "Website URL")
|
|
62
|
+
.action(async (slug, opts, cmd) => {
|
|
63
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
64
|
+
const safeSlug = validateSlug(slug, "organization slug");
|
|
65
|
+
const res = await ctx.gitClient.createOrg({
|
|
66
|
+
description: opts.description,
|
|
67
|
+
website: opts.website,
|
|
68
|
+
title: opts.title,
|
|
69
|
+
slug: safeSlug
|
|
70
|
+
});
|
|
71
|
+
ctx.output.data(res.data, () => {
|
|
72
|
+
ctx.output.success(`Created organization "${safeSlug}".`);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// --- Repositories ---
|
|
77
|
+
const repos = git
|
|
78
|
+
.command("repos")
|
|
79
|
+
.description("List, inspect, create, delete and clone N - Git repositories");
|
|
80
|
+
repos
|
|
81
|
+
.command("list")
|
|
82
|
+
.description("List repositories")
|
|
83
|
+
.option("--owner <slug>", "Filter by owner/organization slug")
|
|
84
|
+
.option("-q, --query <text>", "Search repositories")
|
|
85
|
+
.action(async (opts, cmd) => {
|
|
86
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
87
|
+
const res = await ctx.gitClient.listRepos({
|
|
88
|
+
owner: opts.owner,
|
|
89
|
+
q: opts.query
|
|
90
|
+
});
|
|
91
|
+
const items = (res.data?.repositories || []);
|
|
92
|
+
ctx.output.data(res.data, () => {
|
|
93
|
+
ctx.output.table([
|
|
94
|
+
"REPOSITORY",
|
|
95
|
+
"VISIBILITY",
|
|
96
|
+
"BRANCH",
|
|
97
|
+
"UPDATED"
|
|
98
|
+
], items.map((r) => [
|
|
99
|
+
String(r.fullName || `${r.ownerSlug}/${r.name}`),
|
|
100
|
+
r.isPrivate ? "private" : "public",
|
|
101
|
+
String(r.defaultBranch || "main"),
|
|
102
|
+
String(r.updatedAt || "-")
|
|
103
|
+
]));
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
repos
|
|
108
|
+
.command("info <repo>")
|
|
109
|
+
.description("Show repository details (<owner>/<repo>)")
|
|
110
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
111
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
112
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
113
|
+
const res = await ctx.gitClient.getRepo(owner, repo);
|
|
114
|
+
const r = (res.data?.repository || res.data);
|
|
115
|
+
ctx.output.data(res.data, () => {
|
|
116
|
+
ctx.output.kv([
|
|
117
|
+
[
|
|
118
|
+
"Repository",
|
|
119
|
+
String(r.fullName || `${owner}/${repo}`)
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"Visibility",
|
|
123
|
+
r.isPrivate ? "private" : "public"
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
"Default Branch",
|
|
127
|
+
String(r.defaultBranch || "main")
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
"Description",
|
|
131
|
+
String(r.description || "-")
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"HTTPS Clone",
|
|
135
|
+
`${ctx.gitUrl}/${owner}/${repo}.git`
|
|
136
|
+
]
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
repos
|
|
142
|
+
.command("create <name>")
|
|
143
|
+
.description("Create a repository")
|
|
144
|
+
.option("--org <slug>", "Create under an organization slug")
|
|
145
|
+
.option("--private", "Make repository private (default)", true)
|
|
146
|
+
.option("--public", "Make repository public")
|
|
147
|
+
.option("--description <desc>", "Repository description")
|
|
148
|
+
.action(async (name, opts, cmd) => {
|
|
149
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
150
|
+
const safeName = validateSlug(name, "repository name");
|
|
151
|
+
const isPrivate = opts.public ? false : Boolean(opts.private);
|
|
152
|
+
const res = await ctx.gitClient.createRepo({
|
|
153
|
+
ownerSlug: opts.org ? validateSlug(opts.org, "org slug") : undefined,
|
|
154
|
+
description: opts.description,
|
|
155
|
+
name: safeName,
|
|
156
|
+
isPrivate
|
|
157
|
+
});
|
|
158
|
+
ctx.output.data(res.data, () => {
|
|
159
|
+
const created = res.data?.repository;
|
|
160
|
+
ctx.output.success(`Created repository ${String(created?.fullName || safeName)}.`);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
repos
|
|
165
|
+
.command("delete <repo>")
|
|
166
|
+
.description("Permanently delete a repository (<owner>/<repo>)")
|
|
167
|
+
.requiredOption("--yes", "Confirm irreversible deletion")
|
|
168
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
169
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
170
|
+
const { fullName, owner, repo } = parseRepoSpec(repoSpec);
|
|
171
|
+
const res = await ctx.gitClient.deleteRepo(owner, repo);
|
|
172
|
+
ctx.output.data(res.data, () => {
|
|
173
|
+
ctx.output.success(`Deleted repository ${fullName}.`);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
repos
|
|
178
|
+
.command("clone <repo> [dir]")
|
|
179
|
+
.description("Clone a repository from git.nibgat.space (<owner>/<repo>)")
|
|
180
|
+
.action(async (repoSpec, dir, _opts, cmd) => {
|
|
181
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
182
|
+
const { fullName, owner, repo } = parseRepoSpec(repoSpec);
|
|
183
|
+
const cloneUrl = `${ctx.gitUrl}/${owner}/${repo}.git`;
|
|
184
|
+
const args = [
|
|
185
|
+
"clone",
|
|
186
|
+
cloneUrl
|
|
187
|
+
];
|
|
188
|
+
if (dir) {
|
|
189
|
+
args.push(dir);
|
|
190
|
+
}
|
|
191
|
+
await execSafe("git", args);
|
|
192
|
+
ctx.output.data({
|
|
193
|
+
ok: true,
|
|
194
|
+
repo: fullName,
|
|
195
|
+
url: cloneUrl,
|
|
196
|
+
dir: dir || repo
|
|
197
|
+
}, () => {
|
|
198
|
+
ctx.output.success(`Cloned ${fullName} into ${dir || repo}.`);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
// --- Branches ---
|
|
203
|
+
const branches = git
|
|
204
|
+
.command("branches")
|
|
205
|
+
.description("Inspect repository branches");
|
|
206
|
+
branches
|
|
207
|
+
.command("list <repo>")
|
|
208
|
+
.description("List branches for <owner>/<repo>")
|
|
209
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
210
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
211
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
212
|
+
const res = await ctx.gitClient.listBranches(owner, repo);
|
|
213
|
+
const items = (res.data?.branches || []);
|
|
214
|
+
ctx.output.data(res.data, () => {
|
|
215
|
+
ctx.output.table([
|
|
216
|
+
"BRANCH",
|
|
217
|
+
"COMMIT",
|
|
218
|
+
"PROTECTED"
|
|
219
|
+
], items.map((b) => [
|
|
220
|
+
String(b.name || "-"),
|
|
221
|
+
String(b.sha || b.commitSha || "-").slice(0, 10),
|
|
222
|
+
String(Boolean(b.isProtected ?? b.protected))
|
|
223
|
+
]));
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
// --- Issues ---
|
|
228
|
+
const issues = git
|
|
229
|
+
.command("issues")
|
|
230
|
+
.description("List and create issues / pull requests");
|
|
231
|
+
issues
|
|
232
|
+
.command("list <repo>")
|
|
233
|
+
.description("List issues for <owner>/<repo>")
|
|
234
|
+
.option("--state <state>", "Filter by state (open|closed)")
|
|
235
|
+
.option("--kind <kind>", "Filter by kind (issue|pr)")
|
|
236
|
+
.action(async (repoSpec, opts, cmd) => {
|
|
237
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
238
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
239
|
+
const res = await ctx.gitClient.listIssues(owner, repo, {
|
|
240
|
+
state: opts.state,
|
|
241
|
+
kind: opts.kind
|
|
242
|
+
});
|
|
243
|
+
const items = (res.data?.issues || []);
|
|
244
|
+
ctx.output.data(res.data, () => {
|
|
245
|
+
ctx.output.table([
|
|
246
|
+
"#",
|
|
247
|
+
"KIND",
|
|
248
|
+
"STATE",
|
|
249
|
+
"TITLE"
|
|
250
|
+
], items.map((i) => [
|
|
251
|
+
String(i.number || i.id || "-"),
|
|
252
|
+
String(i.kind || "issue"),
|
|
253
|
+
String(i.state || "-"),
|
|
254
|
+
String(i.title || "-")
|
|
255
|
+
]));
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
issues
|
|
260
|
+
.command("create <repo>")
|
|
261
|
+
.description("Create an issue or pull request in <owner>/<repo>")
|
|
262
|
+
.requiredOption("--title <title>", "Issue title")
|
|
263
|
+
.option("--body <text>", "Issue description")
|
|
264
|
+
.option("--kind <kind>", "issue | pr", "issue")
|
|
265
|
+
.option("--source <branch>", "Source branch (for PR)")
|
|
266
|
+
.option("--target <branch>", "Target branch (for PR)")
|
|
267
|
+
.action(async (repoSpec, opts, cmd) => {
|
|
268
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
269
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
270
|
+
const kind = opts.kind === "pr" ? "pr" : "issue";
|
|
271
|
+
const res = await ctx.gitClient.createIssue(owner, repo, {
|
|
272
|
+
sourceBranch: opts.source,
|
|
273
|
+
targetBranch: opts.target,
|
|
274
|
+
title: opts.title,
|
|
275
|
+
body: opts.body,
|
|
276
|
+
kind
|
|
277
|
+
});
|
|
278
|
+
ctx.output.data(res.data, () => {
|
|
279
|
+
ctx.output.success(`Created ${kind} #${String(res.data.number || "")} in ${owner}/${repo}.`);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
// --- Releases ---
|
|
284
|
+
const releases = git
|
|
285
|
+
.command("releases")
|
|
286
|
+
.description("List and publish N - Git releases");
|
|
287
|
+
releases
|
|
288
|
+
.command("list <repo>")
|
|
289
|
+
.description("List releases for <owner>/<repo>")
|
|
290
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
291
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
292
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
293
|
+
const res = await ctx.gitClient.listReleases(owner, repo);
|
|
294
|
+
const items = (res.data?.releases || []);
|
|
295
|
+
ctx.output.data(res.data, () => {
|
|
296
|
+
ctx.output.table([
|
|
297
|
+
"TAG",
|
|
298
|
+
"TITLE",
|
|
299
|
+
"TARGET",
|
|
300
|
+
"CREATED"
|
|
301
|
+
], items.map((r) => [
|
|
302
|
+
String(r.tagName || "-"),
|
|
303
|
+
String(r.title || "-"),
|
|
304
|
+
String(r.target || "-"),
|
|
305
|
+
String(r.createdAt || "-")
|
|
306
|
+
]));
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
releases
|
|
311
|
+
.command("create <repo> <tag>")
|
|
312
|
+
.description("Create and publish a release for <owner>/<repo>")
|
|
313
|
+
.option("--title <title>", "Release title")
|
|
314
|
+
.option("--body <notes>", "Release notes")
|
|
315
|
+
.option("--target <ref>", "Target branch/commitish", "main")
|
|
316
|
+
.option("--draft", "Mark release as draft")
|
|
317
|
+
.option("--prerelease", "Mark release as prerelease")
|
|
318
|
+
.action(async (repoSpec, tag, opts, cmd) => {
|
|
319
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
320
|
+
const { fullName, owner, repo } = parseRepoSpec(repoSpec);
|
|
321
|
+
const safeTag = validateGitRef(tag);
|
|
322
|
+
const safeTarget = validateGitRef(opts.target || "main");
|
|
323
|
+
const res = await ctx.gitClient.createRelease(owner, repo, {
|
|
324
|
+
isPrerelease: Boolean(opts.prerelease),
|
|
325
|
+
targetCommitish: safeTarget,
|
|
326
|
+
isDraft: Boolean(opts.draft),
|
|
327
|
+
title: opts.title || safeTag,
|
|
328
|
+
body: opts.body || "",
|
|
329
|
+
tagName: safeTag
|
|
330
|
+
});
|
|
331
|
+
ctx.output.data(res.data, () => {
|
|
332
|
+
ctx.output.success(`Published release ${safeTag} on ${fullName}.`);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
// --- Webhooks ---
|
|
337
|
+
const webhooks = git
|
|
338
|
+
.command("webhooks")
|
|
339
|
+
.description("Manage repository webhooks");
|
|
340
|
+
webhooks
|
|
341
|
+
.command("list <repo>")
|
|
342
|
+
.description("List webhooks for <owner>/<repo>")
|
|
343
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
344
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
345
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
346
|
+
const res = await ctx.gitClient.listWebhooks(owner, repo);
|
|
347
|
+
const items = (res.data?.webhooks || []);
|
|
348
|
+
ctx.output.data(res.data, () => {
|
|
349
|
+
ctx.output.table([
|
|
350
|
+
"ID",
|
|
351
|
+
"URL",
|
|
352
|
+
"EVENTS",
|
|
353
|
+
"ACTIVE"
|
|
354
|
+
], items.map((w) => [
|
|
355
|
+
String(w.id || "-"),
|
|
356
|
+
String(w.url || "-"),
|
|
357
|
+
Array.isArray(w.events) ? w.events.join(",") : String(w.events || "-"),
|
|
358
|
+
String(w.isActive ?? true)
|
|
359
|
+
]));
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
webhooks
|
|
364
|
+
.command("create <repo>")
|
|
365
|
+
.description("Create a webhook on <owner>/<repo>")
|
|
366
|
+
.requiredOption("--url <url>", "Webhook endpoint URL")
|
|
367
|
+
.option("--events <csv>", "Comma-separated events", "release,deploy")
|
|
368
|
+
.option("--secret <secret>", "HMAC-SHA256 webhook secret")
|
|
369
|
+
.action(async (repoSpec, opts, cmd) => {
|
|
370
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
371
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
372
|
+
const events = String(opts.events || "")
|
|
373
|
+
.split(",")
|
|
374
|
+
.map((e) => e.trim())
|
|
375
|
+
.filter(Boolean);
|
|
376
|
+
const res = await ctx.gitClient.createWebhook(owner, repo, {
|
|
377
|
+
secret: opts.secret,
|
|
378
|
+
url: opts.url,
|
|
379
|
+
events
|
|
380
|
+
});
|
|
381
|
+
ctx.output.data(res.data, () => {
|
|
382
|
+
ctx.output.success(`Created webhook ${String(res.data.id || "")} -> ${opts.url}`);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
webhooks
|
|
387
|
+
.command("test <repo> <hookId>")
|
|
388
|
+
.description("Send a signed ping event to a webhook")
|
|
389
|
+
.action(async (repoSpec, hookId, _opts, cmd) => {
|
|
390
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
391
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
392
|
+
const res = await ctx.gitClient.testWebhook(owner, repo, hookId);
|
|
393
|
+
ctx.output.data(res.data, () => {
|
|
394
|
+
ctx.output.success(`Webhook ${hookId} test dispatched.`);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
webhooks
|
|
399
|
+
.command("delete <repo> <hookId>")
|
|
400
|
+
.description("Delete a webhook from <owner>/<repo>")
|
|
401
|
+
.action(async (repoSpec, hookId, _opts, cmd) => {
|
|
402
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
403
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
404
|
+
const res = await ctx.gitClient.deleteWebhook(owner, repo, hookId);
|
|
405
|
+
ctx.output.data(res.data, () => {
|
|
406
|
+
ctx.output.success(`Deleted webhook ${hookId}.`);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
// --- Runners ---
|
|
411
|
+
const runners = git
|
|
412
|
+
.command("runners")
|
|
413
|
+
.description("Manage self-hosted CI/CD runners registered on N - Git");
|
|
414
|
+
runners
|
|
415
|
+
.command("list <repo>")
|
|
416
|
+
.description("List registered runners for <owner>/<repo>")
|
|
417
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
418
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
419
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
420
|
+
const res = await ctx.gitClient.listRunners(owner, repo);
|
|
421
|
+
const items = (res.data?.runners || []);
|
|
422
|
+
ctx.output.data(res.data, () => {
|
|
423
|
+
ctx.output.table([
|
|
424
|
+
"ID",
|
|
425
|
+
"NAME",
|
|
426
|
+
"STATUS",
|
|
427
|
+
"LAST HEARTBEAT"
|
|
428
|
+
], items.map((r) => [
|
|
429
|
+
String(r.id || "-"),
|
|
430
|
+
String(r.name || "-"),
|
|
431
|
+
String(r.status || (r.online ? "online" : "offline")),
|
|
432
|
+
String(r.lastHeartbeatAt || r.lastSeenAt || "never")
|
|
433
|
+
]));
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
runners
|
|
438
|
+
.command("register <repo>")
|
|
439
|
+
.description("Register a new self-hosted runner on <owner>/<repo>")
|
|
440
|
+
.requiredOption("--name <name>", "Runner display name")
|
|
441
|
+
.option("--url <url>", "Runner webhook URL (https://...)")
|
|
442
|
+
.option("--events <csv>", "Webhook events", "release,deploy")
|
|
443
|
+
.option("--labels <csv>", "Comma-separated runner labels")
|
|
444
|
+
.action(async (repoSpec, opts, cmd) => {
|
|
445
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
446
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
447
|
+
const events = String(opts.events || "")
|
|
448
|
+
.split(",")
|
|
449
|
+
.map((s) => s.trim())
|
|
450
|
+
.filter(Boolean);
|
|
451
|
+
const labels = opts.labels
|
|
452
|
+
? String(opts.labels).split(",").map((s) => s.trim()).filter(Boolean)
|
|
453
|
+
: undefined;
|
|
454
|
+
const res = await ctx.gitClient.registerRunner(owner, repo, {
|
|
455
|
+
webhookUrl: opts.url,
|
|
456
|
+
name: opts.name,
|
|
457
|
+
url: opts.url,
|
|
458
|
+
events,
|
|
459
|
+
labels
|
|
460
|
+
});
|
|
461
|
+
ctx.output.data(res.data, () => {
|
|
462
|
+
const data = res.data;
|
|
463
|
+
ctx.output.success(`Registered runner "${opts.name}" on ${owner}/${repo}.`);
|
|
464
|
+
ctx.output.kv([
|
|
465
|
+
[
|
|
466
|
+
"Runner ID",
|
|
467
|
+
String(data.id || data.runner?.id || "-")
|
|
468
|
+
],
|
|
469
|
+
[
|
|
470
|
+
"Runner Token",
|
|
471
|
+
data.runnerToken ? maskSecret(String(data.runnerToken)) : "-"
|
|
472
|
+
],
|
|
473
|
+
[
|
|
474
|
+
"Webhook Secret",
|
|
475
|
+
data.webhookSecret ? maskSecret(String(data.webhookSecret)) : "-"
|
|
476
|
+
]
|
|
477
|
+
]);
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
runners
|
|
482
|
+
.command("delete <repo> <runnerId>")
|
|
483
|
+
.description("Delete a runner from <owner>/<repo>")
|
|
484
|
+
.action(async (repoSpec, runnerId, _opts, cmd) => {
|
|
485
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
486
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
487
|
+
const res = await ctx.gitClient.deleteRunner(owner, repo, runnerId);
|
|
488
|
+
ctx.output.data(res.data, () => {
|
|
489
|
+
ctx.output.success(`Deleted runner ${runnerId}.`);
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
// --- Deployments ---
|
|
494
|
+
const deployments = git
|
|
495
|
+
.command("deployments")
|
|
496
|
+
.description("Inspect, trigger and stream deployment logs");
|
|
497
|
+
deployments
|
|
498
|
+
.command("list <repo>")
|
|
499
|
+
.description("List recent deployments for <owner>/<repo>")
|
|
500
|
+
.action(async (repoSpec, _opts, cmd) => {
|
|
501
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
502
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
503
|
+
const res = await ctx.gitClient.listDeployments(owner, repo);
|
|
504
|
+
const list = res.data?.deployments || [];
|
|
505
|
+
ctx.output.data(res.data, () => {
|
|
506
|
+
ctx.output.table([
|
|
507
|
+
"ID",
|
|
508
|
+
"REF",
|
|
509
|
+
"STATUS",
|
|
510
|
+
"STAGE",
|
|
511
|
+
"CREATED"
|
|
512
|
+
], list.map((d) => [
|
|
513
|
+
d.id,
|
|
514
|
+
d.releaseTag || d.ref || "-",
|
|
515
|
+
d.status || "-",
|
|
516
|
+
d.stage || "-",
|
|
517
|
+
d.createdAt || "-"
|
|
518
|
+
]));
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
deployments
|
|
523
|
+
.command("trigger <repo>")
|
|
524
|
+
.description("Trigger a manual deployment on <owner>/<repo>")
|
|
525
|
+
.option("--ref <ref>", "Git tag or branch to deploy", "main")
|
|
526
|
+
.action(async (repoSpec, opts, cmd) => {
|
|
527
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
528
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
529
|
+
const safeRef = validateGitRef(opts.ref || "main");
|
|
530
|
+
const res = await ctx.gitClient.triggerDeployment(owner, repo, safeRef);
|
|
531
|
+
ctx.output.data(res.data, () => {
|
|
532
|
+
ctx.output.success(`Triggered deployment for ${owner}/${repo}@${safeRef}.`);
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
deployments
|
|
537
|
+
.command("logs <repo> [deploymentId]")
|
|
538
|
+
.description("Show logs for a deployment (defaults to latest)")
|
|
539
|
+
.action(async (repoSpec, deploymentId, _opts, cmd) => {
|
|
540
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
541
|
+
const { owner, repo } = parseRepoSpec(repoSpec);
|
|
542
|
+
const res = await ctx.gitClient.listDeployments(owner, repo);
|
|
543
|
+
const list = res.data?.deployments || [];
|
|
544
|
+
const target = deploymentId
|
|
545
|
+
? list.find((d) => d.id === deploymentId)
|
|
546
|
+
: list[0];
|
|
547
|
+
if (!target) {
|
|
548
|
+
throw new Error(`Deployment not found for ${owner}/${repo}.`);
|
|
549
|
+
}
|
|
550
|
+
ctx.output.data(target, () => {
|
|
551
|
+
ctx.output.kv([
|
|
552
|
+
[
|
|
553
|
+
"Deployment",
|
|
554
|
+
target.id
|
|
555
|
+
],
|
|
556
|
+
[
|
|
557
|
+
"Status",
|
|
558
|
+
target.status || "-"
|
|
559
|
+
],
|
|
560
|
+
[
|
|
561
|
+
"Stage",
|
|
562
|
+
target.stage || "-"
|
|
563
|
+
],
|
|
564
|
+
[
|
|
565
|
+
"Ref",
|
|
566
|
+
target.releaseTag || target.ref || "-"
|
|
567
|
+
]
|
|
568
|
+
]);
|
|
569
|
+
process.stdout.write(`\n${target.logs || "(no logs)"}\n`);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
// --- OCI Registry ---
|
|
574
|
+
const registry = git
|
|
575
|
+
.command("registry")
|
|
576
|
+
.description("Manage N - Git OCI Docker Container Registry");
|
|
577
|
+
registry
|
|
578
|
+
.command("list")
|
|
579
|
+
.description("List OCI container repositories and tags")
|
|
580
|
+
.action(async (_opts, cmd) => {
|
|
581
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
582
|
+
const res = await ctx.gitClient.listRegistryRepos();
|
|
583
|
+
const items = (res.data?.repositories || []);
|
|
584
|
+
ctx.output.data(res.data, () => {
|
|
585
|
+
ctx.output.table([
|
|
586
|
+
"IMAGE",
|
|
587
|
+
"TAGS",
|
|
588
|
+
"UPDATED"
|
|
589
|
+
], items.map((r) => [
|
|
590
|
+
String(r.fullName || "-"),
|
|
591
|
+
Array.isArray(r.tags) ? r.tags.map((t) => String(t.tag || "")).join(", ") : "-",
|
|
592
|
+
String(r.updatedAt || "-")
|
|
593
|
+
]));
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
registry
|
|
598
|
+
.command("login")
|
|
599
|
+
.description("Authenticate local Docker client with git.nibgat.space via stdin (never CLI args)")
|
|
600
|
+
.option("--host <host>", "OCI registry host", DEFAULT_REGISTRY_HOST)
|
|
601
|
+
.action(async (opts, cmd) => {
|
|
602
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
603
|
+
const host = validateRegistryHost(opts.host || DEFAULT_REGISTRY_HOST);
|
|
604
|
+
const token = (process.env.NCLI_TOKEN || process.env.NGIT_TOKEN || ctx.credentials?.ngitToken || "").trim();
|
|
605
|
+
if (!token) {
|
|
606
|
+
throw new Error("No N - Git PAT available for Docker registry login. Run 'ncli auth login' or 'ncli auth token create --save'.");
|
|
607
|
+
}
|
|
608
|
+
const username = ctx.credentials?.ngitUsername || ctx.credentials?.userName || "token";
|
|
609
|
+
await execSafe("docker", [
|
|
610
|
+
"login",
|
|
611
|
+
host,
|
|
612
|
+
"-u",
|
|
613
|
+
username,
|
|
614
|
+
"--password-stdin"
|
|
615
|
+
], {
|
|
616
|
+
stdinData: `${token}\n`
|
|
617
|
+
});
|
|
618
|
+
ctx.output.data({
|
|
619
|
+
ok: true,
|
|
620
|
+
username,
|
|
621
|
+
host
|
|
622
|
+
}, () => {
|
|
623
|
+
ctx.output.success(`Docker logged in to ${host} as ${username}.`);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
registry
|
|
628
|
+
.command("delete-tag <image> <tag>")
|
|
629
|
+
.description("Delete an OCI image tag (<owner>/<image> <tag>)")
|
|
630
|
+
.action(async (imageSpec, tag, _opts, cmd) => {
|
|
631
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
632
|
+
const { owner, repo: image } = parseRepoSpec(imageSpec);
|
|
633
|
+
const res = await ctx.gitClient.deleteRegistryTag(owner, image, tag);
|
|
634
|
+
ctx.output.data(res.data, () => {
|
|
635
|
+
ctx.output.success(`Deleted tag ${owner}/${image}:${tag}.`);
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
// --- SSH Keys ---
|
|
640
|
+
const sshKeys = git
|
|
641
|
+
.command("ssh-keys")
|
|
642
|
+
.description("Manage SSH public keys on N - Git");
|
|
643
|
+
sshKeys
|
|
644
|
+
.command("list")
|
|
645
|
+
.description("List SSH public keys")
|
|
646
|
+
.action(async (_opts, cmd) => {
|
|
647
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
648
|
+
const res = await ctx.gitClient.listSshKeys();
|
|
649
|
+
const items = (res.data?.sshKeys || []);
|
|
650
|
+
ctx.output.data(res.data, () => {
|
|
651
|
+
ctx.output.table([
|
|
652
|
+
"ID",
|
|
653
|
+
"TITLE",
|
|
654
|
+
"FINGERPRINT",
|
|
655
|
+
"CREATED"
|
|
656
|
+
], items.map((k) => [
|
|
657
|
+
String(k.id || "-"),
|
|
658
|
+
String(k.title || "-"),
|
|
659
|
+
String(k.fingerprint || "-"),
|
|
660
|
+
String(k.created_at || k.createdAt || "-")
|
|
661
|
+
]));
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
sshKeys
|
|
666
|
+
.command("add")
|
|
667
|
+
.description("Add an SSH public key (inline string or file path)")
|
|
668
|
+
.requiredOption("--title <title>", "Key title")
|
|
669
|
+
.requiredOption("--key <keyOrPath>", "Public key string or path to .pub file")
|
|
670
|
+
.action(async (opts, cmd) => {
|
|
671
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
672
|
+
let pubKey = String(opts.key || "").trim();
|
|
673
|
+
if (fs.existsSync(pubKey) && fs.statSync(pubKey).isFile()) {
|
|
674
|
+
pubKey = fs.readFileSync(path.resolve(pubKey), "utf8").trim();
|
|
675
|
+
}
|
|
676
|
+
const res = await ctx.gitClient.addSshKey(opts.title, pubKey);
|
|
677
|
+
ctx.output.data(res.data, () => {
|
|
678
|
+
ctx.output.success(`Added SSH key "${opts.title}" (${String(res.data.fingerprint || "")}).`);
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
sshKeys
|
|
683
|
+
.command("delete <id>")
|
|
684
|
+
.description("Delete an SSH key")
|
|
685
|
+
.action(async (id, _opts, cmd) => {
|
|
686
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
687
|
+
const res = await ctx.gitClient.deleteSshKey(id);
|
|
688
|
+
ctx.output.data(res.data, () => {
|
|
689
|
+
ctx.output.success(`Deleted SSH key ${id}.`);
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
// --- Audit Logs ---
|
|
694
|
+
git
|
|
695
|
+
.command("audits")
|
|
696
|
+
.description("Query N - Git security audit logs")
|
|
697
|
+
.option("--action <action>", "Filter by action prefix or exact name")
|
|
698
|
+
.option("-q, --query <text>", "Search audit target/detail")
|
|
699
|
+
.option("--page <n>", "Page number", (v) => parseInt(v, 10), 1)
|
|
700
|
+
.option("--limit <n>", "Items per page", (v) => parseInt(v, 10), 20)
|
|
701
|
+
.action(async (opts, cmd) => {
|
|
702
|
+
await runCommandAction(cmd, async (ctx) => {
|
|
703
|
+
const res = await ctx.gitClient.listAudits({
|
|
704
|
+
action: opts.action,
|
|
705
|
+
limit: opts.limit,
|
|
706
|
+
page: opts.page,
|
|
707
|
+
q: opts.query
|
|
708
|
+
});
|
|
709
|
+
const items = (res.data?.audits || res.data?.logs || []);
|
|
710
|
+
ctx.output.data(res.data, () => {
|
|
711
|
+
ctx.output.table([
|
|
712
|
+
"TIME",
|
|
713
|
+
"ACTOR",
|
|
714
|
+
"ACTION",
|
|
715
|
+
"TARGET"
|
|
716
|
+
], items.map((a) => [
|
|
717
|
+
String(a.createdAt || "-"),
|
|
718
|
+
String(a.actorUsername || "-"),
|
|
719
|
+
String(a.action || "-"),
|
|
720
|
+
String(a.target || "-")
|
|
721
|
+
]));
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
//# sourceMappingURL=git.js.map
|