@qawolf/ci-sdk 3.7.1 → 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/README.md +82 -0
- package/dist/index.js +626 -81
- 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/index.d.ts +20 -8
- package/dist/tests/test-lib.d.ts +12 -8
- package/package.json +5 -5
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Redact } from "../domain/collectDeployChanges/sendableChanges.js";
|
|
2
|
+
import type { DeployChange } from "../domain/collectDeployChanges/types.js";
|
|
3
|
+
import type { CoverageContracts } from "../domain/repositoryCoverage/contracts.js";
|
|
4
|
+
type ChangesSchema = {
|
|
5
|
+
safeParse: (value: unknown) => {
|
|
6
|
+
success: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const defaultCoverageContracts: CoverageContracts & {
|
|
10
|
+
deployment?: {
|
|
11
|
+
reportStatus?: {
|
|
12
|
+
input?: {
|
|
13
|
+
shape?: {
|
|
14
|
+
changes?: ChangesSchema;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** The redaction QA Wolf applies to reported changes, when the installed contracts have it. */
|
|
21
|
+
export declare const defaultRedact: Redact | undefined;
|
|
22
|
+
/** Whether the installed contract accepts the change in a deployment report. */
|
|
23
|
+
export declare const defaultAcceptsChange: ((change: DeployChange) => boolean) | undefined;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DeploymentChanges } from "./types.js";
|
|
2
|
+
export type ChangeItem = NonNullable<DeploymentChanges["items"]>[number];
|
|
3
|
+
export type Commit = {
|
|
4
|
+
body: string;
|
|
5
|
+
paths: string[];
|
|
6
|
+
sha: string;
|
|
7
|
+
subject: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The change a commit on the first-parent line stands for: a merged pull
|
|
11
|
+
* request when its message says so, otherwise a commit. Its text is whole;
|
|
12
|
+
* the API's limits are applied later. With `ids`, a pull request carries its
|
|
13
|
+
* number and the commit it landed as, and a commit its sha. With
|
|
14
|
+
* `squashedPullRequests`, a subject ending in `(#N)` is a pull request GitHub
|
|
15
|
+
* squashed; elsewhere `#N` names something else, so it stays a commit.
|
|
16
|
+
*/
|
|
17
|
+
export declare function changeOfCommit(commit: Commit, { descriptions, ids, paths, squashedPullRequests, }: {
|
|
18
|
+
descriptions: boolean;
|
|
19
|
+
ids: boolean;
|
|
20
|
+
paths: boolean;
|
|
21
|
+
squashedPullRequests: boolean;
|
|
22
|
+
}): ChangeItem;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ChangeItem } from "./commitChange.js";
|
|
2
|
+
import type { DeploymentChanges } from "./types.js";
|
|
3
|
+
export declare const maxItems = 250;
|
|
4
|
+
/** The change with its text cut to the API's limits and as many paths as fit its share. */
|
|
5
|
+
export declare function fitItem(item: ChangeItem): ChangeItem;
|
|
6
|
+
/**
|
|
7
|
+
* The changes summary of fitted changes, newest first, within the API's
|
|
8
|
+
* limits, with `extra` counted in the size. `items` may be the newest part of
|
|
9
|
+
* `totalCount` changes; every change left out, there or to fit, is counted in
|
|
10
|
+
* `omittedCount`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fitChanges({ extra, items, releaseNotes, totalCount, }: {
|
|
13
|
+
extra: Pick<DeploymentChanges, "ci" | "problems">;
|
|
14
|
+
items: ChangeItem[];
|
|
15
|
+
releaseNotes: string | undefined;
|
|
16
|
+
totalCount: number;
|
|
17
|
+
}): DeploymentChanges;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { Commit } from "./
|
|
1
|
+
import type { Commit } from "./commitChange.js";
|
|
2
2
|
/**
|
|
3
|
-
* The `git log --format` that `parseLog` reads:
|
|
4
|
-
* each ending in a NUL, which commit
|
|
3
|
+
* The `git log --format` that `parseLog` reads: an empty field starting the
|
|
4
|
+
* record, then the hash, subject and body, each ending in a NUL, which commit
|
|
5
|
+
* text and paths can't hold.
|
|
5
6
|
*/
|
|
6
|
-
export declare const logFormat = "%H%x00%s%x00%b%x00";
|
|
7
|
+
export declare const logFormat = "%x00%H%x00%s%x00%b%x00";
|
|
7
8
|
/**
|
|
8
9
|
* Reads `git log -z` output in `logFormat`. With `--name-only`, each
|
|
9
10
|
* record's changed paths follow, each ending in a NUL, so paths come through
|
|
10
|
-
* unquoted.
|
|
11
|
+
* unquoted. A path is never empty, so the empty field starting the next
|
|
12
|
+
* record ends them.
|
|
11
13
|
*/
|
|
12
14
|
export declare function parseLog(stdout: string): Commit[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Commit } from "./commitChange.js";
|
|
2
|
+
import type { GitDriver } from "./types.js";
|
|
3
|
+
export type CommitRange = {
|
|
4
|
+
commits: Commit[];
|
|
5
|
+
outcome: "read";
|
|
6
|
+
totalCount: number;
|
|
7
|
+
}
|
|
8
|
+
/** The clone is shallow, so it may not hold the whole range. */
|
|
9
|
+
| {
|
|
10
|
+
fix: string;
|
|
11
|
+
outcome: "history-unavailable";
|
|
12
|
+
}
|
|
13
|
+
/** `since` names no commit in this repository, e.g. a typo or a tag that wasn't fetched. */
|
|
14
|
+
| {
|
|
15
|
+
fix: string;
|
|
16
|
+
outcome: "since-not-found";
|
|
17
|
+
}
|
|
18
|
+
/** Git failed for another reason. */
|
|
19
|
+
| {
|
|
20
|
+
message: string;
|
|
21
|
+
outcome: "git-failed";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The newest commits on the first-parent line after `since` up to HEAD, with
|
|
25
|
+
* how many the range holds. It refuses a shallow clone rather than read part
|
|
26
|
+
* of a range.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readCommitRange(git: GitDriver, { cwd, includePaths, since, }: {
|
|
29
|
+
cwd: string;
|
|
30
|
+
includePaths: boolean;
|
|
31
|
+
since: string;
|
|
32
|
+
}): Promise<CommitRange>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import { type Commit } from "./commitChange.js";
|
|
1
2
|
import type { DeploymentChanges } from "./types.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
body: string;
|
|
5
|
-
paths: string[];
|
|
6
|
-
subject: string;
|
|
7
|
-
};
|
|
3
|
+
export type { Commit } from "./commitChange.js";
|
|
4
|
+
export { maxItems } from "./fitChanges.js";
|
|
8
5
|
/**
|
|
9
6
|
* The changes summary of a range's commits, newest first, within the API's
|
|
10
7
|
* limits. `commits` may be the newest part of a range of `totalCount`; every
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FindRepositoryCoverageResult } from "../repositoryCoverage/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Why this deploy's commits are collected, given what QA Wolf reads of the
|
|
4
|
+
* repository. They're collected whatever it reads: QA Wolf reads merged pull
|
|
5
|
+
* requests from a code host, never commits pushed straight to a branch, such
|
|
6
|
+
* as a hotfix.
|
|
7
|
+
*/
|
|
8
|
+
export declare function explainCollection({ coverage, repository, }: FindRepositoryCoverageResult): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LogDriver } from "../../dependencies.js";
|
|
2
|
+
import type { ChangeItem } from "../collectCommitChanges/commitChange.js";
|
|
3
|
+
import type { DeployChangesFilter } from "./types.js";
|
|
4
|
+
export type FilterOutcome = {
|
|
5
|
+
changes: ChangeItem[];
|
|
6
|
+
invalidCount: number;
|
|
7
|
+
outcome: "filtered";
|
|
8
|
+
} | {
|
|
9
|
+
outcome: "failed";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Runs the filter on the changes. It never falls back to the changes as they
|
|
13
|
+
* were: when the filter fails, it says so and keeps none of them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterChanges({ log }: {
|
|
16
|
+
log: LogDriver;
|
|
17
|
+
}, { changes, filter, timeoutMs, }: {
|
|
18
|
+
changes: ChangeItem[];
|
|
19
|
+
filter: DeployChangesFilter;
|
|
20
|
+
timeoutMs: number;
|
|
21
|
+
}): Promise<FilterOutcome>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ApiConfig } from "../../../api-types.js";
|
|
2
|
+
import { type RepositoryCoverageDependencies } from "../repositoryCoverage/index.js";
|
|
3
|
+
import { type Redact } from "./sendableChanges.js";
|
|
4
|
+
import type { CollectDeployChangesParams, CollectDeployChangesResult, DeployChange } from "./types.js";
|
|
5
|
+
export type CollectDeployChangesDependencies = RepositoryCoverageDependencies & {
|
|
6
|
+
/** Whether the installed contract accepts the change; absent from older contracts. */
|
|
7
|
+
acceptsChange: ((change: DeployChange) => boolean) | undefined;
|
|
8
|
+
redact: Redact | undefined;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builds the `changes` for `deployment.reportStatus`: it asks QA Wolf what it
|
|
12
|
+
* reads of the repository and collects this deploy's commits from the local
|
|
13
|
+
* git history, which QA Wolf can't see when they were pushed straight to a
|
|
14
|
+
* branch. Each change carries its ids, passes through `filter` when given,
|
|
15
|
+
* has secrets redacted and is checked against the installed contract before
|
|
16
|
+
* it's returned. It sends nothing itself.
|
|
17
|
+
*/
|
|
18
|
+
export declare function collectDeployChanges(deps: CollectDeployChangesDependencies, apiConfig: ApiConfig, params: CollectDeployChangesParams): Promise<CollectDeployChangesResult>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CiEnvironment } from "../detectProviderDeploymentId/ciSystems.js";
|
|
2
|
+
import type { FindRepositoryCoverageResult } from "../repositoryCoverage/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the repository is on GitHub: github.com, the GitHub Enterprise
|
|
5
|
+
* server a GitHub Actions job runs for, or a host QA Wolf reads through its
|
|
6
|
+
* GitHub integration. Unknown when no repository was found, so it's not.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isGitHubRepository({ coverage, repository }: FindRepositoryCoverageResult, env: CiEnvironment): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChangeItem } from "../collectCommitChanges/commitChange.js";
|
|
2
|
+
export type Redact = (text: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
* The change with secrets redacted from its text, as the API accepts it:
|
|
5
|
+
* empty descriptions and paths left out, a link kept only when it's an http
|
|
6
|
+
* URL. Undefined when nothing is left of its title.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sendableChange(change: ChangeItem, redact: Redact): ChangeItem | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { GitDriver } from "../collectCommitChanges/types.js";
|
|
2
|
+
import type { CollectDeployChangesParams } from "./types.js";
|
|
3
|
+
/** `git log -z` in `logFormat`: an empty field, hash, subject and body, then the paths. */
|
|
4
|
+
export declare const logOf: (commits: {
|
|
5
|
+
body: string;
|
|
6
|
+
paths?: string[];
|
|
7
|
+
subject: string;
|
|
8
|
+
}[]) => string;
|
|
9
|
+
export declare const history: string;
|
|
10
|
+
export declare function makeGit({ isShallow, log, }?: {
|
|
11
|
+
isShallow?: boolean;
|
|
12
|
+
log?: string;
|
|
13
|
+
}): import("jest-mock").Mock<GitDriver>;
|
|
14
|
+
export declare function collect({ answer, git, params, redacts, }?: {
|
|
15
|
+
answer?: unknown;
|
|
16
|
+
git?: GitDriver;
|
|
17
|
+
params?: Partial<CollectDeployChangesParams>;
|
|
18
|
+
/** Whether the installed contracts can redact. */
|
|
19
|
+
redacts?: boolean;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
fetch: import("jest-mock").Mock<typeof globalThis.fetch>;
|
|
22
|
+
git: GitDriver;
|
|
23
|
+
log: {
|
|
24
|
+
error: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
25
|
+
info: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
26
|
+
warn: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
27
|
+
};
|
|
28
|
+
result: import("./types.js").CollectDeployChangesResult;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const collectedItems: ({
|
|
31
|
+
changedPaths: string[];
|
|
32
|
+
description: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
mergeCommitSha: string;
|
|
35
|
+
number: number;
|
|
36
|
+
title: string;
|
|
37
|
+
sha?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
changedPaths: string[];
|
|
40
|
+
description: string;
|
|
41
|
+
kind: string;
|
|
42
|
+
sha: string;
|
|
43
|
+
title: string;
|
|
44
|
+
mergeCommitSha?: undefined;
|
|
45
|
+
number?: undefined;
|
|
46
|
+
})[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ChangeItem } from "../collectCommitChanges/commitChange.js";
|
|
2
|
+
import type { CollectedChangeLevel, DeploymentChanges } from "../collectCommitChanges/types.js";
|
|
3
|
+
import type { FindRepositoryCoverageParams, FindRepositoryCoverageResult } from "../repositoryCoverage/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* One change `collectDeployChanges` sends: a merged pull request or a commit.
|
|
6
|
+
* More kinds and optional fields may be added in minor versions.
|
|
7
|
+
*/
|
|
8
|
+
export type DeployChange = ChangeItem;
|
|
9
|
+
/**
|
|
10
|
+
* Edits the changes before they leave CI: return them changed, or leave some
|
|
11
|
+
* out. It may be async, e.g. to clean the text with your own tools. When it
|
|
12
|
+
* throws, takes too long or returns something that isn't a list of changes,
|
|
13
|
+
* none of the changes are sent.
|
|
14
|
+
*/
|
|
15
|
+
export type DeployChangesFilter = (changes: DeployChange[]) => DeployChange[] | Promise<DeployChange[]>;
|
|
16
|
+
export type CollectDeployChangesParams = FindRepositoryCoverageParams & {
|
|
17
|
+
/**
|
|
18
|
+
* Edits the changes before they're redacted and sent. When it returns
|
|
19
|
+
* something that isn't a change QA Wolf reads, such as one without a title,
|
|
20
|
+
* or with a field QA Wolf doesn't accept, that change is left out and
|
|
21
|
+
* `problems` says the filter failed.
|
|
22
|
+
*/
|
|
23
|
+
filter?: DeployChangesFilter;
|
|
24
|
+
/** How long `filter` may take, in milliseconds; 2 minutes by default. `Infinity` sets no limit. */
|
|
25
|
+
filterTimeoutMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* What to send for each change: its title, its description (the commit
|
|
28
|
+
* message or pull request description) and its changed file paths. All of
|
|
29
|
+
* them by default. Descriptions and paths are what QA Wolf chooses the
|
|
30
|
+
* flows to run from, so leaving them out lowers the quality of the choice.
|
|
31
|
+
*/
|
|
32
|
+
include?: CollectedChangeLevel[];
|
|
33
|
+
/** Notes written for the release, sent with the changes. */
|
|
34
|
+
releaseNotes?: string;
|
|
35
|
+
/** The commit the environment ran before, e.g. the previous release tag. */
|
|
36
|
+
since: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* More outcomes may be added in minor versions. Every outcome other than
|
|
40
|
+
* `collected` carries `message`.
|
|
41
|
+
*/
|
|
42
|
+
export type CollectDeployChangesResult = FindRepositoryCoverageResult & ({
|
|
43
|
+
/**
|
|
44
|
+
* The value to pass as `changes` to `deployment.reportStatus`. When
|
|
45
|
+
* collecting went wrong, its `problems` say what, so QA Wolf can tell
|
|
46
|
+
* you about it.
|
|
47
|
+
*/
|
|
48
|
+
changes: DeploymentChanges;
|
|
49
|
+
outcome: "collected";
|
|
50
|
+
}
|
|
51
|
+
/** Git failed reading the history. */
|
|
52
|
+
| {
|
|
53
|
+
message: string;
|
|
54
|
+
outcome: "git-failed";
|
|
55
|
+
}
|
|
56
|
+
/** The installed `@qawolf/api-contracts` is too old to redact the changes, so none are collected. */
|
|
57
|
+
| {
|
|
58
|
+
message: string;
|
|
59
|
+
outcome: "outdated-contracts";
|
|
60
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A CI system the SDK recognizes. More may be added. */
|
|
2
|
+
export type CiSystem = "azure-pipelines" | "bitbucket" | "buildkite" | "circleci" | "github" | "gitlab" | "jenkins" | (string & {});
|
|
3
|
+
export type CiEnvironment = Record<string, string | undefined>;
|
|
4
|
+
type CiSystemDefinition = {
|
|
5
|
+
ci: CiSystem;
|
|
6
|
+
isActive: (env: CiEnvironment) => boolean;
|
|
7
|
+
/** How QA Wolf names the CI system to you. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The URL of the repository the job checked out, when the CI exposes it. */
|
|
10
|
+
repositoryUrl: (env: CiEnvironment) => string | undefined;
|
|
11
|
+
/** Joined in order into the id; all of them must be present. */
|
|
12
|
+
variables: string[];
|
|
13
|
+
};
|
|
14
|
+
/** The CI system running this job, when its variables say which. */
|
|
15
|
+
export declare function detectCiSystem(env: CiEnvironment): CiSystemDefinition | undefined;
|
|
16
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type CiSystem } from "./ciSystems.js";
|
|
2
|
+
export type { CiSystem };
|
|
2
3
|
export type DetectedProviderDeploymentId = {
|
|
3
4
|
ci: CiSystem;
|
|
4
5
|
/**
|
|
@@ -19,7 +20,6 @@ export type DetectedProviderDeploymentId = {
|
|
|
19
20
|
} | {
|
|
20
21
|
outcome: "unsupported";
|
|
21
22
|
};
|
|
22
|
-
type CiEnvironment = Record<string, string | undefined>;
|
|
23
23
|
export type DetectProviderDeploymentIdOptions = {
|
|
24
24
|
/**
|
|
25
25
|
* Appended to the composed id. Required whenever one job definition deploys
|
|
@@ -31,7 +31,7 @@ export type DetectProviderDeploymentIdOptions = {
|
|
|
31
31
|
*/
|
|
32
32
|
discriminator?: string;
|
|
33
33
|
/** The variables to read, defaulting to `process.env`. */
|
|
34
|
-
env?:
|
|
34
|
+
env?: Record<string, string | undefined>;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* Derives a `providerDeploymentId` from the CI system's own environment
|
|
@@ -46,4 +46,3 @@ export type DetectProviderDeploymentIdOptions = {
|
|
|
46
46
|
* `discriminator` for them or compose the `providerDeploymentId` yourself.
|
|
47
47
|
*/
|
|
48
48
|
export declare function detectProviderDeploymentId({ discriminator, env, }?: DetectProviderDeploymentIdOptions): DetectedProviderDeploymentId;
|
|
49
|
-
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PublicApiContract } from "../../publicApi/callContract.js";
|
|
2
|
+
/** The part of `@qawolf/api-contracts` the check needs, absent from older versions. */
|
|
3
|
+
export type CoverageContracts = {
|
|
4
|
+
codeHostIntegration?: {
|
|
5
|
+
findForRepository?: PublicApiContract<{
|
|
6
|
+
url: string;
|
|
7
|
+
workspaceId?: string;
|
|
8
|
+
}, unknown>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ApiConfig } from "../../../api-types.js";
|
|
2
|
+
import type { SdkDependencies } from "../../dependencies.js";
|
|
3
|
+
import type { CoverageContracts } from "./contracts.js";
|
|
4
|
+
import type { RepositoryCoverage } from "./types.js";
|
|
5
|
+
/** The `@qawolf/api-contracts` version collecting deploy changes needs: the first that redacts them. */
|
|
6
|
+
export declare const minimumContractsVersion = "0.148.0";
|
|
7
|
+
/**
|
|
8
|
+
* Asks QA Wolf whether a code host integration of the workspace can read the
|
|
9
|
+
* repository at `url`, and what it can read there. Any answer it can't use,
|
|
10
|
+
* or a failed call, is `unknown` with the reason.
|
|
11
|
+
*/
|
|
12
|
+
export declare function findRepositoryCoverage(deps: SdkDependencies & {
|
|
13
|
+
contracts: CoverageContracts;
|
|
14
|
+
}, apiConfig: ApiConfig, { url, workspaceId }: {
|
|
15
|
+
url: string;
|
|
16
|
+
workspaceId: string | undefined;
|
|
17
|
+
}): Promise<RepositoryCoverage>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { GitDriver } from "../collectCommitChanges/types.js";
|
|
2
|
+
import { type CiEnvironment } from "../detectProviderDeploymentId/ciSystems.js";
|
|
3
|
+
/** The repository to check: its URL, or its full name on a code host. */
|
|
4
|
+
export type RepositoryInput = {
|
|
5
|
+
type: "url";
|
|
6
|
+
url: string;
|
|
7
|
+
} | {
|
|
8
|
+
/** The repository's full name, e.g. `acme/storefront` or `acme/web/storefront`. */
|
|
9
|
+
fullName: string;
|
|
10
|
+
/**
|
|
11
|
+
* The code host, e.g. `gitlab.com`. When unset, the host of the
|
|
12
|
+
* repository the CI's variables or the `origin` remote name, else
|
|
13
|
+
* `github.com`.
|
|
14
|
+
*/
|
|
15
|
+
host?: string;
|
|
16
|
+
type: "full-name";
|
|
17
|
+
};
|
|
18
|
+
export type IdentifiedRepository = {
|
|
19
|
+
/** Where the URL came from: the `repository` you passed, the CI's own variables, or the `origin` git remote. */
|
|
20
|
+
source: "ci" | "git-remote" | "input";
|
|
21
|
+
/** The repository's URL, without any credentials it carried. */
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The URL without credentials: a URL's user, password, query and fragment are
|
|
26
|
+
* removed, and an scp-like URL's user becomes git's own `git`, so none of them
|
|
27
|
+
* reaches a request address or a log.
|
|
28
|
+
*/
|
|
29
|
+
export declare function withoutCredentials(url: string): string;
|
|
30
|
+
/** The host of a URL or scp-like URL, when it names one. */
|
|
31
|
+
export declare function hostOf(url: string): string | undefined;
|
|
32
|
+
/** Whether `repository` has the shape `RepositoryInput` describes, for callers without types. */
|
|
33
|
+
export declare function isRepositoryInput(repository: unknown): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The repository this job deploys from: `repository` when given, else the
|
|
36
|
+
* one the CI's variables name, else the `origin` remote of the clone in
|
|
37
|
+
* `cwd`. A full name becomes a URL on its host. Undefined when none of them
|
|
38
|
+
* names one.
|
|
39
|
+
*/
|
|
40
|
+
export declare function identifyRepository(git: GitDriver, { cwd, env, repository, }: {
|
|
41
|
+
cwd: string;
|
|
42
|
+
env: CiEnvironment;
|
|
43
|
+
repository: RepositoryInput | undefined;
|
|
44
|
+
}): Promise<IdentifiedRepository | undefined>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApiConfig } from "../../../api-types.js";
|
|
2
|
+
import type { SdkDependencies } from "../../dependencies.js";
|
|
3
|
+
import type { GitDriver } from "../collectCommitChanges/types.js";
|
|
4
|
+
import type { CoverageContracts } from "./contracts.js";
|
|
5
|
+
import type { FindRepositoryCoverageParams, FindRepositoryCoverageResult } from "./types.js";
|
|
6
|
+
export type RepositoryCoverageDependencies = SdkDependencies & {
|
|
7
|
+
contracts: CoverageContracts;
|
|
8
|
+
git: GitDriver;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Works out which repository this job deploys from and asks QA Wolf what it
|
|
12
|
+
* can read there. It never fails: a repository it can't find, or an answer
|
|
13
|
+
* it can't get, is `unknown` coverage with the reason, which it also logs.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findCoverageOfRepository(deps: RepositoryCoverageDependencies, apiConfig: ApiConfig, { cwd, env, repository, workspaceId, }?: FindRepositoryCoverageParams): Promise<FindRepositoryCoverageResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jest } from "@jest/globals";
|
|
2
|
+
import type { ApiConfig } from "../../../api-types.js";
|
|
3
|
+
import type { FetchDriver } from "../../dependencies.js";
|
|
4
|
+
import type { GitDriver } from "../collectCommitChanges/types.js";
|
|
5
|
+
import type { CoverageContracts } from "./contracts.js";
|
|
6
|
+
export declare const apiConfig: ApiConfig;
|
|
7
|
+
export declare const coveredByStandardApp: {
|
|
8
|
+
coverage: string;
|
|
9
|
+
fullName: string;
|
|
10
|
+
permissions: {
|
|
11
|
+
code: string;
|
|
12
|
+
pullRequests: string;
|
|
13
|
+
};
|
|
14
|
+
provider: string;
|
|
15
|
+
settingsUrl: string;
|
|
16
|
+
};
|
|
17
|
+
/** A response with QA Wolf's answer to the repository check. */
|
|
18
|
+
export declare const coverageAnswer: (answer: unknown) => Response;
|
|
19
|
+
export declare function makeCoverageDeps({ answer, contracts, git, }?: {
|
|
20
|
+
answer?: Response;
|
|
21
|
+
contracts?: CoverageContracts;
|
|
22
|
+
git?: GitDriver;
|
|
23
|
+
}): {
|
|
24
|
+
deps: {
|
|
25
|
+
clock: {
|
|
26
|
+
now: () => number;
|
|
27
|
+
sleep: import("jest-mock").Mock<() => Promise<undefined>>;
|
|
28
|
+
};
|
|
29
|
+
contracts: CoverageContracts;
|
|
30
|
+
fetch: import("jest-mock").Mock<typeof globalThis.fetch>;
|
|
31
|
+
git: GitDriver;
|
|
32
|
+
log: {
|
|
33
|
+
error: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
34
|
+
info: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
35
|
+
warn: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
fetch: import("jest-mock").Mock<typeof globalThis.fetch>;
|
|
39
|
+
log: {
|
|
40
|
+
error: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
41
|
+
info: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
42
|
+
warn: import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** The input the repository check sent. */
|
|
46
|
+
export declare function sentCoverageInput(fetch: jest.Mock<FetchDriver>): unknown;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { IdentifiedRepository, RepositoryInput } from "./identifyRepository.js";
|
|
2
|
+
export type { IdentifiedRepository, RepositoryInput, } from "./identifyRepository.js";
|
|
3
|
+
/** Access to the repository's code and commits. More values may be added. */
|
|
4
|
+
export type CodeAccess = "no-access" | "read" | "write" | (string & {});
|
|
5
|
+
/** Access to the repository's pull requests. More values may be added. */
|
|
6
|
+
export type PullRequestAccess = "read" | "write" | (string & {});
|
|
7
|
+
/** Why QA Wolf's coverage of a repository is unknown. More values may be added. */
|
|
8
|
+
export type CoverageUnknownReason =
|
|
9
|
+
/** The `repository` given doesn't have the shape `RepositoryInput` describes. */
|
|
10
|
+
"invalid-repository"
|
|
11
|
+
/** The installed `@qawolf/api-contracts` is too old to check a repository. */
|
|
12
|
+
| "outdated-contracts"
|
|
13
|
+
/** No repository was given, and neither the CI's variables nor the `origin` git remote name one. */
|
|
14
|
+
| "repository-not-found"
|
|
15
|
+
/** The call to QA Wolf failed. */
|
|
16
|
+
| "request-failed"
|
|
17
|
+
/** QA Wolf answered with something this SDK version can't use. */
|
|
18
|
+
| "unexpected-answer"
|
|
19
|
+
/** QA Wolf doesn't recognize the URL as a repository URL. */
|
|
20
|
+
| "unrecognized-url" | (string & {});
|
|
21
|
+
/**
|
|
22
|
+
* What QA Wolf can read of a repository through the workspace's code host
|
|
23
|
+
* integrations. More values may be added in minor versions; treat one you
|
|
24
|
+
* don't handle like `unknown`.
|
|
25
|
+
*/
|
|
26
|
+
export type RepositoryCoverage = {
|
|
27
|
+
/** The repository's full name as QA Wolf knows it, e.g. `acme/storefront`. */
|
|
28
|
+
fullName: string;
|
|
29
|
+
permissions: {
|
|
30
|
+
code: CodeAccess;
|
|
31
|
+
pullRequests: PullRequestAccess;
|
|
32
|
+
};
|
|
33
|
+
/** The code host the integration connects, e.g. `github` or `gitlab`. */
|
|
34
|
+
provider: string;
|
|
35
|
+
/** Where a workspace admin manages the integration, when QA Wolf said. */
|
|
36
|
+
settingsUrl: string | undefined;
|
|
37
|
+
status: "covered";
|
|
38
|
+
} | {
|
|
39
|
+
/** Where a workspace admin connects the code host, when QA Wolf said. */
|
|
40
|
+
settingsUrl: string | undefined;
|
|
41
|
+
status: "not-covered";
|
|
42
|
+
}
|
|
43
|
+
/** The repository is on a code host QA Wolf doesn't connect to. */
|
|
44
|
+
| {
|
|
45
|
+
status: "unsupported-host";
|
|
46
|
+
} | {
|
|
47
|
+
message: string;
|
|
48
|
+
reason: CoverageUnknownReason;
|
|
49
|
+
status: "unknown";
|
|
50
|
+
};
|
|
51
|
+
export type FindRepositoryCoverageParams = {
|
|
52
|
+
/**
|
|
53
|
+
* The repository folder; the current directory when unset. The CI's
|
|
54
|
+
* variables name the repository the job was started for, so pass
|
|
55
|
+
* `repository` too when `cwd` is a checkout of another one.
|
|
56
|
+
*/
|
|
57
|
+
cwd?: string;
|
|
58
|
+
/** The variables to read the CI's repository from, defaulting to `process.env`. */
|
|
59
|
+
env?: Record<string, string | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* The repository to check. When unset, the CI's own variables name it, or
|
|
62
|
+
* the clone's `origin` remote. Credentials in a URL are removed before it's
|
|
63
|
+
* sent.
|
|
64
|
+
*/
|
|
65
|
+
repository?: RepositoryInput;
|
|
66
|
+
/** The workspace to check. Only needed with an organization or user API key. */
|
|
67
|
+
workspaceId?: string;
|
|
68
|
+
};
|
|
69
|
+
export type FindRepositoryCoverageResult = {
|
|
70
|
+
coverage: RepositoryCoverage;
|
|
71
|
+
/** The repository checked, or undefined when none was found. */
|
|
72
|
+
repository: IdentifiedRepository | undefined;
|
|
73
|
+
};
|
package/dist/lib/sdk/index.d.ts
CHANGED
|
@@ -12,32 +12,42 @@ export declare function makeQaWolfSdk({ apiKey, serviceBase, userAgent, }: {
|
|
|
12
12
|
* triggers do not see. Use `deployment.reportStatus` instead.
|
|
13
13
|
*/
|
|
14
14
|
attemptNotifyDeploy: (config: Partial<import("./domain/attemptDeploy/deployConfig.js").DeployConfig>) => Promise<import("./domain/attemptDeploy/types.js").NotifyDeployStatus>;
|
|
15
|
+
codeHostIntegration: {
|
|
16
|
+
/** Works out this job's repository and asks QA Wolf what it can read there. */
|
|
17
|
+
findForRepository: (args_0?: import("./domain/repositoryCoverage/types.js").FindRepositoryCoverageParams | undefined) => Promise<import("./domain/repositoryCoverage/types.js").FindRepositoryCoverageResult>;
|
|
18
|
+
};
|
|
15
19
|
deployment: {
|
|
16
20
|
/** Builds `changes` for `reportStatus` from the local git history; sends nothing itself. */
|
|
17
21
|
collectCommitChanges: (args_0: import("./domain/collectCommitChanges/types.js").CollectCommitChangesParams) => Promise<import("./domain/collectCommitChanges/types.js").CollectCommitChangesResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Builds `changes` for `reportStatus` from the deploy's commits, including
|
|
24
|
+
* ones QA Wolf can't read of the repository, with ids, your filter and
|
|
25
|
+
* redaction applied; sends nothing itself.
|
|
26
|
+
*/
|
|
27
|
+
collectDeployChanges: (params: import("./domain/collectDeployChanges/types.js").CollectDeployChangesParams) => Promise<import("./domain/collectDeployChanges/types.js").CollectDeployChangesResult>;
|
|
18
28
|
reportStatus: (params: {
|
|
19
29
|
providerDeploymentId: string;
|
|
20
|
-
status: "success" | "
|
|
30
|
+
status: "success" | "failure" | "inactive" | "pending";
|
|
21
31
|
workspaceId: string;
|
|
22
32
|
builds?: string[] | undefined;
|
|
23
33
|
changes?: {
|
|
24
34
|
ci?: string | undefined;
|
|
25
35
|
items?: ({
|
|
26
|
-
kind: "pull-request";
|
|
27
36
|
title: string;
|
|
28
|
-
|
|
29
|
-
number?: number | undefined;
|
|
37
|
+
kind: "pull-request";
|
|
30
38
|
changedPaths?: string[] | undefined;
|
|
31
39
|
description?: string | undefined;
|
|
32
40
|
url?: string | undefined;
|
|
41
|
+
mergeCommitSha?: string | undefined;
|
|
42
|
+
number?: number | undefined;
|
|
33
43
|
} | {
|
|
34
|
-
kind: "commit";
|
|
35
44
|
title: string;
|
|
36
|
-
|
|
37
|
-
sha?: string | undefined;
|
|
45
|
+
kind: "commit";
|
|
38
46
|
changedPaths?: string[] | undefined;
|
|
39
47
|
description?: string | undefined;
|
|
40
48
|
url?: string | undefined;
|
|
49
|
+
pullRequestNumber?: number | undefined;
|
|
50
|
+
sha?: string | undefined;
|
|
41
51
|
})[] | undefined;
|
|
42
52
|
omittedCount?: number | undefined;
|
|
43
53
|
problems?: ({
|
|
@@ -101,7 +111,7 @@ export declare function makeQaWolfSdk({ apiKey, serviceBase, userAgent, }: {
|
|
|
101
111
|
} | {
|
|
102
112
|
deploymentId: string;
|
|
103
113
|
outcome: "not-tested";
|
|
104
|
-
reason: "no-
|
|
114
|
+
reason: "no-run-created" | "no-trigger-matched";
|
|
105
115
|
triggers: {
|
|
106
116
|
message: string;
|
|
107
117
|
triggerName: string;
|
|
@@ -265,11 +275,13 @@ export declare function makeQaWolfSdk({ apiKey, serviceBase, userAgent, }: {
|
|
|
265
275
|
};
|
|
266
276
|
export type * from "./domain/attemptDeploy/index.js";
|
|
267
277
|
export type * from "./domain/collectCommitChanges/types.js";
|
|
278
|
+
export type * from "./domain/collectDeployChanges/types.js";
|
|
268
279
|
export type * from "./domain/environment/types.js";
|
|
269
280
|
export type * from "./domain/generateSignedUrls/types.js";
|
|
270
281
|
export type * from "./domain/notifyTerminatedEphemeralEnvironment/types.js";
|
|
271
282
|
export type * from "./domain/pollCiGreenlight/types.js";
|
|
272
283
|
export type * from "./domain/promotion/types.js";
|
|
273
284
|
export type * from "./domain/reportDeployment/types.js";
|
|
285
|
+
export type * from "./domain/repositoryCoverage/types.js";
|
|
274
286
|
export type * from "./domain/uploadBuild/types.js";
|
|
275
287
|
export type * from "./domain/waitForVerdict/types.js";
|