@nasebanal/cli 0.9.0 → 0.10.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/README.md +4 -0
- package/dist/reports/ci.js +3 -0
- package/dist/reports/upload.js +49 -3
- package/package.json +1 -1
- package/specs/account.yaml +13 -2
- package/specs/assurance.yaml +15 -1
package/README.md
CHANGED
|
@@ -92,6 +92,10 @@ nb assurance report upload --dir locust/logs/20261001_090000
|
|
|
92
92
|
relative to the repository root, so Assurance can link to the file at that commit.
|
|
93
93
|
A report that CI has just generated is not in the commit, so no path is sent;
|
|
94
94
|
override with `--report-path`.
|
|
95
|
+
The repository's web address is sent too (`repo_url`, detected from `GITHUB_SERVER_URL` /
|
|
96
|
+
`CI_PROJECT_URL`; override with `--repo-url`), so the link also works on a self-hosted
|
|
97
|
+
GitLab or GitHub Enterprise. The CI's repository also replaces the project's `repo`
|
|
98
|
+
(the latest sender wins).
|
|
95
99
|
- **Tie the project to its API in the catalog (`--spec-id`, `--spec-environment`):**
|
|
96
100
|
`--spec-id <id>` links the project to a spec of the API catalog (its id in Assurance /
|
|
97
101
|
Specs), `--spec-environment production` says which environment of it the project covers
|
package/dist/reports/ci.js
CHANGED
|
@@ -61,6 +61,7 @@ export function detectCi(env, git = readGit, now = new Date()) {
|
|
|
61
61
|
ciUrl: repo && runId ? `${server}/${repo}/actions/runs/${runId}` : null,
|
|
62
62
|
project: repo,
|
|
63
63
|
repo,
|
|
64
|
+
repoUrl: repo ? `${server.replace(/\/+$/, "")}/${repo}` : null,
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
if (env.GITLAB_CI === "true") {
|
|
@@ -74,6 +75,7 @@ export function detectCi(env, git = readGit, now = new Date()) {
|
|
|
74
75
|
ciUrl: nonEmpty(env.CI_PIPELINE_URL),
|
|
75
76
|
project: path,
|
|
76
77
|
repo: path && host && host !== "gitlab.com" ? `${host}/${path}` : path,
|
|
78
|
+
repoUrl: nonEmpty(env.CI_PROJECT_URL) ?? (path && host ? `https://${host}/${path}` : null),
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
const { sha, branch } = git();
|
|
@@ -86,5 +88,6 @@ export function detectCi(env, git = readGit, now = new Date()) {
|
|
|
86
88
|
ciUrl: null,
|
|
87
89
|
project: null,
|
|
88
90
|
repo: null,
|
|
91
|
+
repoUrl: null,
|
|
89
92
|
};
|
|
90
93
|
}
|
package/dist/reports/upload.js
CHANGED
|
@@ -60,6 +60,20 @@ export function checkProvider(raw) {
|
|
|
60
60
|
throw new Error(`--provider must be one of ${RUN_PROVIDERS.join(" | ")}`);
|
|
61
61
|
return v;
|
|
62
62
|
}
|
|
63
|
+
/** `--repo-url`: an http(s) address without credentials, query or fragment, as the API accepts it. */
|
|
64
|
+
export function checkRepoUrl(v) {
|
|
65
|
+
let u;
|
|
66
|
+
try {
|
|
67
|
+
u = new URL(v);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new Error("--repo-url must be an http(s) address, e.g. https://gitlab.example.com/group/app");
|
|
71
|
+
}
|
|
72
|
+
if ((u.protocol !== "https:" && u.protocol !== "http:") || u.username || u.password || u.search || u.hash) {
|
|
73
|
+
throw new Error("--repo-url must be an http(s) address without credentials, query or fragment");
|
|
74
|
+
}
|
|
75
|
+
return `${u.origin}${u.pathname.replace(/\/+$/, "")}`;
|
|
76
|
+
}
|
|
63
77
|
/** `--report-path`: a path relative to the repository root, as the API accepts it. */
|
|
64
78
|
export function checkReportPath(raw) {
|
|
65
79
|
const v = raw.trim();
|
|
@@ -218,7 +232,7 @@ export async function ensureProject(conn, name, repo, create, spec) {
|
|
|
218
232
|
const res = await request({ ...conn, method: "GET", path: "/api/v1/projects", query: { name } });
|
|
219
233
|
const list = res.data.data.data;
|
|
220
234
|
const hit = list[0];
|
|
221
|
-
return hit ? { id: hit.id, created: false, spec: { id: hit.spec_id ?? null, environment: hit.spec_environment ?? null } } : null;
|
|
235
|
+
return hit ? { id: hit.id, created: false, repo: hit.repo, spec: { id: hit.spec_id ?? null, environment: hit.spec_environment ?? null } } : null;
|
|
222
236
|
};
|
|
223
237
|
const existing = await find();
|
|
224
238
|
if (existing)
|
|
@@ -234,7 +248,7 @@ export async function ensureProject(conn, name, repo, create, spec) {
|
|
|
234
248
|
// A new project is born linked: nothing to compare, nothing to patch afterwards.
|
|
235
249
|
body: { name, ...(repo ? { repo } : {}), ...(spec ? { spec_id: spec.id, ...(spec.environment ? { spec_environment: spec.environment } : {}) } : {}) },
|
|
236
250
|
});
|
|
237
|
-
return { id: res.data.data.id, created: true, spec: spec ? { id: spec.id, environment: spec.environment ?? null } : undefined, specLinked: !!spec };
|
|
251
|
+
return { id: res.data.data.id, created: true, repo, spec: spec ? { id: spec.id, environment: spec.environment ?? null } : undefined, specLinked: !!spec };
|
|
238
252
|
}
|
|
239
253
|
catch (err) {
|
|
240
254
|
// Another job of the same pipeline created it between our lookup and our create.
|
|
@@ -246,6 +260,21 @@ export async function ensureProject(conn, name, repo, create, spec) {
|
|
|
246
260
|
throw err;
|
|
247
261
|
}
|
|
248
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* The repository the CI reports is the project's repository: the latest sender wins, whether the old value was typed in
|
|
265
|
+
* or came from an earlier upload. (To follow another repository, use another project.) Only a difference is written.
|
|
266
|
+
*/
|
|
267
|
+
async function syncRepo(conn, project, repo) {
|
|
268
|
+
let current = project.repo;
|
|
269
|
+
if (current === undefined) {
|
|
270
|
+
const res = await request({ ...conn, method: "GET", path: `/api/v1/projects/${encodeURIComponent(project.id)}` });
|
|
271
|
+
current = res.data.data.repo ?? null;
|
|
272
|
+
}
|
|
273
|
+
if (current === repo)
|
|
274
|
+
return { changed: false, was: current };
|
|
275
|
+
await request({ ...conn, method: "PATCH", path: `/api/v1/projects/${encodeURIComponent(project.id)}`, body: { repo } });
|
|
276
|
+
return { changed: true, was: current ?? null };
|
|
277
|
+
}
|
|
249
278
|
/**
|
|
250
279
|
* Bring the project's link to the catalog in line with what the CI says. Only what differs is written, so a pipeline that
|
|
251
280
|
* runs on every commit leaves the project untouched once it is linked. Pointing at another spec clears the environment
|
|
@@ -292,6 +321,17 @@ export async function uploadReport(p) {
|
|
|
292
321
|
}
|
|
293
322
|
const data = res.data.data;
|
|
294
323
|
const done = { project_id: project.id, project_created: project.created, ...data };
|
|
324
|
+
if (p.repo) {
|
|
325
|
+
try {
|
|
326
|
+
const synced = await syncRepo(p.conn, project, p.repo);
|
|
327
|
+
if (synced.changed)
|
|
328
|
+
done.repo_changed_from = synced.was;
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
const detail = err instanceof ApiError ? (err.data?.error?.message ?? err.message) : err.message;
|
|
332
|
+
throw new Error(`The result was reported, but the project's repository could not be updated: ${detail}`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
295
335
|
if (p.spec) {
|
|
296
336
|
// The result is in; a link that fails now leaves it as it is and says so.
|
|
297
337
|
try {
|
|
@@ -426,7 +466,8 @@ export function buildReportUploadCommand() {
|
|
|
426
466
|
.option("--spec-org <id>", "with --spec-file: the organization whose catalog it is (an id), or 'personal' (default; or $NB_SPECS_ORG)")
|
|
427
467
|
.option("--spec-environment <name>", "which environment of that API the project covers (production, staging, ...); needs --spec-id")
|
|
428
468
|
.option("--project-id <id>", "send to this project by id (or $NB_ASSURANCE_PROJECT_ID): no lookup by name and nothing is created, so a rename never moves the results; recommended for a pipeline once the project exists")
|
|
429
|
-
.option("--repo <repo>", "repository recorded on
|
|
469
|
+
.option("--repo <repo>", "repository recorded on the project; the latest sender wins (CI: detected)")
|
|
470
|
+
.option("--repo-url <url>", "the repository's web address on its host, e.g. https://gitlab.example.com/group/app (CI: detected); lets Evolution link to the report on a self-hosted GitLab / GitHub Enterprise")
|
|
430
471
|
.option("--provider <provider>", `the CI provider: ${RUN_PROVIDERS.join(" | ")} (CI: detected)`)
|
|
431
472
|
.option("--report-path <path>", "the report file's path in the repository, relative to its root (default: detected, and only for a file committed at the reported commit)")
|
|
432
473
|
.option("--run-key <key>", "identity of the pipeline run (CI: detected); all jobs of a run share it")
|
|
@@ -513,6 +554,7 @@ export function buildReportUploadCommand() {
|
|
|
513
554
|
const branch = opts.branch ?? ci.branch;
|
|
514
555
|
const ciUrl = opts.ciUrl ?? ci.ciUrl;
|
|
515
556
|
const provider = opts.provider !== undefined ? checkProvider(opts.provider) : ci.provider === "local" ? undefined : ci.provider;
|
|
557
|
+
const repoUrl = opts.repoUrl !== undefined ? checkRepoUrl(opts.repoUrl) : ci.repoUrl;
|
|
516
558
|
const reportPath = opts.reportPath !== undefined ? checkReportPath(opts.reportPath) : readReportPath(file, commit);
|
|
517
559
|
if (reportPath)
|
|
518
560
|
parsed.suite.report_path = reportPath;
|
|
@@ -523,6 +565,7 @@ export function buildReportUploadCommand() {
|
|
|
523
565
|
...(branch ? { branch } : {}),
|
|
524
566
|
...(ciUrl ? { ci_url: ciUrl } : {}),
|
|
525
567
|
...(provider ? { provider } : {}),
|
|
568
|
+
...(repoUrl ? { repo_url: repoUrl } : {}),
|
|
526
569
|
},
|
|
527
570
|
suite: parsed.suite,
|
|
528
571
|
};
|
|
@@ -575,6 +618,9 @@ export function buildReportUploadCommand() {
|
|
|
575
618
|
`${attachment ? `, attached ${attachment.name} (${(attachment.bytes.length / 1024).toFixed(0)} KiB)` : ""}` +
|
|
576
619
|
`${pushed ? `, spec ${pushed.name} v${pushed.version} (${pushed.action.replace("_", " ")})` : ""}` +
|
|
577
620
|
`${result.spec ? `, catalog ${result.spec.id}${result.spec.environment ? ` (${result.spec.environment})` : ""} ${result.spec.changed ? (result.spec.was ? `(changed from ${result.spec.was})` : "(linked)") : "(already linked)"}` : ""}\n`);
|
|
621
|
+
if (result.repo_changed_from !== undefined) {
|
|
622
|
+
process.stderr.write(` Repository of the project set to ${repo} (was ${result.repo_changed_from ?? "not set"}); the latest sender wins\n`);
|
|
623
|
+
}
|
|
578
624
|
if (!projectId) {
|
|
579
625
|
process.stderr.write(` Pin it so a rename or a typo cannot send results elsewhere: --project-id ${result.project_id} (or NB_ASSURANCE_PROJECT_ID=${result.project_id})\n`);
|
|
580
626
|
}
|
package/package.json
CHANGED
package/specs/account.yaml
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
openapi: 3.0.3
|
|
2
2
|
info:
|
|
3
3
|
title: NASEBANAL Account API
|
|
4
|
-
description: Centralized user and billing management API for NASEBANAL applications. Manages user profiles, per-service subscriptions,
|
|
5
|
-
version: 1.
|
|
4
|
+
description: Centralized user and billing management API for NASEBANAL applications. Manages user profiles, per-service subscriptions, and Personal Access Tokens (PAT).
|
|
5
|
+
version: 1.7.0
|
|
6
6
|
contact:
|
|
7
7
|
name: NASEBANAL
|
|
8
8
|
url: https://www.nasebanal.com
|
|
@@ -1150,6 +1150,17 @@ components:
|
|
|
1150
1150
|
error:
|
|
1151
1151
|
code: NOT_FOUND
|
|
1152
1152
|
message: Resource not found
|
|
1153
|
+
Gone:
|
|
1154
|
+
description: Billing is not offered
|
|
1155
|
+
content:
|
|
1156
|
+
application/json:
|
|
1157
|
+
schema:
|
|
1158
|
+
$ref: "#/components/schemas/Error"
|
|
1159
|
+
example:
|
|
1160
|
+
success: false
|
|
1161
|
+
error:
|
|
1162
|
+
code: BILLING_NOT_AVAILABLE
|
|
1163
|
+
message: Billing is not offered
|
|
1153
1164
|
Forbidden:
|
|
1154
1165
|
description: Caller is authenticated but lacks the required role or plan
|
|
1155
1166
|
content:
|
package/specs/assurance.yaml
CHANGED
|
@@ -2,7 +2,7 @@ openapi: 3.0.3
|
|
|
2
2
|
info:
|
|
3
3
|
title: NASEBANAL - Assurance API
|
|
4
4
|
description: "Backend of NASEBANAL Assurance (quality assurance for APIs and web apps, under NASEBANAL Evolution). Authenticates users via Auth0 JWT and Personal Access Tokens (PAT) and integrates with the Account API. External monitoring: register URLs to be probed on an interval, then read availability reports. Test results: report the normalised result of each CI/CD job into a named project (typically one per repository), then read its runs and suites. Every response is wrapped as `{ success, data }` (or `{ success: false, error }`)."
|
|
5
|
-
version: 1.
|
|
5
|
+
version: 1.9.0
|
|
6
6
|
contact:
|
|
7
7
|
name: NASEBANAL
|
|
8
8
|
url: https://www.nasebanal.com
|
|
@@ -2669,6 +2669,11 @@ components:
|
|
|
2669
2669
|
nullable: true
|
|
2670
2670
|
maxLength: 20
|
|
2671
2671
|
description: The CI provider the run came from (`github` or `gitlab`; `other` for anything else), when the sender knew it. With the project's repository and the commit it lets a page link to a file in the repository.
|
|
2672
|
+
repo_url:
|
|
2673
|
+
type: string
|
|
2674
|
+
maxLength: 2048
|
|
2675
|
+
nullable: true
|
|
2676
|
+
description: The web address of the repository on its host (for example `https://gitlab.example.com/group/app`), http(s) only, without a trailing slash. Needed to link to a file when the host is not github.com / gitlab.com (a self-hosted GitLab or GitHub Enterprise); otherwise the host is taken from `provider`. Informational.
|
|
2672
2677
|
AttachmentStored:
|
|
2673
2678
|
type: object
|
|
2674
2679
|
description: What was stored for the result.
|
|
@@ -2828,6 +2833,11 @@ components:
|
|
|
2828
2833
|
nullable: true
|
|
2829
2834
|
maxLength: 20
|
|
2830
2835
|
description: The CI provider the run came from (`github` or `gitlab`; `other` for anything else), when the sender knew it. With the project's repository and the commit it lets a page link to a file in the repository.
|
|
2836
|
+
repo_url:
|
|
2837
|
+
type: string
|
|
2838
|
+
maxLength: 2048
|
|
2839
|
+
nullable: true
|
|
2840
|
+
description: The web address of the repository on its host (for example `https://gitlab.example.com/group/app`), http(s) only, without a trailing slash. Needed to link to a file when the host is not github.com / gitlab.com (a self-hosted GitLab or GitHub Enterprise); otherwise the host is taken from `provider`. Informational.
|
|
2831
2841
|
started_at:
|
|
2832
2842
|
type: string
|
|
2833
2843
|
format: date-time
|
|
@@ -2879,6 +2889,10 @@ components:
|
|
|
2879
2889
|
- gitlab
|
|
2880
2890
|
- other
|
|
2881
2891
|
description: The CI provider the run came from (`github` or `gitlab`; `other` for anything else), when the sender knew it. With the project's repository and the commit it lets a page link to a file in the repository.
|
|
2892
|
+
repo_url:
|
|
2893
|
+
type: string
|
|
2894
|
+
maxLength: 2048
|
|
2895
|
+
description: The web address of the repository on its host (for example `https://gitlab.example.com/group/app`), http(s) only, without a trailing slash. Needed to link to a file when the host is not github.com / gitlab.com (a self-hosted GitLab or GitHub Enterprise); otherwise the host is taken from `provider`. Informational.
|
|
2882
2896
|
started_at:
|
|
2883
2897
|
type: string
|
|
2884
2898
|
format: date-time
|