@qawolf/ci-sdk 3.7.0 → 3.8.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 +89 -7
- package/dist/index.js +629 -83
- package/dist/index.js.map +4 -4
- package/dist/lib/sdk/defaults/contracts.d.ts +24 -0
- package/dist/lib/sdk/domain/collectCommitChanges/commitChange.d.ts +22 -0
- package/dist/lib/sdk/domain/collectCommitChanges/fitChanges.d.ts +17 -0
- package/dist/lib/sdk/domain/collectCommitChanges/parseLog.d.ts +7 -5
- package/dist/lib/sdk/domain/collectCommitChanges/readCommitRange.d.ts +32 -0
- package/dist/lib/sdk/domain/collectCommitChanges/summarizeCommits.d.ts +3 -6
- package/dist/lib/sdk/domain/collectDeployChanges/explainCollection.d.ts +8 -0
- package/dist/lib/sdk/domain/collectDeployChanges/filterChanges.d.ts +21 -0
- package/dist/lib/sdk/domain/collectDeployChanges/index.d.ts +18 -0
- package/dist/lib/sdk/domain/collectDeployChanges/isGitHubRepository.d.ts +8 -0
- package/dist/lib/sdk/domain/collectDeployChanges/sendableChanges.d.ts +8 -0
- package/dist/lib/sdk/domain/collectDeployChanges/testHarness.d.ts +46 -0
- package/dist/lib/sdk/domain/collectDeployChanges/types.d.ts +60 -0
- package/dist/lib/sdk/domain/detectProviderDeploymentId/ciSystems.d.ts +16 -0
- package/dist/lib/sdk/domain/detectProviderDeploymentId/index.d.ts +3 -4
- package/dist/lib/sdk/domain/repositoryCoverage/contracts.d.ts +10 -0
- package/dist/lib/sdk/domain/repositoryCoverage/findRepositoryCoverage.d.ts +17 -0
- package/dist/lib/sdk/domain/repositoryCoverage/identifyRepository.d.ts +44 -0
- package/dist/lib/sdk/domain/repositoryCoverage/index.d.ts +15 -0
- package/dist/lib/sdk/domain/repositoryCoverage/testHarness.d.ts +46 -0
- package/dist/lib/sdk/domain/repositoryCoverage/types.d.ts +73 -0
- package/dist/lib/sdk/domain/uploadBuild/types.d.ts +2 -2
- package/dist/lib/sdk/index.d.ts +35 -5
- package/dist/tests/test-lib.d.ts +27 -5
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
4
|
|
|
5
|
-
// src/lib/sdk/domain/detectProviderDeploymentId/
|
|
5
|
+
// src/lib/sdk/domain/detectProviderDeploymentId/ciSystems.ts
|
|
6
6
|
var ciSystems = [
|
|
7
7
|
{
|
|
8
8
|
ci: "github",
|
|
9
9
|
isActive: /* @__PURE__ */ __name((env) => env.GITHUB_ACTIONS === "true", "isActive"),
|
|
10
|
+
name: "GitHub Actions",
|
|
11
|
+
repositoryUrl: /* @__PURE__ */ __name(({ GITHUB_REPOSITORY, GITHUB_SERVER_URL }) => GITHUB_REPOSITORY && GITHUB_SERVER_URL ? `${GITHUB_SERVER_URL.replace(/\/+$/u, "")}/${GITHUB_REPOSITORY}` : void 0, "repositoryUrl"),
|
|
10
12
|
// GITHUB_RUN_ID is stable across re-runs and GITHUB_RUN_ATTEMPT increments,
|
|
11
13
|
// and both are shared by every job in the workflow, so GITHUB_JOB separates
|
|
12
14
|
// jobs that deploy in parallel. GITHUB_JOB names the job definition, which
|
|
@@ -16,12 +18,16 @@ var ciSystems = [
|
|
|
16
18
|
{
|
|
17
19
|
ci: "gitlab",
|
|
18
20
|
isActive: /* @__PURE__ */ __name((env) => env.GITLAB_CI === "true", "isActive"),
|
|
21
|
+
name: "GitLab CI/CD",
|
|
22
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.CI_PROJECT_URL, "repositoryUrl"),
|
|
19
23
|
// Retrying a job keeps the pipeline id and mints a new job id.
|
|
20
24
|
variables: ["CI_PIPELINE_ID", "CI_JOB_ID"]
|
|
21
25
|
},
|
|
22
26
|
{
|
|
23
27
|
ci: "circleci",
|
|
24
28
|
isActive: /* @__PURE__ */ __name((env) => env.CIRCLECI === "true", "isActive"),
|
|
29
|
+
name: "CircleCI",
|
|
30
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.CIRCLE_REPOSITORY_URL, "repositoryUrl"),
|
|
25
31
|
// A rerun keeps the workflow id and allocates a new build number. A job
|
|
26
32
|
// run with `parallelism` shares both across its containers, so those need
|
|
27
33
|
// a discriminator.
|
|
@@ -30,6 +36,8 @@ var ciSystems = [
|
|
|
30
36
|
{
|
|
31
37
|
ci: "buildkite",
|
|
32
38
|
isActive: /* @__PURE__ */ __name((env) => env.BUILDKITE === "true", "isActive"),
|
|
39
|
+
name: "Buildkite",
|
|
40
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.BUILDKITE_REPO, "repositoryUrl"),
|
|
33
41
|
// BUILDKITE_BUILD_ID covers the whole build, so BUILDKITE_JOB_ID separates
|
|
34
42
|
// the jobs within it and BUILDKITE_RETRY_COUNT separates a job's retries.
|
|
35
43
|
variables: [
|
|
@@ -42,6 +50,9 @@ var ciSystems = [
|
|
|
42
50
|
ci: "jenkins",
|
|
43
51
|
// JENKINS_URL is unset on some agent configurations.
|
|
44
52
|
isActive: /* @__PURE__ */ __name((env) => env.JENKINS_URL !== void 0 || env.JENKINS_HOME !== void 0, "isActive"),
|
|
53
|
+
name: "Jenkins",
|
|
54
|
+
// Set by the Git plugin when the job checks out a repository.
|
|
55
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.GIT_URL, "repositoryUrl"),
|
|
45
56
|
// BUILD_TAG is `jenkins-${JOB_NAME}-${BUILD_NUMBER}`, and Jenkins allocates
|
|
46
57
|
// a fresh BUILD_NUMBER for every externally visible re-run — Rebuild,
|
|
47
58
|
// Naginator, Replay and Restart from Stage — so it needs no attempt
|
|
@@ -53,6 +64,8 @@ var ciSystems = [
|
|
|
53
64
|
{
|
|
54
65
|
ci: "bitbucket",
|
|
55
66
|
isActive: /* @__PURE__ */ __name((env) => env.BITBUCKET_WORKSPACE !== void 0 || env.BITBUCKET_BUILD_NUMBER !== void 0, "isActive"),
|
|
67
|
+
name: "Bitbucket Pipelines",
|
|
68
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.BITBUCKET_GIT_HTTP_ORIGIN, "repositoryUrl"),
|
|
56
69
|
// Rerunning a whole pipeline mints a new build number, but rerunning only
|
|
57
70
|
// the failed steps keeps it and increments the step's run number instead.
|
|
58
71
|
// Parallel steps share both, so BITBUCKET_STEP_UUID separates them.
|
|
@@ -61,13 +74,28 @@ var ciSystems = [
|
|
|
61
74
|
"BITBUCKET_STEP_UUID",
|
|
62
75
|
"BITBUCKET_STEP_RUN_NUMBER"
|
|
63
76
|
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
ci: "azure-pipelines",
|
|
80
|
+
isActive: /* @__PURE__ */ __name((env) => env.TF_BUILD?.toLowerCase() === "true", "isActive"),
|
|
81
|
+
name: "Azure Pipelines",
|
|
82
|
+
repositoryUrl: /* @__PURE__ */ __name((env) => env.BUILD_REPOSITORY_URI, "repositoryUrl"),
|
|
83
|
+
// Rerunning failed jobs keeps the build id and increments the job's
|
|
84
|
+
// attempt. Every job, including each leg of a matrix, has its own job id.
|
|
85
|
+
variables: ["BUILD_BUILDID", "SYSTEM_JOBID", "SYSTEM_JOBATTEMPT"]
|
|
64
86
|
}
|
|
65
87
|
];
|
|
88
|
+
function detectCiSystem(env) {
|
|
89
|
+
return ciSystems.find((candidate) => candidate.isActive(env));
|
|
90
|
+
}
|
|
91
|
+
__name(detectCiSystem, "detectCiSystem");
|
|
92
|
+
|
|
93
|
+
// src/lib/sdk/domain/detectProviderDeploymentId/index.ts
|
|
66
94
|
function detectProviderDeploymentId({
|
|
67
95
|
discriminator,
|
|
68
96
|
env = process.env
|
|
69
97
|
} = {}) {
|
|
70
|
-
const system =
|
|
98
|
+
const system = detectCiSystem(env);
|
|
71
99
|
if (!system) return { outcome: "unsupported" };
|
|
72
100
|
const missingVariables = system.variables.filter((name) => !env[name]);
|
|
73
101
|
if (missingVariables.length > 0)
|
|
@@ -101,6 +129,14 @@ var buildFetchWithTimeout = /* @__PURE__ */ __name((fetch, defaultTimeoutMs) =>
|
|
|
101
129
|
// src/lib/sdk/defaults/clock.ts
|
|
102
130
|
var defaultClock = { now: /* @__PURE__ */ __name(() => Date.now(), "now"), sleep };
|
|
103
131
|
|
|
132
|
+
// src/lib/sdk/defaults/contracts.ts
|
|
133
|
+
import * as apiContracts from "@qawolf/api-contracts";
|
|
134
|
+
var installed = apiContracts;
|
|
135
|
+
var changesSchema = installed.publicContractsV1.deployment?.reportStatus?.input?.shape?.changes;
|
|
136
|
+
var defaultCoverageContracts = installed.publicContractsV1;
|
|
137
|
+
var defaultRedact = installed.redactReportedText;
|
|
138
|
+
var defaultAcceptsChange = changesSchema && ((change) => changesSchema.safeParse({ items: [change] }).success);
|
|
139
|
+
|
|
104
140
|
// src/lib/sdk/defaults/fetch.ts
|
|
105
141
|
var defaultFetch = globalThis.fetch;
|
|
106
142
|
|
|
@@ -123,7 +159,7 @@ var defaultServiceBase = "https://app.qawolf.com/";
|
|
|
123
159
|
// package.json
|
|
124
160
|
var package_default = {
|
|
125
161
|
name: "@qawolf/ci-sdk",
|
|
126
|
-
version: "3.
|
|
162
|
+
version: "3.8.0",
|
|
127
163
|
private: false,
|
|
128
164
|
description: "A simple SDK for interacting with QAWolf in CI scripts.",
|
|
129
165
|
keywords: [],
|
|
@@ -136,6 +172,7 @@ var package_default = {
|
|
|
136
172
|
},
|
|
137
173
|
files: [
|
|
138
174
|
"/dist",
|
|
175
|
+
"/LICENSE",
|
|
139
176
|
"/README.md"
|
|
140
177
|
],
|
|
141
178
|
type: "module",
|
|
@@ -148,16 +185,16 @@ var package_default = {
|
|
|
148
185
|
},
|
|
149
186
|
scripts: {
|
|
150
187
|
build: "platform-builder --config platformBuilder.config.ts",
|
|
151
|
-
"lint:ci": "
|
|
152
|
-
"lint:dev": "
|
|
153
|
-
"lint:first-half": "oxlint . --fix --quiet --report-unused-disable-directives --type-aware && oxfmt --write .",
|
|
188
|
+
"lint:ci": "pnpm run lint:first-half; FIRST_HALF_EXIT=$?; pnpm run lint:second-half && exit $FIRST_HALF_EXIT",
|
|
189
|
+
"lint:dev": "pnpm run lint:first-half",
|
|
190
|
+
"lint:first-half": "oxfmt --write . && { oxlint . --fix --quiet --report-unused-disable-directives --type-aware || { oxfmt --write . && oxlint . --fix --quiet --report-unused-disable-directives --type-aware; }; } && oxfmt --write .",
|
|
154
191
|
"lint:second-half": "rev-dep config run",
|
|
155
192
|
prepublishOnly: "nx run ci-sdk:build",
|
|
156
193
|
test: 'NODE_OPTIONS="--experimental-vm-modules" NODE_NO_WARNINGS=1 jest',
|
|
157
|
-
"tsc:check": "
|
|
194
|
+
"tsc:check": "tsrs --noEmit"
|
|
158
195
|
},
|
|
159
196
|
dependencies: {
|
|
160
|
-
"@qawolf/api-contracts": ">=0.
|
|
197
|
+
"@qawolf/api-contracts": ">=0.148.0",
|
|
161
198
|
"@qawolf/ci-utils": "^2.0.0",
|
|
162
199
|
"@sinonjs/fake-timers": "^10.3.0",
|
|
163
200
|
superjson: "^2.2.6",
|
|
@@ -167,7 +204,7 @@ var package_default = {
|
|
|
167
204
|
devDependencies: {
|
|
168
205
|
"@qawolf/platform-builder": "^1.2.7",
|
|
169
206
|
tsx: "^4.19.4",
|
|
170
|
-
typescript: "^
|
|
207
|
+
typescript: "^6.0.3"
|
|
171
208
|
},
|
|
172
209
|
engines: {
|
|
173
210
|
node: ">=24.14.1 <25"
|
|
@@ -521,32 +558,7 @@ ${stderr}` : error.message
|
|
|
521
558
|
});
|
|
522
559
|
}), "defaultGitDriver");
|
|
523
560
|
|
|
524
|
-
// src/lib/sdk/domain/collectCommitChanges/
|
|
525
|
-
var logFormat = "%H%x00%s%x00%b%x00";
|
|
526
|
-
var hashPattern = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/u;
|
|
527
|
-
var fieldsBeforePaths = 4;
|
|
528
|
-
function parseLog(stdout) {
|
|
529
|
-
const tokens = stdout.split("\0");
|
|
530
|
-
const starts = tokens.reduce((found, token, index) => {
|
|
531
|
-
const previous = found.at(-1);
|
|
532
|
-
const canStart = previous === void 0 ? index === 0 : index >= previous + fieldsBeforePaths;
|
|
533
|
-
return canStart && hashPattern.test(token) ? [...found, index] : found;
|
|
534
|
-
}, []);
|
|
535
|
-
return starts.map((start, position) => {
|
|
536
|
-
const [, subject = "", body = "", , ...paths] = tokens.slice(
|
|
537
|
-
start,
|
|
538
|
-
starts[position + 1] ?? tokens.length
|
|
539
|
-
);
|
|
540
|
-
return {
|
|
541
|
-
body: body.trim(),
|
|
542
|
-
paths: paths.map((path) => path.replace(/^\n/u, "")).filter((path) => path.length > 0),
|
|
543
|
-
subject: subject.trim()
|
|
544
|
-
};
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
__name(parseLog, "parseLog");
|
|
548
|
-
|
|
549
|
-
// src/lib/sdk/domain/collectCommitChanges/summarizeCommits.ts
|
|
561
|
+
// src/lib/sdk/domain/collectCommitChanges/fitChanges.ts
|
|
550
562
|
var maxItems = 250;
|
|
551
563
|
var maxTitleLength = 512;
|
|
552
564
|
var maxDescriptionLength = 4e3;
|
|
@@ -557,35 +569,15 @@ var maxBytes = 256 * 1024;
|
|
|
557
569
|
var maxBytesPerItem = maxBytes / 8;
|
|
558
570
|
var cut = /* @__PURE__ */ __name((text, max) => text.length > max ? text.slice(0, max) : text, "cut");
|
|
559
571
|
var byteLengthOf = /* @__PURE__ */ __name((value) => new TextEncoder().encode(JSON.stringify(value)).length, "byteLengthOf");
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
function readMessage({ body, subject }) {
|
|
564
|
-
if (mergeSubjectPattern.test(subject) && body.length > 0) {
|
|
565
|
-
const [firstLine = "", ...rest] = body.replace(mergeRequestTrailerPattern, "").trim().split("\n");
|
|
566
|
-
return {
|
|
567
|
-
description: rest.join("\n").trim(),
|
|
568
|
-
kind: "pull-request",
|
|
569
|
-
// A GitLab merge commit can hold only the trailer.
|
|
570
|
-
title: firstLine.trim() || subject
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
return {
|
|
574
|
-
description: body,
|
|
575
|
-
kind: squashSubjectPattern.test(subject) ? "pull-request" : "commit",
|
|
576
|
-
title: subject
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
__name(readMessage, "readMessage");
|
|
580
|
-
function toItem(commit, { descriptions, paths }) {
|
|
581
|
-
const { description, kind, title } = readMessage(commit);
|
|
582
|
-
const keptPaths = commit.paths.filter((path) => path.length <= maxPathLength).slice(0, maxPathsPerItem);
|
|
572
|
+
function fitItem(item) {
|
|
573
|
+
const { changedPaths = [], description, title, ...rest } = item;
|
|
574
|
+
const keptPaths = changedPaths.filter((path) => path.length <= maxPathLength).slice(0, maxPathsPerItem);
|
|
583
575
|
const withPaths = /* @__PURE__ */ __name((count) => ({
|
|
584
|
-
...
|
|
585
|
-
...
|
|
576
|
+
...count > 0 && { changedPaths: keptPaths.slice(0, count) },
|
|
577
|
+
...description !== void 0 && {
|
|
586
578
|
description: cut(description, maxDescriptionLength)
|
|
587
579
|
},
|
|
588
|
-
|
|
580
|
+
...rest,
|
|
589
581
|
title: cut(title, maxTitleLength)
|
|
590
582
|
}), "withPaths");
|
|
591
583
|
const fits = /* @__PURE__ */ __name((count) => byteLengthOf(withPaths(count)) <= maxBytesPerItem, "fits");
|
|
@@ -593,24 +585,18 @@ function toItem(commit, { descriptions, paths }) {
|
|
|
593
585
|
fits(keptPaths.length) ? keptPaths.length : largestFittingCount(keptPaths.length, fits)
|
|
594
586
|
);
|
|
595
587
|
}
|
|
596
|
-
__name(
|
|
597
|
-
function
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
includePaths,
|
|
588
|
+
__name(fitItem, "fitItem");
|
|
589
|
+
function fitChanges({
|
|
590
|
+
extra,
|
|
591
|
+
items,
|
|
601
592
|
releaseNotes,
|
|
602
593
|
totalCount
|
|
603
594
|
}) {
|
|
604
|
-
const items = commits.filter(({ subject }) => subject.length > 0).map(
|
|
605
|
-
(commit) => toItem(commit, {
|
|
606
|
-
descriptions: includeDescriptions,
|
|
607
|
-
paths: includePaths
|
|
608
|
-
})
|
|
609
|
-
);
|
|
610
595
|
const notes = releaseNotes?.trim();
|
|
611
596
|
const summaryOf = /* @__PURE__ */ __name((count) => {
|
|
612
597
|
const omittedCount = Math.max(totalCount, items.length) - count;
|
|
613
598
|
return {
|
|
599
|
+
...extra,
|
|
614
600
|
...count > 0 && { items: items.slice(0, count) },
|
|
615
601
|
...omittedCount > 0 && { omittedCount },
|
|
616
602
|
...notes && { releaseNotes: cut(notes, maxReleaseNotesLength) }
|
|
@@ -623,7 +609,7 @@ function summarizeCommits({
|
|
|
623
609
|
)
|
|
624
610
|
);
|
|
625
611
|
}
|
|
626
|
-
__name(
|
|
612
|
+
__name(fitChanges, "fitChanges");
|
|
627
613
|
function largestFittingCount(max, fits) {
|
|
628
614
|
const search = /* @__PURE__ */ __name((low, high) => {
|
|
629
615
|
if (low >= high) return low;
|
|
@@ -634,13 +620,40 @@ function largestFittingCount(max, fits) {
|
|
|
634
620
|
}
|
|
635
621
|
__name(largestFittingCount, "largestFittingCount");
|
|
636
622
|
|
|
637
|
-
// src/lib/sdk/domain/collectCommitChanges/
|
|
623
|
+
// src/lib/sdk/domain/collectCommitChanges/parseLog.ts
|
|
624
|
+
var logFormat = "%x00%H%x00%s%x00%b%x00";
|
|
625
|
+
var headerLength = 5;
|
|
626
|
+
function readRecords(tokens, start) {
|
|
627
|
+
const sha2 = tokens[start + 1];
|
|
628
|
+
if (!sha2) return [];
|
|
629
|
+
const pathsStart = start + headerLength;
|
|
630
|
+
const pathsEnd = tokens.indexOf("", pathsStart);
|
|
631
|
+
const paths = tokens.slice(
|
|
632
|
+
pathsStart,
|
|
633
|
+
pathsEnd === -1 ? tokens.length : pathsEnd
|
|
634
|
+
);
|
|
635
|
+
return [
|
|
636
|
+
{
|
|
637
|
+
body: (tokens[start + 3] ?? "").trim(),
|
|
638
|
+
paths: paths.map((path) => path.replace(/^\n/u, "")),
|
|
639
|
+
sha: sha2,
|
|
640
|
+
subject: (tokens[start + 2] ?? "").trim()
|
|
641
|
+
},
|
|
642
|
+
...readRecords(tokens, pathsStart + paths.length)
|
|
643
|
+
];
|
|
644
|
+
}
|
|
645
|
+
__name(readRecords, "readRecords");
|
|
646
|
+
function parseLog(stdout) {
|
|
647
|
+
return readRecords(stdout.split("\0"), 0);
|
|
648
|
+
}
|
|
649
|
+
__name(parseLog, "parseLog");
|
|
650
|
+
|
|
651
|
+
// src/lib/sdk/domain/collectCommitChanges/readCommitRange.ts
|
|
638
652
|
var historyFix = "Fetch the full history before collecting changes, e.g. `fetch-depth: 0` on actions/checkout, or `git fetch --unshallow`.";
|
|
639
653
|
var sinceFix = /* @__PURE__ */ __name((since) => `Check that ${JSON.stringify(since)} names a commit or tag, and fetch it first if it's a tag, e.g. \`git fetch --tags\`.`, "sinceFix");
|
|
640
|
-
async function
|
|
641
|
-
cwd
|
|
642
|
-
|
|
643
|
-
releaseNotes,
|
|
654
|
+
async function readCommitRange(git, {
|
|
655
|
+
cwd,
|
|
656
|
+
includePaths,
|
|
644
657
|
since
|
|
645
658
|
}) {
|
|
646
659
|
const shallow = await git(["rev-parse", "--is-shallow-repository"], cwd);
|
|
@@ -664,7 +677,6 @@ async function collectCommitChanges(git, {
|
|
|
664
677
|
cwd
|
|
665
678
|
);
|
|
666
679
|
if (!count.ok) return { message: count.stderr, outcome: "git-failed" };
|
|
667
|
-
const includePaths = include.includes("paths");
|
|
668
680
|
const log = await git(
|
|
669
681
|
[
|
|
670
682
|
"log",
|
|
@@ -679,21 +691,125 @@ async function collectCommitChanges(git, {
|
|
|
679
691
|
cwd
|
|
680
692
|
);
|
|
681
693
|
if (!log.ok) return { message: log.stderr, outcome: "git-failed" };
|
|
694
|
+
return {
|
|
695
|
+
commits: parseLog(log.stdout),
|
|
696
|
+
outcome: "read",
|
|
697
|
+
totalCount: Number(count.stdout.trim())
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
__name(readCommitRange, "readCommitRange");
|
|
701
|
+
|
|
702
|
+
// src/lib/sdk/domain/collectCommitChanges/commitChange.ts
|
|
703
|
+
var mergeSubjectPattern = /^Merge (pull request #\d+|branch .+ into )/u;
|
|
704
|
+
var squashSubjectPattern = /\(#(\d+)\)$/u;
|
|
705
|
+
var mergeRequestTrailerPattern = /^See merge request \S+$/mu;
|
|
706
|
+
var pullRequestNumberPattern = /^Merge pull request #(\d+)/u;
|
|
707
|
+
var mergeRequestNumberPattern = /^See merge request \S+!(\d+)$/mu;
|
|
708
|
+
function numberOf(match) {
|
|
709
|
+
const number2 = Number(match?.[1]);
|
|
710
|
+
return Number.isSafeInteger(number2) && number2 > 0 ? number2 : void 0;
|
|
711
|
+
}
|
|
712
|
+
__name(numberOf, "numberOf");
|
|
713
|
+
function readMessage({ body, subject }, { squashedPullRequests }) {
|
|
714
|
+
if (mergeSubjectPattern.test(subject) && body.length > 0) {
|
|
715
|
+
const [firstLine = "", ...rest] = body.replace(mergeRequestTrailerPattern, "").trim().split("\n");
|
|
716
|
+
return {
|
|
717
|
+
description: rest.join("\n").trim(),
|
|
718
|
+
kind: "pull-request",
|
|
719
|
+
number: numberOf(
|
|
720
|
+
pullRequestNumberPattern.exec(subject) ?? mergeRequestNumberPattern.exec(body)
|
|
721
|
+
),
|
|
722
|
+
// A GitLab merge commit can hold only the trailer.
|
|
723
|
+
title: firstLine.trim() || subject
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const squashed = squashedPullRequests && squashSubjectPattern.test(subject);
|
|
727
|
+
return {
|
|
728
|
+
description: body,
|
|
729
|
+
kind: squashed ? "pull-request" : "commit",
|
|
730
|
+
number: squashed ? numberOf(squashSubjectPattern.exec(subject)) : void 0,
|
|
731
|
+
title: subject
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
__name(readMessage, "readMessage");
|
|
735
|
+
function changeOfCommit(commit, {
|
|
736
|
+
descriptions,
|
|
737
|
+
ids,
|
|
738
|
+
paths,
|
|
739
|
+
squashedPullRequests
|
|
740
|
+
}) {
|
|
741
|
+
const { description, kind, number: number2, title } = readMessage(commit, {
|
|
742
|
+
squashedPullRequests
|
|
743
|
+
});
|
|
744
|
+
const content = {
|
|
745
|
+
...paths && commit.paths.length > 0 && { changedPaths: commit.paths },
|
|
746
|
+
...descriptions && description.length > 0 && { description },
|
|
747
|
+
title
|
|
748
|
+
};
|
|
749
|
+
if (kind === "commit")
|
|
750
|
+
return { ...content, kind, ...ids && { sha: commit.sha } };
|
|
751
|
+
return {
|
|
752
|
+
...content,
|
|
753
|
+
kind,
|
|
754
|
+
...ids && {
|
|
755
|
+
mergeCommitSha: commit.sha,
|
|
756
|
+
...number2 !== void 0 && { number: number2 }
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
__name(changeOfCommit, "changeOfCommit");
|
|
761
|
+
|
|
762
|
+
// src/lib/sdk/domain/collectCommitChanges/summarizeCommits.ts
|
|
763
|
+
function summarizeCommits({
|
|
764
|
+
commits,
|
|
765
|
+
includeDescriptions,
|
|
766
|
+
includePaths,
|
|
767
|
+
releaseNotes,
|
|
768
|
+
totalCount
|
|
769
|
+
}) {
|
|
770
|
+
return fitChanges({
|
|
771
|
+
extra: {},
|
|
772
|
+
items: commits.filter(({ subject }) => subject.length > 0).map(
|
|
773
|
+
(commit) => fitItem(
|
|
774
|
+
changeOfCommit(commit, {
|
|
775
|
+
descriptions: includeDescriptions,
|
|
776
|
+
ids: false,
|
|
777
|
+
paths: includePaths,
|
|
778
|
+
squashedPullRequests: true
|
|
779
|
+
})
|
|
780
|
+
)
|
|
781
|
+
),
|
|
782
|
+
releaseNotes,
|
|
783
|
+
totalCount
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
__name(summarizeCommits, "summarizeCommits");
|
|
787
|
+
|
|
788
|
+
// src/lib/sdk/domain/collectCommitChanges/index.ts
|
|
789
|
+
async function collectCommitChanges(git, {
|
|
790
|
+
cwd = process.cwd(),
|
|
791
|
+
include = ["titles"],
|
|
792
|
+
releaseNotes,
|
|
793
|
+
since
|
|
794
|
+
}) {
|
|
795
|
+
const includePaths = include.includes("paths");
|
|
796
|
+
const range = await readCommitRange(git, { cwd, includePaths, since });
|
|
797
|
+
if (range.outcome !== "read") return range;
|
|
682
798
|
return {
|
|
683
799
|
changes: summarizeCommits({
|
|
684
|
-
commits:
|
|
800
|
+
commits: range.commits,
|
|
685
801
|
includeDescriptions: include.includes("descriptions"),
|
|
686
802
|
includePaths,
|
|
687
803
|
releaseNotes,
|
|
688
|
-
totalCount:
|
|
804
|
+
totalCount: range.totalCount
|
|
689
805
|
}),
|
|
690
806
|
outcome: "collected"
|
|
691
807
|
};
|
|
692
808
|
}
|
|
693
809
|
__name(collectCommitChanges, "collectCommitChanges");
|
|
694
810
|
|
|
695
|
-
// src/lib/sdk/domain/
|
|
696
|
-
import {
|
|
811
|
+
// src/lib/sdk/domain/repositoryCoverage/findRepositoryCoverage.ts
|
|
812
|
+
import { z } from "zod";
|
|
697
813
|
|
|
698
814
|
// src/lib/sdk/publicApi/trpcEnvelope.ts
|
|
699
815
|
import superjson from "superjson";
|
|
@@ -808,6 +924,413 @@ async function callPublicContract({ fetch: localFetch, log }, apiConfig, {
|
|
|
808
924
|
}
|
|
809
925
|
__name(callPublicContract, "callPublicContract");
|
|
810
926
|
|
|
927
|
+
// src/lib/sdk/domain/repositoryCoverage/findRepositoryCoverage.ts
|
|
928
|
+
var minimumContractsVersion = "0.148.0";
|
|
929
|
+
var answerSchema = z.object({
|
|
930
|
+
coverage: z.string(),
|
|
931
|
+
fullName: z.string().optional(),
|
|
932
|
+
permissions: z.object({ code: z.string(), pullRequests: z.string() }).optional(),
|
|
933
|
+
provider: z.string().optional(),
|
|
934
|
+
settingsUrl: z.string().optional()
|
|
935
|
+
});
|
|
936
|
+
function coverageOf({
|
|
937
|
+
coverage,
|
|
938
|
+
fullName,
|
|
939
|
+
permissions,
|
|
940
|
+
provider,
|
|
941
|
+
settingsUrl
|
|
942
|
+
}) {
|
|
943
|
+
if (coverage === "covered" && fullName && permissions && provider) {
|
|
944
|
+
return {
|
|
945
|
+
fullName,
|
|
946
|
+
permissions,
|
|
947
|
+
provider,
|
|
948
|
+
settingsUrl,
|
|
949
|
+
status: coverage
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
if (coverage === "not-covered") return { settingsUrl, status: coverage };
|
|
953
|
+
if (coverage === "unsupported-host") return { status: coverage };
|
|
954
|
+
if (coverage === "unrecognized-url") {
|
|
955
|
+
return {
|
|
956
|
+
message: "QA Wolf doesn't recognize the URL as a repository URL.",
|
|
957
|
+
reason: "unrecognized-url",
|
|
958
|
+
status: "unknown"
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
return {
|
|
962
|
+
message: `QA Wolf answered with a coverage this SDK version doesn't know (${JSON.stringify(coverage)}).`,
|
|
963
|
+
reason: "unexpected-answer",
|
|
964
|
+
status: "unknown"
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
__name(coverageOf, "coverageOf");
|
|
968
|
+
async function findRepositoryCoverage(deps, apiConfig, { url, workspaceId }) {
|
|
969
|
+
const contract = deps.contracts.codeHostIntegration?.findForRepository;
|
|
970
|
+
if (!contract) {
|
|
971
|
+
return {
|
|
972
|
+
message: `The installed @qawolf/api-contracts can't check a repository. Install version ${minimumContractsVersion} or later.`,
|
|
973
|
+
reason: "outdated-contracts",
|
|
974
|
+
status: "unknown"
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
const lenientContract = {
|
|
978
|
+
input: contract.input,
|
|
979
|
+
kind: contract.kind,
|
|
980
|
+
name: contract.name,
|
|
981
|
+
output: answerSchema
|
|
982
|
+
};
|
|
983
|
+
const result = await callPublicContract(deps, apiConfig, {
|
|
984
|
+
contract: lenientContract,
|
|
985
|
+
input: { url, ...workspaceId !== void 0 && { workspaceId } }
|
|
986
|
+
});
|
|
987
|
+
if (result.outcome === "ok") return coverageOf(result.data);
|
|
988
|
+
if (result.outcome === "invalid-response-body") {
|
|
989
|
+
return {
|
|
990
|
+
message: "QA Wolf answered with a body this SDK version can't read.",
|
|
991
|
+
reason: "unexpected-answer",
|
|
992
|
+
status: "unknown"
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
return {
|
|
996
|
+
message: result.outcome === "http-error" ? `QA Wolf answered HTTP ${result.httpStatus}${result.message ? `: ${result.message}` : ""}.` : "The request didn't reach QA Wolf.",
|
|
997
|
+
reason: "request-failed",
|
|
998
|
+
status: "unknown"
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
__name(findRepositoryCoverage, "findRepositoryCoverage");
|
|
1002
|
+
|
|
1003
|
+
// src/lib/sdk/domain/repositoryCoverage/identifyRepository.ts
|
|
1004
|
+
var scpLike = /^([^@/\s]+)@([^@/:\s]+:(?!\/\/).*)$/u;
|
|
1005
|
+
function withoutCredentials(url) {
|
|
1006
|
+
const trimmed = url.trim();
|
|
1007
|
+
if (scpLike.test(trimmed)) return trimmed.replace(scpLike, "git@$2");
|
|
1008
|
+
if (!URL.canParse(trimmed)) return trimmed;
|
|
1009
|
+
const parsed = new URL(trimmed);
|
|
1010
|
+
const { hash, password, search, username } = parsed;
|
|
1011
|
+
const carriesNothing = password === "" && (username === "" || username === "git") && search === "" && hash === "";
|
|
1012
|
+
if (carriesNothing) return trimmed;
|
|
1013
|
+
parsed.username = "";
|
|
1014
|
+
parsed.password = "";
|
|
1015
|
+
parsed.search = "";
|
|
1016
|
+
parsed.hash = "";
|
|
1017
|
+
return parsed.toString();
|
|
1018
|
+
}
|
|
1019
|
+
__name(withoutCredentials, "withoutCredentials");
|
|
1020
|
+
function hostOf(url) {
|
|
1021
|
+
const scp = /^[^@/\s]+@([^@/:\s]+):(?!\/\/)/u.exec(url);
|
|
1022
|
+
if (scp) return scp[1];
|
|
1023
|
+
if (!URL.canParse(url)) return void 0;
|
|
1024
|
+
const parsed = new URL(url);
|
|
1025
|
+
return (parsed.protocol === "ssh:" ? parsed.hostname : parsed.host) || void 0;
|
|
1026
|
+
}
|
|
1027
|
+
__name(hostOf, "hostOf");
|
|
1028
|
+
var repositoryUrl = /* @__PURE__ */ __name((fullName, host) => `https://${host.split(":").map(encodeURIComponent).join(":")}/${fullName.split("/").filter(Boolean).map(encodeURIComponent).join("/")}`, "repositoryUrl");
|
|
1029
|
+
function isRepositoryInput(repository) {
|
|
1030
|
+
if (typeof repository !== "object" || repository === null) return false;
|
|
1031
|
+
if (!("type" in repository)) return false;
|
|
1032
|
+
if (repository.type === "url")
|
|
1033
|
+
return "url" in repository && typeof repository.url === "string";
|
|
1034
|
+
if (repository.type !== "full-name") return false;
|
|
1035
|
+
const host = "host" in repository ? repository.host : void 0;
|
|
1036
|
+
return "fullName" in repository && typeof repository.fullName === "string" && (host === void 0 || typeof host === "string");
|
|
1037
|
+
}
|
|
1038
|
+
__name(isRepositoryInput, "isRepositoryInput");
|
|
1039
|
+
async function detectedUrl(git, { cwd, env }) {
|
|
1040
|
+
const fromCi = detectCiSystem(env)?.repositoryUrl(env)?.trim();
|
|
1041
|
+
if (fromCi) return { source: "ci", url: withoutCredentials(fromCi) };
|
|
1042
|
+
const remote = await git(["remote", "get-url", "origin"], cwd);
|
|
1043
|
+
const fromRemote = remote.ok ? remote.stdout.trim() : "";
|
|
1044
|
+
return fromRemote ? { source: "git-remote", url: withoutCredentials(fromRemote) } : void 0;
|
|
1045
|
+
}
|
|
1046
|
+
__name(detectedUrl, "detectedUrl");
|
|
1047
|
+
async function identifyRepository(git, {
|
|
1048
|
+
cwd,
|
|
1049
|
+
env,
|
|
1050
|
+
repository
|
|
1051
|
+
}) {
|
|
1052
|
+
if (repository === void 0) return detectedUrl(git, { cwd, env });
|
|
1053
|
+
switch (repository.type) {
|
|
1054
|
+
case "full-name": {
|
|
1055
|
+
const detected = repository.host ? void 0 : await detectedUrl(git, { cwd, env });
|
|
1056
|
+
const host = repository.host?.trim() || detected && hostOf(detected.url) || "github.com";
|
|
1057
|
+
return {
|
|
1058
|
+
source: "input",
|
|
1059
|
+
url: repositoryUrl(repository.fullName.trim(), host)
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
case "url":
|
|
1063
|
+
return { source: "input", url: withoutCredentials(repository.url) };
|
|
1064
|
+
default:
|
|
1065
|
+
repository;
|
|
1066
|
+
throw Error("Unexpected repository type");
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
__name(identifyRepository, "identifyRepository");
|
|
1070
|
+
|
|
1071
|
+
// src/lib/sdk/domain/repositoryCoverage/index.ts
|
|
1072
|
+
async function findCoverageOfRepository(deps, apiConfig, {
|
|
1073
|
+
cwd = process.cwd(),
|
|
1074
|
+
env = process.env,
|
|
1075
|
+
repository,
|
|
1076
|
+
workspaceId
|
|
1077
|
+
} = {}) {
|
|
1078
|
+
if (repository !== void 0 && !isRepositoryInput(repository)) {
|
|
1079
|
+
const coverage2 = {
|
|
1080
|
+
message: 'The `repository` given isn\'t `{ type: "url", url }` or `{ type: "full-name", fullName }`.',
|
|
1081
|
+
reason: "invalid-repository",
|
|
1082
|
+
status: "unknown"
|
|
1083
|
+
};
|
|
1084
|
+
deps.log.warn(
|
|
1085
|
+
`\u26A0\uFE0F Couldn't tell what QA Wolf can read: ${coverage2.message}`
|
|
1086
|
+
);
|
|
1087
|
+
return { coverage: coverage2, repository: void 0 };
|
|
1088
|
+
}
|
|
1089
|
+
const identified = await identifyRepository(deps.git, {
|
|
1090
|
+
cwd,
|
|
1091
|
+
env,
|
|
1092
|
+
repository
|
|
1093
|
+
});
|
|
1094
|
+
const coverage = identified ? await findRepositoryCoverage(deps, apiConfig, {
|
|
1095
|
+
url: identified.url,
|
|
1096
|
+
workspaceId
|
|
1097
|
+
}) : {
|
|
1098
|
+
message: "No repository was given, and neither the CI's variables nor the `origin` git remote name one. Pass `repository`.",
|
|
1099
|
+
reason: "repository-not-found",
|
|
1100
|
+
status: "unknown"
|
|
1101
|
+
};
|
|
1102
|
+
if (coverage.status === "unknown") {
|
|
1103
|
+
deps.log.warn(
|
|
1104
|
+
`\u26A0\uFE0F Couldn't tell what QA Wolf can read of ${identified?.url ?? "this repository"}: ${coverage.message}`
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
return { coverage, repository: identified };
|
|
1108
|
+
}
|
|
1109
|
+
__name(findCoverageOfRepository, "findCoverageOfRepository");
|
|
1110
|
+
|
|
1111
|
+
// src/lib/sdk/domain/collectDeployChanges/explainCollection.ts
|
|
1112
|
+
function explainCollection({
|
|
1113
|
+
coverage,
|
|
1114
|
+
repository
|
|
1115
|
+
}) {
|
|
1116
|
+
const name = repository?.url ?? "this repository";
|
|
1117
|
+
switch (coverage.status) {
|
|
1118
|
+
case "covered":
|
|
1119
|
+
return `QA Wolf reads ${coverage.fullName}'s pull requests itself but not commits pushed straight to a branch, so this deploy's commits are collected.`;
|
|
1120
|
+
case "not-covered":
|
|
1121
|
+
return `QA Wolf can't read ${name}, so this deploy's commits are collected.${coverage.settingsUrl ? ` Connect its code host at ${coverage.settingsUrl}.` : ""}`;
|
|
1122
|
+
case "unknown":
|
|
1123
|
+
return "Collecting this deploy's commits.";
|
|
1124
|
+
case "unsupported-host":
|
|
1125
|
+
return `QA Wolf doesn't connect to ${name}'s code host, so this deploy's commits are collected.`;
|
|
1126
|
+
default:
|
|
1127
|
+
throw Error(`Unexpected coverage: ${coverage}`);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
__name(explainCollection, "explainCollection");
|
|
1131
|
+
|
|
1132
|
+
// src/lib/sdk/domain/collectDeployChanges/filterChanges.ts
|
|
1133
|
+
import { z as z2 } from "zod";
|
|
1134
|
+
var sha = z2.string().regex(/^[0-9a-f]{7,64}$/iu);
|
|
1135
|
+
var number = z2.number().int().positive();
|
|
1136
|
+
var sharedFields = {
|
|
1137
|
+
changedPaths: z2.array(z2.string()).optional(),
|
|
1138
|
+
description: z2.string().optional(),
|
|
1139
|
+
title: z2.string().refine((title) => title.trim().length > 0),
|
|
1140
|
+
url: z2.string().optional()
|
|
1141
|
+
};
|
|
1142
|
+
var changeSchema = z2.discriminatedUnion("kind", [
|
|
1143
|
+
z2.looseObject({
|
|
1144
|
+
...sharedFields,
|
|
1145
|
+
kind: z2.literal("pull-request"),
|
|
1146
|
+
mergeCommitSha: sha.optional(),
|
|
1147
|
+
number: number.optional()
|
|
1148
|
+
}),
|
|
1149
|
+
z2.looseObject({
|
|
1150
|
+
...sharedFields,
|
|
1151
|
+
kind: z2.literal("commit"),
|
|
1152
|
+
pullRequestNumber: number.optional(),
|
|
1153
|
+
sha: sha.optional()
|
|
1154
|
+
})
|
|
1155
|
+
]);
|
|
1156
|
+
var maxTimerDelayMs = 2 ** 31 - 1;
|
|
1157
|
+
async function settle(filter, changes, timeoutMs) {
|
|
1158
|
+
const timeout = Promise.withResolvers();
|
|
1159
|
+
const timer = setTimeout(
|
|
1160
|
+
() => timeout.resolve({ ok: false, reason: `took over ${timeoutMs} ms` }),
|
|
1161
|
+
// Timers overflow past this and fire at once, so a longer wait, such as
|
|
1162
|
+
// `Infinity`, waits this long instead.
|
|
1163
|
+
Math.min(timeoutMs, maxTimerDelayMs)
|
|
1164
|
+
);
|
|
1165
|
+
const run = Promise.resolve().then(() => filter(structuredClone(changes))).then(
|
|
1166
|
+
(value) => ({ ok: true, value }),
|
|
1167
|
+
(error) => ({
|
|
1168
|
+
ok: false,
|
|
1169
|
+
reason: `threw ${error instanceof Error ? error.message : String(error)}`
|
|
1170
|
+
})
|
|
1171
|
+
);
|
|
1172
|
+
const settled = await Promise.race([run, timeout.promise]);
|
|
1173
|
+
clearTimeout(timer);
|
|
1174
|
+
return settled;
|
|
1175
|
+
}
|
|
1176
|
+
__name(settle, "settle");
|
|
1177
|
+
async function filterChanges({ log }, {
|
|
1178
|
+
changes,
|
|
1179
|
+
filter,
|
|
1180
|
+
timeoutMs
|
|
1181
|
+
}) {
|
|
1182
|
+
const settled = await settle(filter, changes, timeoutMs);
|
|
1183
|
+
if (!settled.ok) {
|
|
1184
|
+
log.warn(
|
|
1185
|
+
`\u26A0\uFE0F The changes filter ${settled.reason}, so no changes are sent.`
|
|
1186
|
+
);
|
|
1187
|
+
return { outcome: "failed" };
|
|
1188
|
+
}
|
|
1189
|
+
const parsed = z2.array(z2.unknown()).safeParse(settled.value);
|
|
1190
|
+
if (!parsed.success) {
|
|
1191
|
+
log.warn(
|
|
1192
|
+
"\u26A0\uFE0F The changes filter returned something other than a list of changes, so no changes are sent."
|
|
1193
|
+
);
|
|
1194
|
+
return { outcome: "failed" };
|
|
1195
|
+
}
|
|
1196
|
+
const filtered = parsed.data.flatMap((value) => {
|
|
1197
|
+
const change = changeSchema.safeParse(value);
|
|
1198
|
+
return change.success ? [change.data] : [];
|
|
1199
|
+
});
|
|
1200
|
+
const invalidCount = parsed.data.length - filtered.length;
|
|
1201
|
+
if (invalidCount > 0) {
|
|
1202
|
+
log.warn(
|
|
1203
|
+
`\u26A0\uFE0F The changes filter returned ${invalidCount} change(s) that aren't changes QA Wolf reads, such as one without a title or kind, so they're left out.`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
return { changes: filtered, invalidCount, outcome: "filtered" };
|
|
1207
|
+
}
|
|
1208
|
+
__name(filterChanges, "filterChanges");
|
|
1209
|
+
|
|
1210
|
+
// src/lib/sdk/domain/collectDeployChanges/isGitHubRepository.ts
|
|
1211
|
+
function isGitHubRepository({ coverage, repository }, env) {
|
|
1212
|
+
if (coverage.status === "covered" && coverage.provider === "github")
|
|
1213
|
+
return true;
|
|
1214
|
+
const host = repository && hostOf(repository.url)?.toLowerCase();
|
|
1215
|
+
if (!host) return false;
|
|
1216
|
+
if (host === "github.com") return true;
|
|
1217
|
+
const server = env.GITHUB_ACTIONS === "true" && env.GITHUB_SERVER_URL ? hostOf(env.GITHUB_SERVER_URL)?.toLowerCase() : void 0;
|
|
1218
|
+
return host === server;
|
|
1219
|
+
}
|
|
1220
|
+
__name(isGitHubRepository, "isGitHubRepository");
|
|
1221
|
+
|
|
1222
|
+
// src/lib/sdk/domain/collectDeployChanges/sendableChanges.ts
|
|
1223
|
+
var isHttpUrl = /* @__PURE__ */ __name((url) => URL.canParse(url) && ["http:", "https:"].includes(new URL(url).protocol), "isHttpUrl");
|
|
1224
|
+
function sendableChange(change, redact) {
|
|
1225
|
+
const { changedPaths, description, url, ...rest } = change;
|
|
1226
|
+
const title = redact(change.title).trim();
|
|
1227
|
+
if (!title) return void 0;
|
|
1228
|
+
const paths = changedPaths?.filter((path) => path.trim()) ?? [];
|
|
1229
|
+
const redactedDescription = description && redact(description).trim();
|
|
1230
|
+
const redactedUrl = url && redact(url).trim();
|
|
1231
|
+
return {
|
|
1232
|
+
...rest,
|
|
1233
|
+
...paths.length > 0 && { changedPaths: paths },
|
|
1234
|
+
...redactedDescription && { description: redactedDescription },
|
|
1235
|
+
...redactedUrl && isHttpUrl(redactedUrl) && { url: redactedUrl },
|
|
1236
|
+
title
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
__name(sendableChange, "sendableChange");
|
|
1240
|
+
|
|
1241
|
+
// src/lib/sdk/domain/collectDeployChanges/index.ts
|
|
1242
|
+
var allFields = ["titles", "descriptions", "paths"];
|
|
1243
|
+
var defaultFilterTimeoutMs = 2 * 60 * 1e3;
|
|
1244
|
+
async function collectDeployChanges(deps, apiConfig, params) {
|
|
1245
|
+
const {
|
|
1246
|
+
cwd = process.cwd(),
|
|
1247
|
+
env = process.env,
|
|
1248
|
+
filter,
|
|
1249
|
+
filterTimeoutMs = defaultFilterTimeoutMs,
|
|
1250
|
+
include = allFields,
|
|
1251
|
+
releaseNotes,
|
|
1252
|
+
repository,
|
|
1253
|
+
since,
|
|
1254
|
+
workspaceId
|
|
1255
|
+
} = params;
|
|
1256
|
+
const found = await findCoverageOfRepository(deps, apiConfig, {
|
|
1257
|
+
cwd,
|
|
1258
|
+
env,
|
|
1259
|
+
repository,
|
|
1260
|
+
workspaceId
|
|
1261
|
+
});
|
|
1262
|
+
const { acceptsChange, redact } = deps;
|
|
1263
|
+
if (!redact || !acceptsChange) {
|
|
1264
|
+
const message = `The installed @qawolf/api-contracts can't redact changes, so none are collected. Install version ${minimumContractsVersion} or later.`;
|
|
1265
|
+
deps.log.error(`\u274C ${message}`);
|
|
1266
|
+
return { ...found, message, outcome: "outdated-contracts" };
|
|
1267
|
+
}
|
|
1268
|
+
const ci = detectCiSystem(env)?.name;
|
|
1269
|
+
const notes = releaseNotes && redact(releaseNotes);
|
|
1270
|
+
const summaryOf = /* @__PURE__ */ __name((items2, totalCount, problems) => fitChanges({
|
|
1271
|
+
extra: { ...ci && { ci }, ...problems && { problems } },
|
|
1272
|
+
items: items2,
|
|
1273
|
+
releaseNotes: notes,
|
|
1274
|
+
totalCount
|
|
1275
|
+
}), "summaryOf");
|
|
1276
|
+
deps.log.info(`\u2139\uFE0F ${explainCollection(found)}`);
|
|
1277
|
+
const range = await readCommitRange(deps.git, {
|
|
1278
|
+
cwd,
|
|
1279
|
+
includePaths: include.includes("paths"),
|
|
1280
|
+
since
|
|
1281
|
+
});
|
|
1282
|
+
if (range.outcome === "git-failed") return { ...found, ...range };
|
|
1283
|
+
if (range.outcome !== "read") {
|
|
1284
|
+
deps.log.warn(`\u26A0\uFE0F Couldn't read this deploy's commits. ${range.fix}`);
|
|
1285
|
+
return {
|
|
1286
|
+
...found,
|
|
1287
|
+
changes: summaryOf([], 0, [{ kind: range.outcome }]),
|
|
1288
|
+
outcome: "collected"
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
const squashedPullRequests = isGitHubRepository(found, env);
|
|
1292
|
+
const collected = range.commits.filter(({ subject }) => subject.length > 0).map(
|
|
1293
|
+
(commit) => changeOfCommit(commit, {
|
|
1294
|
+
descriptions: include.includes("descriptions"),
|
|
1295
|
+
ids: true,
|
|
1296
|
+
paths: include.includes("paths"),
|
|
1297
|
+
squashedPullRequests
|
|
1298
|
+
})
|
|
1299
|
+
);
|
|
1300
|
+
const filtered = filter ? await filterChanges(deps, {
|
|
1301
|
+
changes: collected,
|
|
1302
|
+
filter,
|
|
1303
|
+
timeoutMs: filterTimeoutMs
|
|
1304
|
+
}) : { changes: collected, invalidCount: 0, outcome: "filtered" };
|
|
1305
|
+
const kept = filtered.outcome === "filtered" ? filtered.changes : [];
|
|
1306
|
+
const fitted = kept.flatMap((change) => {
|
|
1307
|
+
const sendable = sendableChange(change, redact);
|
|
1308
|
+
return sendable ? [fitItem(sendable)] : [];
|
|
1309
|
+
});
|
|
1310
|
+
const items = fitted.filter(acceptsChange);
|
|
1311
|
+
const rejectedCount = fitted.length - items.length;
|
|
1312
|
+
if (rejectedCount > 0) {
|
|
1313
|
+
deps.log.warn(
|
|
1314
|
+
`\u26A0\uFE0F Left out ${rejectedCount} change(s) QA Wolf doesn't accept, such as one with a field it doesn't know.`
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
const failed = filtered.outcome === "failed" || filtered.invalidCount > 0 || filter !== void 0 && rejectedCount > 0;
|
|
1318
|
+
const leftOut = Math.max(0, collected.length - kept.length);
|
|
1319
|
+
return {
|
|
1320
|
+
...found,
|
|
1321
|
+
changes: summaryOf(
|
|
1322
|
+
items,
|
|
1323
|
+
range.totalCount - leftOut,
|
|
1324
|
+
failed ? [{ kind: "filter-failed" }] : void 0
|
|
1325
|
+
),
|
|
1326
|
+
outcome: "collected"
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
__name(collectDeployChanges, "collectDeployChanges");
|
|
1330
|
+
|
|
1331
|
+
// src/lib/sdk/domain/environment/promote.ts
|
|
1332
|
+
import { publicContractsV1 } from "@qawolf/api-contracts";
|
|
1333
|
+
|
|
811
1334
|
// src/lib/sdk/publicApi/mapFailure.ts
|
|
812
1335
|
function mapPublicApiFailure(result) {
|
|
813
1336
|
if (result.outcome !== "http-error") return { outcome: result.outcome };
|
|
@@ -2206,15 +2729,38 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
2206
2729
|
log
|
|
2207
2730
|
};
|
|
2208
2731
|
const apiConfig = { apiKey, serviceBase, userAgent };
|
|
2732
|
+
const coverageDeps = { ...deps, contracts: defaultCoverageContracts, git };
|
|
2209
2733
|
return {
|
|
2210
2734
|
/**
|
|
2211
2735
|
* @deprecated Reports through the legacy `deploy_success` webhook, which
|
|
2212
2736
|
* triggers do not see. Use `deployment.reportStatus` instead.
|
|
2213
2737
|
*/
|
|
2214
2738
|
attemptNotifyDeploy: attemptNotifyDeploy.bind(null, deps, apiConfig),
|
|
2739
|
+
codeHostIntegration: {
|
|
2740
|
+
/** Works out this job's repository and asks QA Wolf what it can read there. */
|
|
2741
|
+
findForRepository: findCoverageOfRepository.bind(
|
|
2742
|
+
null,
|
|
2743
|
+
coverageDeps,
|
|
2744
|
+
apiConfig
|
|
2745
|
+
)
|
|
2746
|
+
},
|
|
2215
2747
|
deployment: {
|
|
2216
2748
|
/** Builds `changes` for `reportStatus` from the local git history; sends nothing itself. */
|
|
2217
2749
|
collectCommitChanges: collectCommitChanges.bind(null, git),
|
|
2750
|
+
/**
|
|
2751
|
+
* Builds `changes` for `reportStatus` from the deploy's commits, including
|
|
2752
|
+
* ones QA Wolf can't read of the repository, with ids, your filter and
|
|
2753
|
+
* redaction applied; sends nothing itself.
|
|
2754
|
+
*/
|
|
2755
|
+
collectDeployChanges: collectDeployChanges.bind(
|
|
2756
|
+
null,
|
|
2757
|
+
{
|
|
2758
|
+
...coverageDeps,
|
|
2759
|
+
acceptsChange: defaultAcceptsChange,
|
|
2760
|
+
redact: defaultRedact
|
|
2761
|
+
},
|
|
2762
|
+
apiConfig
|
|
2763
|
+
),
|
|
2218
2764
|
reportStatus: reportDeployment.bind(null, deps, apiConfig),
|
|
2219
2765
|
waitForVerdict: waitForVerdict.bind(null, deps, apiConfig)
|
|
2220
2766
|
},
|