@gitkraken/core-gitlens 0.40.0 → 0.43.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/CHANGELOG.md +25 -1
- package/dist/git/models/issue.d.ts +2 -0
- package/dist/git/models/issue.js.map +1 -1
- package/dist/git/models/issueOrPullRequest.d.ts +4 -0
- package/dist/git/models/pullRequest.d.ts +57 -1
- package/dist/git/models/pullRequest.js +5 -1
- package/dist/git/models/pullRequest.js.map +1 -1
- package/dist/git/models/pullRequestActivity.d.ts +55 -0
- package/dist/git/models/pullRequestActivity.js +0 -0
- package/dist/git/utils/pullRequest.utils.js +3 -1
- package/dist/git/utils/pullRequest.utils.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +1 -0
- package/dist/git/watching/worktreeSummary.js +34 -2
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/plus/git-github/api/aliasedQuery.d.ts +19 -0
- package/dist/plus/git-github/api/aliasedQuery.js +21 -0
- package/dist/plus/git-github/api/aliasedQuery.js.map +1 -0
- package/dist/plus/git-github/api/cancellation.d.ts +4 -0
- package/dist/plus/git-github/api/cancellation.js +9 -0
- package/dist/plus/git-github/api/cancellation.js.map +1 -0
- package/dist/plus/git-github/api/checkRunLogs.d.ts +31 -0
- package/dist/plus/git-github/api/checkRunLogs.js +252 -0
- package/dist/plus/git-github/api/checkRunLogs.js.map +1 -0
- package/dist/plus/git-github/api/checkRuns.d.ts +26 -0
- package/dist/plus/git-github/api/checkRuns.js +191 -0
- package/dist/plus/git-github/api/checkRuns.js.map +1 -0
- package/dist/plus/git-github/api/github.d.ts +23 -6
- package/dist/plus/git-github/api/github.js +174 -39
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +3 -2
- package/dist/plus/git-github/api/issueWrites.js +10 -5
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/git-github/api/pullRequestActivity.d.ts +19 -0
- package/dist/plus/git-github/api/pullRequestActivity.js +355 -0
- package/dist/plus/git-github/api/pullRequestActivity.js.map +1 -0
- package/dist/plus/git-github/models.d.ts +100 -4
- package/dist/plus/git-github/models.js +142 -6
- package/dist/plus/git-github/models.js.map +1 -1
- package/dist/plus/integrations/fieldPresence.d.ts +10 -5
- package/dist/plus/integrations/fieldPresence.js +46 -25
- package/dist/plus/integrations/fieldPresence.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +5 -2
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +26 -1
- package/dist/plus/integrations/integrationService.js +22 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +86 -1
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +31 -1
- package/dist/plus/integrations/models/gitHostIntegration.js +68 -0
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +21 -2
- package/dist/plus/integrations/models/integration.js +20 -1
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/providers/azure/azure.js +20 -14
- package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
- package/dist/plus/integrations/providers/azure/models.js +7 -3
- package/dist/plus/integrations/providers/azure/models.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/bitbucket.js +18 -13
- package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/models.js +5 -2
- package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket-server/models.js +3 -1
- package/dist/plus/integrations/providers/bitbucket-server/models.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +15 -6
- package/dist/plus/integrations/providers/github.js +65 -5
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.js +12 -6
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/models.js +5 -2
- package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js +3 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
- package/dist/plus/integrations/providers/models.js +9 -4
- package/dist/plus/integrations/providers/models.js.map +1 -1
- package/dist/plus/integrations/providers/providerApiClient.js +10 -7
- package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.js +3 -1
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/reads/etag.js +20 -5
- package/dist/plus/integrations/reads/etag.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestActivity.d.ts +36 -0
- package/dist/plus/integrations/reads/pullRequestActivity.js +103 -0
- package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -0
- package/dist/plus/integrations/reads/pullRequestBatch.d.ts +4 -1
- package/dist/plus/integrations/reads/pullRequestBatch.js +5 -2
- package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestBranches.d.ts +2 -0
- package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
- package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +27 -0
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js +92 -0
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -0
- package/docs/integrations.md +111 -14
- package/package.json +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GraphqlResponseError } from "@octokit/graphql";
|
|
2
|
+
import { RequestParameters } from "@octokit/types";
|
|
3
|
+
//#region ../plus/git-github/src/api/aliasedQuery.d.ts
|
|
4
|
+
/** One field-level error GitHub attaches to a GraphQL response, as thrown via {@link GraphqlResponseError}. */
|
|
5
|
+
export type GraphqlAliasError = NonNullable<GraphqlResponseError<unknown>['errors']>[number];
|
|
6
|
+
/** An aliased GraphQL read: the (possibly partial) `data` alongside the field-level errors GitHub attached to it. */
|
|
7
|
+
export type AliasedGraphql = <T>(query: string, variables: RequestParameters) => Promise<{
|
|
8
|
+
readonly data: T;
|
|
9
|
+
readonly errors: readonly GraphqlAliasError[];
|
|
10
|
+
} | undefined>;
|
|
11
|
+
export declare const aliasedQueryChunkSize = 25;
|
|
12
|
+
/**
|
|
13
|
+
* What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every
|
|
14
|
+
* error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND
|
|
15
|
+
* nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAliasErrorVerdict(errors: readonly GraphqlAliasError[], alias: string, node: unknown): 'absent' | PromiseRejectedResult | undefined;
|
|
18
|
+
//#endregion
|
|
19
|
+
//# sourceMappingURL=aliasedQuery.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region ../plus/git-github/src/api/aliasedQuery.ts
|
|
2
|
+
const aliasedQueryChunkSize = 25;
|
|
3
|
+
/**
|
|
4
|
+
* What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every
|
|
5
|
+
* error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND
|
|
6
|
+
* nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.
|
|
7
|
+
*/
|
|
8
|
+
function getAliasErrorVerdict(errors, alias, node) {
|
|
9
|
+
const aliasErrors = errors.filter((e) => e.path?.[0] === alias);
|
|
10
|
+
if (aliasErrors.length === 0) return void 0;
|
|
11
|
+
if (node == null && aliasErrors.every((e) => e.type === "NOT_FOUND")) return "absent";
|
|
12
|
+
const primary = aliasErrors.find((e) => e.type !== "NOT_FOUND") ?? aliasErrors[0];
|
|
13
|
+
return {
|
|
14
|
+
status: "rejected",
|
|
15
|
+
reason: new Error(primary.message)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { aliasedQueryChunkSize, getAliasErrorVerdict };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=aliasedQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliasedQuery.js","names":[],"sources":["../../../../../plus/git-github/src/api/aliasedQuery.ts"],"sourcesContent":["import type { GraphqlResponseError } from '@octokit/graphql';\nimport type { RequestParameters } from '@octokit/types';\n\n/** One field-level error GitHub attaches to a GraphQL response, as thrown via {@link GraphqlResponseError}. */\nexport type GraphqlAliasError = NonNullable<GraphqlResponseError<unknown>['errors']>[number];\n\n/** An aliased GraphQL read: the (possibly partial) `data` alongside the field-level errors GitHub attached to it. */\nexport type AliasedGraphql = <T>(\n\tquery: string,\n\tvariables: RequestParameters,\n) => Promise<{ readonly data: T; readonly errors: readonly GraphqlAliasError[] } | undefined>;\n\nexport const aliasedQueryChunkSize = 25;\n\n/**\n * What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every\n * error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND\n * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.\n */\nexport function getAliasErrorVerdict(\n\terrors: readonly GraphqlAliasError[],\n\talias: string,\n\tnode: unknown,\n): 'absent' | PromiseRejectedResult | undefined {\n\tconst aliasErrors = errors.filter(e => e.path?.[0] === alias);\n\tif (aliasErrors.length === 0) return undefined;\n\tif (node == null && aliasErrors.every(e => e.type === 'NOT_FOUND')) return 'absent';\n\n\tconst primary = aliasErrors.find(e => e.type !== 'NOT_FOUND') ?? aliasErrors[0];\n\treturn { status: 'rejected', reason: new Error(primary.message) };\n}\n"],"mappings":";AAYA,MAAa,wBAAwB;;;;;;AAOrC,SAAgB,qBACf,QACA,OACA,MAC+C;CAC/C,MAAM,cAAc,OAAO,QAAO,MAAK,EAAE,OAAO,OAAO,KAAK;CAC5D,IAAI,YAAY,WAAW,GAAG,OAAO,KAAA;CACrC,IAAI,QAAQ,QAAQ,YAAY,OAAM,MAAK,EAAE,SAAS,WAAW,GAAG,OAAO;CAE3E,MAAM,UAAU,YAAY,MAAK,MAAK,EAAE,SAAS,WAAW,KAAK,YAAY;CAC7E,OAAO;EAAE,QAAQ;EAAY,QAAQ,IAAI,MAAM,QAAQ,OAAO;CAAE;AACjE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CancellationError } from "../../../utils/cancellation.js";
|
|
2
|
+
//#region ../plus/git-github/src/api/cancellation.ts
|
|
3
|
+
function toCancellationError(ex) {
|
|
4
|
+
return ex instanceof Error && ex.name === "AbortError" ? new CancellationError(ex) : ex;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { toCancellationError };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=cancellation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellation.js","names":[],"sources":["../../../../../plus/git-github/src/api/cancellation.ts"],"sourcesContent":["import { CancellationError } from '@gitlens/utils/cancellation.js';\n\nexport function toCancellationError(ex: unknown): unknown {\n\treturn ex instanceof Error && ex.name === 'AbortError' ? new CancellationError(ex) : ex;\n}\n"],"mappings":";;AAEA,SAAgB,oBAAoB,IAAsB;CACzD,OAAO,cAAc,SAAS,GAAG,SAAS,eAAe,IAAI,kBAAkB,EAAE,IAAI;AACtF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PullRequestCheckLog } from "../../../git/models/pullRequest.js";
|
|
2
|
+
import { ScopedLogger } from "../../../utils/logger.scoped.js";
|
|
3
|
+
import { AliasedGraphql } from "./aliasedQuery.js";
|
|
4
|
+
import { GitHubCheckRunRef } from "../models.js";
|
|
5
|
+
//#region ../plus/git-github/src/api/checkRunLogs.d.ts
|
|
6
|
+
export interface GitHubActionsJob {
|
|
7
|
+
readonly owner: string;
|
|
8
|
+
readonly repo: string;
|
|
9
|
+
readonly jobId: number;
|
|
10
|
+
}
|
|
11
|
+
interface GitHubCheckRunLogClient {
|
|
12
|
+
readonly isWeb: boolean;
|
|
13
|
+
readonly graphql: AliasedGraphql;
|
|
14
|
+
requestJobLogRedirect(job: GitHubActionsJob): Promise<{
|
|
15
|
+
status: number;
|
|
16
|
+
location: string | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
requestJobLogStream(job: GitHubActionsJob): Promise<ReadableStream<Uint8Array> | null>;
|
|
19
|
+
requestJobStatus(job: GitHubActionsJob): Promise<string | undefined>;
|
|
20
|
+
fetchStorage(url: string, init: {
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
signal: AbortSignal | undefined;
|
|
23
|
+
}): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
export declare function readGitHubCheckRunLogs(client: GitHubCheckRunLogClient, targets: readonly {
|
|
26
|
+
owner: string;
|
|
27
|
+
repo: string;
|
|
28
|
+
ref: GitHubCheckRunRef;
|
|
29
|
+
}[], tailLines: number, scope: ScopedLogger | undefined, cancellation: AbortSignal | undefined): Promise<PromiseSettledResult<PullRequestCheckLog>[]>;
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=checkRunLogs.d.ts.map
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { CancellationError, isCancellationError } from "../../../utils/cancellation.js";
|
|
2
|
+
import { mapSettledBounded } from "../../../utils/promise.js";
|
|
3
|
+
import { RequestNotFoundError } from "../../../git/errors.js";
|
|
4
|
+
import { getAliasErrorVerdict } from "./aliasedQuery.js";
|
|
5
|
+
import { toCancellationError } from "./cancellation.js";
|
|
6
|
+
import { RequestError } from "@octokit/request-error";
|
|
7
|
+
//#region ../plus/git-github/src/api/checkRunLogs.ts
|
|
8
|
+
const checkRunLogTailBytes = 262144;
|
|
9
|
+
const actionsJobLogConcurrency = 4;
|
|
10
|
+
const wholeJobLogLimitBytes = 20971520;
|
|
11
|
+
async function readGitHubCheckRunLogs(client, targets, tailLines, scope, cancellation) {
|
|
12
|
+
const slots = new Array(targets.length);
|
|
13
|
+
const jobs = [];
|
|
14
|
+
const checkRuns = [];
|
|
15
|
+
targets.forEach((target, index) => {
|
|
16
|
+
switch (target.ref.kind) {
|
|
17
|
+
case "actions-job":
|
|
18
|
+
jobs.push({
|
|
19
|
+
index,
|
|
20
|
+
job: {
|
|
21
|
+
owner: target.owner,
|
|
22
|
+
repo: target.repo,
|
|
23
|
+
jobId: target.ref.jobId
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
break;
|
|
27
|
+
case "check-run":
|
|
28
|
+
checkRuns.push({
|
|
29
|
+
index,
|
|
30
|
+
nodeId: target.ref.nodeId
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case "status": slots[index] = {
|
|
34
|
+
status: "fulfilled",
|
|
35
|
+
value: { unavailable: "no-log" }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const [jobSlots, outputSlots] = await Promise.all([mapSettledBounded(jobs, actionsJobLogConcurrency, ({ job }) => client.isWeb ? readWebJobLog(client, job, tailLines) : readStoredJobLog(client, job, tailLines, cancellation)), readCheckRunOutputs(client.graphql, checkRuns.map((c) => c.nodeId), tailLines, scope)]);
|
|
40
|
+
if (cancellation?.aborted) throw new CancellationError();
|
|
41
|
+
jobs.forEach((job, i) => {
|
|
42
|
+
slots[job.index] = jobSlots[i];
|
|
43
|
+
});
|
|
44
|
+
checkRuns.forEach((checkRun, i) => {
|
|
45
|
+
slots[checkRun.index] = outputSlots[i];
|
|
46
|
+
});
|
|
47
|
+
return slots;
|
|
48
|
+
}
|
|
49
|
+
async function readCheckRunOutputs(graphql, nodeIds, tailLines, scope) {
|
|
50
|
+
if (nodeIds.length === 0) return [];
|
|
51
|
+
const variables = {};
|
|
52
|
+
nodeIds.forEach((nodeId, i) => {
|
|
53
|
+
variables[`i${i}`] = nodeId;
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
const rsp = await graphql(checkRunOutputsQuery(nodeIds.length), variables);
|
|
57
|
+
if (rsp?.data == null) throw new Error("GitHub returned no data for the check run outputs");
|
|
58
|
+
const { data, errors } = rsp;
|
|
59
|
+
return nodeIds.map((_, i) => {
|
|
60
|
+
const alias = `c${i}`;
|
|
61
|
+
const node = data[alias];
|
|
62
|
+
const verdict = getAliasErrorVerdict(errors, alias, node);
|
|
63
|
+
if (verdict != null && verdict !== "absent") return verdict;
|
|
64
|
+
const text = checkRunOutputText(node);
|
|
65
|
+
return {
|
|
66
|
+
status: "fulfilled",
|
|
67
|
+
value: text != null ? { log: tailLogText(text, {
|
|
68
|
+
partialFirstLine: false,
|
|
69
|
+
tailLines,
|
|
70
|
+
source: "check-run-output"
|
|
71
|
+
}) } : { unavailable: "no-log" }
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
} catch (ex) {
|
|
75
|
+
if (isCancellationError(ex)) throw ex;
|
|
76
|
+
scope?.warn(`failed to read check run outputs; ex=${ex}`);
|
|
77
|
+
return nodeIds.map(() => ({
|
|
78
|
+
status: "rejected",
|
|
79
|
+
reason: ex
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function checkRunOutputsQuery(count) {
|
|
84
|
+
return `query getCheckRunOutputs(
|
|
85
|
+
${Array.from({ length: count }, (_, i) => `$i${i}: ID!`).join("\n ")}
|
|
86
|
+
) {
|
|
87
|
+
${Array.from({ length: count }, (_, i) => `c${i}: node(id: $i${i}) { ... on CheckRun { title summary text } }`).join("\n ")}
|
|
88
|
+
}`;
|
|
89
|
+
}
|
|
90
|
+
function checkRunOutputText(output) {
|
|
91
|
+
const parts = [
|
|
92
|
+
output?.title,
|
|
93
|
+
output?.summary,
|
|
94
|
+
output?.text
|
|
95
|
+
].filter((part) => part != null && part.trim().length !== 0);
|
|
96
|
+
return parts.length !== 0 ? parts.join("\n\n") : void 0;
|
|
97
|
+
}
|
|
98
|
+
async function readWebJobLog(client, job, tailLines) {
|
|
99
|
+
let stream;
|
|
100
|
+
try {
|
|
101
|
+
stream = await client.requestJobLogStream(job);
|
|
102
|
+
} catch (ex) {
|
|
103
|
+
return readMissingJobLog(client, job, ex);
|
|
104
|
+
}
|
|
105
|
+
return readWholeJobLog(stream, tailLines);
|
|
106
|
+
}
|
|
107
|
+
async function readStoredJobLog(client, job, tailLines, cancellation) {
|
|
108
|
+
let redirect;
|
|
109
|
+
try {
|
|
110
|
+
redirect = await client.requestJobLogRedirect(job);
|
|
111
|
+
} catch (ex) {
|
|
112
|
+
return readMissingJobLog(client, job, ex);
|
|
113
|
+
}
|
|
114
|
+
if (redirect.status !== 302 || !redirect.location) throw new Error(`GitHub answered ${redirect.status} without a job log location`);
|
|
115
|
+
const url = redirect.location;
|
|
116
|
+
const probe = await fetchStorage(client, url, "bytes=0-0", cancellation);
|
|
117
|
+
if (probe.status === 200) return readWholeJobLog(probe.body, tailLines);
|
|
118
|
+
if (probe.status !== 206) {
|
|
119
|
+
await discardBody(probe);
|
|
120
|
+
if (probe.status === 404 || probe.status === 416) return { unavailable: "no-log" };
|
|
121
|
+
throw new Error(`GitHub job log storage answered ${probe.status}`);
|
|
122
|
+
}
|
|
123
|
+
const total = parseContentRangeTotal(probe.headers.get("content-range"));
|
|
124
|
+
await discardBody(probe);
|
|
125
|
+
if (total == null) throw new Error("GitHub job log storage answered without the log size");
|
|
126
|
+
if (total === 0) return { unavailable: "no-log" };
|
|
127
|
+
const start = Math.max(0, total - checkRunLogTailBytes);
|
|
128
|
+
const tail = await fetchStorage(client, url, `bytes=${start}-`, cancellation);
|
|
129
|
+
if (tail.status === 200) return readWholeJobLog(tail.body, tailLines);
|
|
130
|
+
if (tail.status !== 206) {
|
|
131
|
+
await discardBody(tail);
|
|
132
|
+
if (tail.status === 404 || tail.status === 416) return { unavailable: "no-log" };
|
|
133
|
+
throw new Error(`GitHub job log storage answered ${tail.status}`);
|
|
134
|
+
}
|
|
135
|
+
return { log: toJobLogText(new Uint8Array(await readBody(tail)), start > 0, tailLines) };
|
|
136
|
+
}
|
|
137
|
+
async function readMissingJobLog(client, job, ex) {
|
|
138
|
+
if (!isNotFoundStatus(ex, 404, 410)) throw ex;
|
|
139
|
+
try {
|
|
140
|
+
return { unavailable: await client.requestJobStatus(job) === "completed" ? "log-expired" : "log-not-ready" };
|
|
141
|
+
} catch (statusEx) {
|
|
142
|
+
if (isNotFoundStatus(statusEx, 404)) return { unavailable: "no-log" };
|
|
143
|
+
throw statusEx;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function fetchStorage(client, url, range, cancellation) {
|
|
147
|
+
if (cancellation?.aborted) throw new CancellationError();
|
|
148
|
+
try {
|
|
149
|
+
return await client.fetchStorage(url, {
|
|
150
|
+
headers: { Range: range },
|
|
151
|
+
signal: cancellation
|
|
152
|
+
});
|
|
153
|
+
} catch (ex) {
|
|
154
|
+
throw toCancellationError(ex);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function readWholeJobLog(stream, tailLines) {
|
|
158
|
+
const tail = await readStreamTail(stream, checkRunLogTailBytes, wholeJobLogLimitBytes);
|
|
159
|
+
if (tail == null) return { unavailable: "log-too-large" };
|
|
160
|
+
if (tail.bytes.byteLength === 0) return { unavailable: "no-log" };
|
|
161
|
+
return { log: toJobLogText(tail.bytes, tail.skipped, tailLines) };
|
|
162
|
+
}
|
|
163
|
+
async function readStreamTail(stream, keepBytes, limitBytes) {
|
|
164
|
+
if (stream == null) return {
|
|
165
|
+
bytes: /* @__PURE__ */ new Uint8Array(0),
|
|
166
|
+
skipped: false
|
|
167
|
+
};
|
|
168
|
+
const reader = stream.getReader();
|
|
169
|
+
const chunks = [];
|
|
170
|
+
let kept = 0;
|
|
171
|
+
let read = 0;
|
|
172
|
+
let skipped = false;
|
|
173
|
+
try {
|
|
174
|
+
for (;;) {
|
|
175
|
+
const { done, value } = await reader.read();
|
|
176
|
+
if (done) break;
|
|
177
|
+
read += value.byteLength;
|
|
178
|
+
if (read > limitBytes) {
|
|
179
|
+
await reader.cancel();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
chunks.push(value);
|
|
183
|
+
kept += value.byteLength;
|
|
184
|
+
while (chunks.length > 1 && kept - chunks[0].byteLength >= keepBytes) {
|
|
185
|
+
kept -= chunks[0].byteLength;
|
|
186
|
+
chunks.shift();
|
|
187
|
+
skipped = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} catch (ex) {
|
|
191
|
+
throw toCancellationError(ex);
|
|
192
|
+
} finally {
|
|
193
|
+
reader.releaseLock();
|
|
194
|
+
}
|
|
195
|
+
const bytes = new Uint8Array(kept);
|
|
196
|
+
let offset = 0;
|
|
197
|
+
for (const chunk of chunks) {
|
|
198
|
+
bytes.set(chunk, offset);
|
|
199
|
+
offset += chunk.byteLength;
|
|
200
|
+
}
|
|
201
|
+
const start = Math.max(0, bytes.byteLength - keepBytes);
|
|
202
|
+
return {
|
|
203
|
+
bytes: bytes.subarray(start),
|
|
204
|
+
skipped: skipped || start > 0
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function parseContentRangeTotal(header) {
|
|
208
|
+
const match = header != null ? /^bytes \d+-\d+\/(\d+)$/i.exec(header.trim()) : null;
|
|
209
|
+
if (match == null) return void 0;
|
|
210
|
+
const total = Number(match[1]);
|
|
211
|
+
return Number.isSafeInteger(total) ? total : void 0;
|
|
212
|
+
}
|
|
213
|
+
function toJobLogText(bytes, skipped, tailLines) {
|
|
214
|
+
return tailLogText(new TextDecoder("utf-8").decode(bytes), {
|
|
215
|
+
partialFirstLine: skipped,
|
|
216
|
+
tailLines,
|
|
217
|
+
source: "actions-job-log"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function tailLogText(text, options) {
|
|
221
|
+
let normalized = text.replace(/\r\n/g, "\n");
|
|
222
|
+
if (options.partialFirstLine) {
|
|
223
|
+
const newline = normalized.indexOf("\n");
|
|
224
|
+
normalized = newline === -1 ? "" : normalized.slice(newline + 1);
|
|
225
|
+
}
|
|
226
|
+
const lines = normalized.length !== 0 ? normalized.split("\n") : [];
|
|
227
|
+
if (lines.at(-1) === "") lines.pop();
|
|
228
|
+
const kept = lines.length > options.tailLines ? lines.slice(-options.tailLines) : lines;
|
|
229
|
+
return {
|
|
230
|
+
text: kept.join("\n"),
|
|
231
|
+
lineCount: kept.length,
|
|
232
|
+
truncated: options.partialFirstLine || lines.length > kept.length,
|
|
233
|
+
source: options.source
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async function readBody(rsp) {
|
|
237
|
+
try {
|
|
238
|
+
return await rsp.arrayBuffer();
|
|
239
|
+
} catch (ex) {
|
|
240
|
+
throw toCancellationError(ex);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function discardBody(rsp) {
|
|
244
|
+
await readBody(rsp);
|
|
245
|
+
}
|
|
246
|
+
function isNotFoundStatus(ex, ...statuses) {
|
|
247
|
+
return RequestNotFoundError.is(ex) && ex.original instanceof RequestError && statuses.includes(ex.original.status);
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
export { readGitHubCheckRunLogs };
|
|
251
|
+
|
|
252
|
+
//# sourceMappingURL=checkRunLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkRunLogs.js","names":[],"sources":["../../../../../plus/git-github/src/api/checkRunLogs.ts"],"sourcesContent":["import { RequestError } from '@octokit/request-error';\nimport { RequestNotFoundError } from '@gitlens/git/errors.js';\nimport type { PullRequestCheckLog, PullRequestCheckLogText } from '@gitlens/git/models/pullRequest.js';\nimport { CancellationError, isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { ScopedLogger } from '@gitlens/utils/logger.scoped.js';\nimport { mapSettledBounded } from '@gitlens/utils/promise.js';\nimport type { GitHubCheckRunRef } from '../models.js';\nimport type { AliasedGraphql } from './aliasedQuery.js';\nimport { getAliasErrorVerdict } from './aliasedQuery.js';\nimport { toCancellationError } from './cancellation.js';\n\nexport interface GitHubActionsJob {\n\treadonly owner: string;\n\treadonly repo: string;\n\treadonly jobId: number;\n}\n\ninterface GitHubCheckRunLogClient {\n\treadonly isWeb: boolean;\n\treadonly graphql: AliasedGraphql;\n\trequestJobLogRedirect(job: GitHubActionsJob): Promise<{ status: number; location: string | undefined }>;\n\trequestJobLogStream(job: GitHubActionsJob): Promise<ReadableStream<Uint8Array> | null>;\n\trequestJobStatus(job: GitHubActionsJob): Promise<string | undefined>;\n\tfetchStorage(\n\t\turl: string,\n\t\tinit: { headers: Record<string, string>; signal: AbortSignal | undefined },\n\t): Promise<Response>;\n}\n\ntype CheckRunOutput = { title?: string | null; summary?: string | null; text?: string | null };\n\nconst checkRunLogTailBytes = 262144;\nconst actionsJobLogConcurrency = 4;\nconst wholeJobLogLimitBytes = 20 * 1024 * 1024;\n\nexport async function readGitHubCheckRunLogs(\n\tclient: GitHubCheckRunLogClient,\n\ttargets: readonly { owner: string; repo: string; ref: GitHubCheckRunRef }[],\n\ttailLines: number,\n\tscope: ScopedLogger | undefined,\n\tcancellation: AbortSignal | undefined,\n): Promise<PromiseSettledResult<PullRequestCheckLog>[]> {\n\tconst slots = new Array<PromiseSettledResult<PullRequestCheckLog>>(targets.length);\n\tconst jobs: { index: number; job: GitHubActionsJob }[] = [];\n\tconst checkRuns: { index: number; nodeId: string }[] = [];\n\ttargets.forEach((target, index) => {\n\t\tswitch (target.ref.kind) {\n\t\t\tcase 'actions-job':\n\t\t\t\tjobs.push({ index: index, job: { owner: target.owner, repo: target.repo, jobId: target.ref.jobId } });\n\t\t\t\tbreak;\n\t\t\tcase 'check-run':\n\t\t\t\tcheckRuns.push({ index: index, nodeId: target.ref.nodeId });\n\t\t\t\tbreak;\n\t\t\tcase 'status':\n\t\t\t\tslots[index] = { status: 'fulfilled', value: { unavailable: 'no-log' } };\n\t\t\t\tbreak;\n\t\t}\n\t});\n\n\tconst [jobSlots, outputSlots] = await Promise.all([\n\t\tmapSettledBounded(jobs, actionsJobLogConcurrency, ({ job }) =>\n\t\t\tclient.isWeb\n\t\t\t\t? readWebJobLog(client, job, tailLines)\n\t\t\t\t: readStoredJobLog(client, job, tailLines, cancellation),\n\t\t),\n\t\treadCheckRunOutputs(\n\t\t\tclient.graphql,\n\t\t\tcheckRuns.map(c => c.nodeId),\n\t\t\ttailLines,\n\t\t\tscope,\n\t\t),\n\t]);\n\tif (cancellation?.aborted) throw new CancellationError();\n\n\tjobs.forEach((job, i) => {\n\t\tslots[job.index] = jobSlots[i];\n\t});\n\tcheckRuns.forEach((checkRun, i) => {\n\t\tslots[checkRun.index] = outputSlots[i];\n\t});\n\treturn slots;\n}\n\nasync function readCheckRunOutputs(\n\tgraphql: AliasedGraphql,\n\tnodeIds: readonly string[],\n\ttailLines: number,\n\tscope: ScopedLogger | undefined,\n): Promise<PromiseSettledResult<PullRequestCheckLog>[]> {\n\tif (nodeIds.length === 0) return [];\n\n\tconst variables: Record<string, unknown> = {};\n\tnodeIds.forEach((nodeId, i) => {\n\t\tvariables[`i${i}`] = nodeId;\n\t});\n\n\ttry {\n\t\tconst rsp = await graphql<Record<string, CheckRunOutput | null | undefined>>(\n\t\t\tcheckRunOutputsQuery(nodeIds.length),\n\t\t\tvariables,\n\t\t);\n\t\tif (rsp?.data == null) throw new Error('GitHub returned no data for the check run outputs');\n\n\t\tconst { data, errors } = rsp;\n\t\treturn nodeIds.map((_, i): PromiseSettledResult<PullRequestCheckLog> => {\n\t\t\tconst alias = `c${i}`;\n\t\t\tconst node = data[alias];\n\t\t\tconst verdict = getAliasErrorVerdict(errors, alias, node);\n\t\t\tif (verdict != null && verdict !== 'absent') return verdict;\n\n\t\t\tconst text = checkRunOutputText(node);\n\t\t\treturn {\n\t\t\t\tstatus: 'fulfilled',\n\t\t\t\tvalue:\n\t\t\t\t\ttext != null\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tlog: tailLogText(text, {\n\t\t\t\t\t\t\t\t\tpartialFirstLine: false,\n\t\t\t\t\t\t\t\t\ttailLines: tailLines,\n\t\t\t\t\t\t\t\t\tsource: 'check-run-output',\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: { unavailable: 'no-log' },\n\t\t\t};\n\t\t});\n\t} catch (ex) {\n\t\tif (isCancellationError(ex)) throw ex;\n\n\t\tscope?.warn(`failed to read check run outputs; ex=${ex}`);\n\t\treturn nodeIds.map((): PromiseRejectedResult => ({ status: 'rejected', reason: ex }));\n\t}\n}\n\nfunction checkRunOutputsQuery(count: number): string {\n\tconst params = Array.from({ length: count }, (_, i) => `$i${i}: ID!`).join('\\n\\t\\t\\t\\t');\n\tconst fields = Array.from(\n\t\t{ length: count },\n\t\t(_, i) => `c${i}: node(id: $i${i}) { ... on CheckRun { title summary text } }`,\n\t).join('\\n\\t\\t\\t\\t');\n\treturn `query getCheckRunOutputs(\n\t\t\t\t${params}\n\t\t\t) {\n\t\t\t\t${fields}\n\t\t\t}`;\n}\n\nfunction checkRunOutputText(output: CheckRunOutput | null | undefined): string | undefined {\n\tconst parts = [output?.title, output?.summary, output?.text].filter(\n\t\t(part): part is string => part != null && part.trim().length !== 0,\n\t);\n\treturn parts.length !== 0 ? parts.join('\\n\\n') : undefined;\n}\n\nasync function readWebJobLog(\n\tclient: GitHubCheckRunLogClient,\n\tjob: GitHubActionsJob,\n\ttailLines: number,\n): Promise<PullRequestCheckLog> {\n\tlet stream: ReadableStream<Uint8Array> | null;\n\ttry {\n\t\tstream = await client.requestJobLogStream(job);\n\t} catch (ex) {\n\t\treturn readMissingJobLog(client, job, ex);\n\t}\n\n\treturn readWholeJobLog(stream, tailLines);\n}\n\nasync function readStoredJobLog(\n\tclient: GitHubCheckRunLogClient,\n\tjob: GitHubActionsJob,\n\ttailLines: number,\n\tcancellation: AbortSignal | undefined,\n): Promise<PullRequestCheckLog> {\n\tlet redirect: { status: number; location: string | undefined };\n\ttry {\n\t\tredirect = await client.requestJobLogRedirect(job);\n\t} catch (ex) {\n\t\treturn readMissingJobLog(client, job, ex);\n\t}\n\tif (redirect.status !== 302 || !redirect.location) {\n\t\tthrow new Error(`GitHub answered ${redirect.status} without a job log location`);\n\t}\n\n\tconst url = redirect.location;\n\tconst probe = await fetchStorage(client, url, 'bytes=0-0', cancellation);\n\tif (probe.status === 200) return readWholeJobLog(probe.body, tailLines);\n\n\tif (probe.status !== 206) {\n\t\tawait discardBody(probe);\n\t\tif (probe.status === 404 || probe.status === 416) return { unavailable: 'no-log' };\n\n\t\tthrow new Error(`GitHub job log storage answered ${probe.status}`);\n\t}\n\n\tconst total = parseContentRangeTotal(probe.headers.get('content-range'));\n\tawait discardBody(probe);\n\tif (total == null) throw new Error('GitHub job log storage answered without the log size');\n\tif (total === 0) return { unavailable: 'no-log' };\n\n\tconst start = Math.max(0, total - checkRunLogTailBytes);\n\tconst tail = await fetchStorage(client, url, `bytes=${start}-`, cancellation);\n\tif (tail.status === 200) return readWholeJobLog(tail.body, tailLines);\n\n\tif (tail.status !== 206) {\n\t\tawait discardBody(tail);\n\t\tif (tail.status === 404 || tail.status === 416) return { unavailable: 'no-log' };\n\n\t\tthrow new Error(`GitHub job log storage answered ${tail.status}`);\n\t}\n\n\tconst bytes = new Uint8Array(await readBody(tail));\n\treturn { log: toJobLogText(bytes, start > 0, tailLines) };\n}\n\nasync function readMissingJobLog(\n\tclient: GitHubCheckRunLogClient,\n\tjob: GitHubActionsJob,\n\tex: unknown,\n): Promise<PullRequestCheckLog> {\n\tif (!isNotFoundStatus(ex, 404, 410)) throw ex;\n\n\ttry {\n\t\tconst status = await client.requestJobStatus(job);\n\t\treturn { unavailable: status === 'completed' ? 'log-expired' : 'log-not-ready' };\n\t} catch (statusEx) {\n\t\tif (isNotFoundStatus(statusEx, 404)) return { unavailable: 'no-log' };\n\n\t\tthrow statusEx;\n\t}\n}\n\nasync function fetchStorage(\n\tclient: GitHubCheckRunLogClient,\n\turl: string,\n\trange: string,\n\tcancellation: AbortSignal | undefined,\n): Promise<Response> {\n\tif (cancellation?.aborted) throw new CancellationError();\n\n\ttry {\n\t\treturn await client.fetchStorage(url, { headers: { Range: range }, signal: cancellation });\n\t} catch (ex) {\n\t\tthrow toCancellationError(ex);\n\t}\n}\n\nasync function readWholeJobLog(\n\tstream: ReadableStream<Uint8Array> | null,\n\ttailLines: number,\n): Promise<PullRequestCheckLog> {\n\tconst tail = await readStreamTail(stream, checkRunLogTailBytes, wholeJobLogLimitBytes);\n\tif (tail == null) return { unavailable: 'log-too-large' };\n\tif (tail.bytes.byteLength === 0) return { unavailable: 'no-log' };\n\n\treturn { log: toJobLogText(tail.bytes, tail.skipped, tailLines) };\n}\n\nasync function readStreamTail(\n\tstream: ReadableStream<Uint8Array> | null,\n\tkeepBytes: number,\n\tlimitBytes: number,\n): Promise<{ bytes: Uint8Array; skipped: boolean } | undefined> {\n\tif (stream == null) return { bytes: new Uint8Array(0), skipped: false };\n\n\tconst reader = stream.getReader();\n\tconst chunks: Uint8Array[] = [];\n\tlet kept = 0;\n\tlet read = 0;\n\tlet skipped = false;\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\n\t\t\tread += value.byteLength;\n\t\t\tif (read > limitBytes) {\n\t\t\t\tawait reader.cancel();\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tchunks.push(value);\n\t\t\tkept += value.byteLength;\n\t\t\twhile (chunks.length > 1 && kept - chunks[0].byteLength >= keepBytes) {\n\t\t\t\tkept -= chunks[0].byteLength;\n\t\t\t\tchunks.shift();\n\t\t\t\tskipped = true;\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\tthrow toCancellationError(ex);\n\t} finally {\n\t\treader.releaseLock();\n\t}\n\n\tconst bytes = new Uint8Array(kept);\n\tlet offset = 0;\n\tfor (const chunk of chunks) {\n\t\tbytes.set(chunk, offset);\n\t\toffset += chunk.byteLength;\n\t}\n\n\tconst start = Math.max(0, bytes.byteLength - keepBytes);\n\treturn { bytes: bytes.subarray(start), skipped: skipped || start > 0 };\n}\n\nfunction parseContentRangeTotal(header: string | null): number | undefined {\n\tconst match = header != null ? /^bytes \\d+-\\d+\\/(\\d+)$/i.exec(header.trim()) : null;\n\tif (match == null) return undefined;\n\n\tconst total = Number(match[1]);\n\treturn Number.isSafeInteger(total) ? total : undefined;\n}\n\nfunction toJobLogText(bytes: Uint8Array, skipped: boolean, tailLines: number): PullRequestCheckLogText {\n\treturn tailLogText(new TextDecoder('utf-8').decode(bytes), {\n\t\tpartialFirstLine: skipped,\n\t\ttailLines: tailLines,\n\t\tsource: 'actions-job-log',\n\t});\n}\n\nfunction tailLogText(\n\ttext: string,\n\toptions: { partialFirstLine: boolean; tailLines: number; source: PullRequestCheckLogText['source'] },\n): PullRequestCheckLogText {\n\tlet normalized = text.replace(/\\r\\n/g, '\\n');\n\tif (options.partialFirstLine) {\n\t\tconst newline = normalized.indexOf('\\n');\n\t\tnormalized = newline === -1 ? '' : normalized.slice(newline + 1);\n\t}\n\n\tconst lines = normalized.length !== 0 ? normalized.split('\\n') : [];\n\tif (lines.at(-1) === '') {\n\t\tlines.pop();\n\t}\n\n\tconst kept = lines.length > options.tailLines ? lines.slice(-options.tailLines) : lines;\n\treturn {\n\t\ttext: kept.join('\\n'),\n\t\tlineCount: kept.length,\n\t\ttruncated: options.partialFirstLine || lines.length > kept.length,\n\t\tsource: options.source,\n\t};\n}\n\nasync function readBody(rsp: Response): Promise<ArrayBuffer> {\n\ttry {\n\t\treturn await rsp.arrayBuffer();\n\t} catch (ex) {\n\t\tthrow toCancellationError(ex);\n\t}\n}\n\nasync function discardBody(rsp: Response): Promise<void> {\n\tawait readBody(rsp);\n}\n\nfunction isNotFoundStatus(ex: unknown, ...statuses: number[]): boolean {\n\treturn RequestNotFoundError.is(ex) && ex.original instanceof RequestError && statuses.includes(ex.original.status);\n}\n"],"mappings":";;;;;;;AA+BA,MAAM,uBAAuB;AAC7B,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAE9B,eAAsB,uBACrB,QACA,SACA,WACA,OACA,cACuD;CACvD,MAAM,QAAQ,IA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,MAAM,SAAS,QAAQ,YAAY,MAAM,MAAM,CAAC,QAAQ,SAAS,IAAI;CAClF,OAAO;EACN,MAAM,KAAK,KAAK,IAAI;EACpB,WAAW,KAAK;EAChB,WAAW,QAAQ,oBAAoB,MAAM,SAAS,KAAK;EAC3D,QAAQ,QAAQ;CACjB;AACD;AAEA,eAAe,SAAS,KAAqC;CAC5D,IAAI;EACH,OAAO,MAAM,IAAI,YAAY;CAC9B,SAAS,IAAI;EACZ,MAAM,oBAAoB,EAAE;CAC7B;AACD;AAEA,eAAe,YAAY,KAA8B;CACxD,MAAM,SAAS,GAAG;AACnB;AAEA,SAAS,iBAAiB,IAAa,GAAG,UAA6B;CACtE,OAAO,qBAAqB,GAAG,EAAE,KAAK,GAAG,oBAAoB,gBAAgB,SAAS,SAAS,GAAG,SAAS,MAAM;AAClH"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ScopedLogger } from "../../../utils/logger.scoped.js";
|
|
2
|
+
import { AliasedGraphql, GraphqlAliasError } from "./aliasedQuery.js";
|
|
3
|
+
import { GitHubCheckContextEtagNode, GitHubCheckContexts, GitHubCheckContextsRead } from "../models.js";
|
|
4
|
+
//#region ../plus/git-github/src/api/checkRuns.d.ts
|
|
5
|
+
export type CheckContextsFragment = {
|
|
6
|
+
readonly kind: 'row';
|
|
7
|
+
readonly readsRequired: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'etag';
|
|
10
|
+
};
|
|
11
|
+
export declare const etagCheckContextsFragment: CheckContextsFragment;
|
|
12
|
+
export declare function gqlPullRequestCheckRunsFragment(fragment: CheckContextsFragment, index: number): string;
|
|
13
|
+
export declare function isCheckContextsError(error: GraphqlAliasError): boolean;
|
|
14
|
+
interface CheckContextsTarget<N extends GitHubCheckContextEtagNode> {
|
|
15
|
+
readonly number: number;
|
|
16
|
+
readonly commit: {
|
|
17
|
+
readonly id?: string;
|
|
18
|
+
readonly statusCheckRollup: {
|
|
19
|
+
readonly contexts?: GitHubCheckContexts<N>;
|
|
20
|
+
} | null;
|
|
21
|
+
} | undefined;
|
|
22
|
+
readonly errorPath: readonly (string | number)[];
|
|
23
|
+
}
|
|
24
|
+
export declare function readCheckContexts<N extends GitHubCheckContextEtagNode>(graphql: AliasedGraphql, fragment: CheckContextsFragment, targets: readonly (CheckContextsTarget<N> | undefined)[], errors: readonly GraphqlAliasError[], scope: ScopedLogger | undefined): Promise<(GitHubCheckContextsRead<N> | undefined)[]>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=checkRuns.d.ts.map
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { chunk } from "../../../utils/array.js";
|
|
2
|
+
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
3
|
+
import "./aliasedQuery.js";
|
|
4
|
+
//#region ../plus/git-github/src/api/checkRuns.ts
|
|
5
|
+
const etagCheckContextsFragment = { kind: "etag" };
|
|
6
|
+
const checkContextsPageSize = 100;
|
|
7
|
+
const checkContextsLimit = 500;
|
|
8
|
+
function readsRequired(fragment) {
|
|
9
|
+
return fragment.kind === "row" && fragment.readsRequired;
|
|
10
|
+
}
|
|
11
|
+
function gqlCheckContextNodes(fragment, index) {
|
|
12
|
+
if (fragment.kind === "etag") return `
|
|
13
|
+
__typename
|
|
14
|
+
... on CheckRun {
|
|
15
|
+
id
|
|
16
|
+
databaseId
|
|
17
|
+
name
|
|
18
|
+
status
|
|
19
|
+
conclusion
|
|
20
|
+
checkSuite {
|
|
21
|
+
app {
|
|
22
|
+
slug
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
... on StatusContext {
|
|
27
|
+
id
|
|
28
|
+
context
|
|
29
|
+
state
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const isRequired = fragment.readsRequired ? `isRequired(pullRequestNumber: $k${index})` : "";
|
|
33
|
+
return `
|
|
34
|
+
__typename
|
|
35
|
+
... on CheckRun {
|
|
36
|
+
id
|
|
37
|
+
databaseId
|
|
38
|
+
name
|
|
39
|
+
status
|
|
40
|
+
conclusion
|
|
41
|
+
detailsUrl
|
|
42
|
+
url
|
|
43
|
+
title
|
|
44
|
+
startedAt
|
|
45
|
+
completedAt
|
|
46
|
+
${isRequired}
|
|
47
|
+
checkSuite {
|
|
48
|
+
app {
|
|
49
|
+
slug
|
|
50
|
+
}
|
|
51
|
+
workflowRun {
|
|
52
|
+
workflow {
|
|
53
|
+
name
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
... on StatusContext {
|
|
59
|
+
id
|
|
60
|
+
context
|
|
61
|
+
state
|
|
62
|
+
targetUrl
|
|
63
|
+
createdAt
|
|
64
|
+
${isRequired}
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
function gqlCheckContexts(fragment, index, after) {
|
|
69
|
+
return `
|
|
70
|
+
statusCheckRollup {
|
|
71
|
+
contexts(${after != null ? `first: ${checkContextsPageSize}, after: ${after}` : `first: ${checkContextsPageSize}`}) {
|
|
72
|
+
pageInfo {
|
|
73
|
+
hasNextPage
|
|
74
|
+
endCursor
|
|
75
|
+
}
|
|
76
|
+
nodes {
|
|
77
|
+
${gqlCheckContextNodes(fragment, index)}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
function gqlPullRequestCheckRunsFragment(fragment, index) {
|
|
84
|
+
return `
|
|
85
|
+
commits(last: 1) {
|
|
86
|
+
nodes {
|
|
87
|
+
commit {
|
|
88
|
+
id
|
|
89
|
+
${gqlCheckContexts(fragment, index, void 0)}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
function isCheckContextsError(error) {
|
|
96
|
+
const path = error.path;
|
|
97
|
+
const at = path?.indexOf("statusCheckRollup") ?? -1;
|
|
98
|
+
return at !== -1 && path?.[at + 1] === "contexts" && path[at + 2] === "nodes";
|
|
99
|
+
}
|
|
100
|
+
function losesCheckContexts(errors, prefix, contexts) {
|
|
101
|
+
return errors.some((e) => {
|
|
102
|
+
const path = e.path;
|
|
103
|
+
if (path == null || !isCheckContextsError(e) || !prefix.every((key, i) => path[i] === key)) return false;
|
|
104
|
+
const tail = path.slice(path.indexOf("statusCheckRollup") + 2);
|
|
105
|
+
const index = tail[1];
|
|
106
|
+
return typeof index !== "number" || tail.length === 2 || contexts?.nodes?.[index] == null;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function gqlCommitCheckContextsPageQuery(fragment, count) {
|
|
110
|
+
const params = [];
|
|
111
|
+
const fields = [];
|
|
112
|
+
for (let j = 0; j < count; j++) {
|
|
113
|
+
params.push(`$c${j}: ID!`, `$a${j}: String!`);
|
|
114
|
+
if (readsRequired(fragment)) params.push(`$k${j}: Int!`);
|
|
115
|
+
fields.push(`c${j}: node(id: $c${j}) {
|
|
116
|
+
... on Commit {
|
|
117
|
+
${gqlCheckContexts(fragment, j, `$a${j}`)}
|
|
118
|
+
}
|
|
119
|
+
}`);
|
|
120
|
+
}
|
|
121
|
+
return `query getCommitCheckContextsPage(
|
|
122
|
+
${params.join("\n ")}
|
|
123
|
+
) {
|
|
124
|
+
${fields.join("\n ")}
|
|
125
|
+
}`;
|
|
126
|
+
}
|
|
127
|
+
async function readCheckContexts(graphql, fragment, targets, errors, scope) {
|
|
128
|
+
let pending = [];
|
|
129
|
+
const follow = (read, number, commitId, contexts) => {
|
|
130
|
+
if (!contexts?.pageInfo.hasNextPage) return;
|
|
131
|
+
if (commitId == null || contexts.pageInfo.endCursor == null) {
|
|
132
|
+
read.truncated = true;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
pending.push({
|
|
136
|
+
read,
|
|
137
|
+
number,
|
|
138
|
+
commitId,
|
|
139
|
+
after: contexts.pageInfo.endCursor
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
const reads = targets.map((target) => {
|
|
143
|
+
if (target == null) return void 0;
|
|
144
|
+
const contexts = target.commit?.statusCheckRollup?.contexts;
|
|
145
|
+
const read = {
|
|
146
|
+
contexts: [...contexts?.nodes ?? []],
|
|
147
|
+
truncated: losesCheckContexts(errors, target.errorPath, contexts)
|
|
148
|
+
};
|
|
149
|
+
follow(read, target.number, target.commit?.id, contexts);
|
|
150
|
+
return read;
|
|
151
|
+
});
|
|
152
|
+
for (let count = checkContextsPageSize; pending.length > 0; count += checkContextsPageSize) {
|
|
153
|
+
const current = pending;
|
|
154
|
+
pending = [];
|
|
155
|
+
if (count >= checkContextsLimit) {
|
|
156
|
+
for (const p of current) p.read.truncated = true;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
for (const page of chunk(current, 25)) {
|
|
160
|
+
const variables = {};
|
|
161
|
+
page.forEach((p, j) => {
|
|
162
|
+
variables[`c${j}`] = p.commitId;
|
|
163
|
+
variables[`a${j}`] = p.after;
|
|
164
|
+
if (readsRequired(fragment)) variables[`k${j}`] = p.number;
|
|
165
|
+
});
|
|
166
|
+
let rsp;
|
|
167
|
+
try {
|
|
168
|
+
rsp = await graphql(gqlCommitCheckContextsPageQuery(fragment, page.length), variables);
|
|
169
|
+
} catch (ex) {
|
|
170
|
+
if (isCancellationError(ex)) throw ex;
|
|
171
|
+
scope?.warn(`failed to read a page of check runs; ex=${ex}`);
|
|
172
|
+
}
|
|
173
|
+
page.forEach((p, j) => {
|
|
174
|
+
const alias = `c${j}`;
|
|
175
|
+
const contexts = rsp?.data[alias]?.statusCheckRollup?.contexts;
|
|
176
|
+
if (rsp == null || contexts == null || rsp.errors.some((e) => e.path?.[0] === alias && !isCheckContextsError(e))) {
|
|
177
|
+
p.read.truncated = true;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
p.read.contexts.push(...contexts.nodes ?? []);
|
|
181
|
+
if (losesCheckContexts(rsp.errors, [alias], contexts)) p.read.truncated = true;
|
|
182
|
+
follow(p.read, p.number, p.commitId, contexts);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return reads;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
export { etagCheckContextsFragment, gqlPullRequestCheckRunsFragment, isCheckContextsError, readCheckContexts };
|
|
190
|
+
|
|
191
|
+
//# sourceMappingURL=checkRuns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkRuns.js","names":[],"sources":["../../../../../plus/git-github/src/api/checkRuns.ts"],"sourcesContent":["import { chunk } from '@gitlens/utils/array.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { ScopedLogger } from '@gitlens/utils/logger.scoped.js';\nimport type { GitHubCheckContextEtagNode, GitHubCheckContexts, GitHubCheckContextsRead } from '../models.js';\nimport type { AliasedGraphql, GraphqlAliasError } from './aliasedQuery.js';\nimport { aliasedQueryChunkSize } from './aliasedQuery.js';\n\nexport type CheckContextsFragment =\n\t| { readonly kind: 'row'; readonly readsRequired: boolean }\n\t| { readonly kind: 'etag' };\n\nexport const etagCheckContextsFragment: CheckContextsFragment = { kind: 'etag' };\n\nconst checkContextsPageSize = 100;\nconst checkContextsLimit = 500;\n\nfunction readsRequired(fragment: CheckContextsFragment): boolean {\n\treturn fragment.kind === 'row' && fragment.readsRequired;\n}\n\nfunction gqlCheckContextNodes(fragment: CheckContextsFragment, index: number): string {\n\tif (fragment.kind === 'etag') {\n\t\treturn `\n__typename\n... on CheckRun {\n\tid\n\tdatabaseId\n\tname\n\tstatus\n\tconclusion\n\tcheckSuite {\n\t\tapp {\n\t\t\tslug\n\t\t}\n\t}\n}\n... on StatusContext {\n\tid\n\tcontext\n\tstate\n}\n`;\n\t}\n\n\t// KEEP: reads `$k{index}`, so a query selecting `readsRequired` must declare it for this alias.\n\tconst isRequired = fragment.readsRequired ? `isRequired(pullRequestNumber: $k${index})` : '';\n\treturn `\n__typename\n... on CheckRun {\n\tid\n\tdatabaseId\n\tname\n\tstatus\n\tconclusion\n\tdetailsUrl\n\turl\n\ttitle\n\tstartedAt\n\tcompletedAt\n\t${isRequired}\n\tcheckSuite {\n\t\tapp {\n\t\t\tslug\n\t\t}\n\t\tworkflowRun {\n\t\t\tworkflow {\n\t\t\t\tname\n\t\t\t}\n\t\t}\n\t}\n}\n... on StatusContext {\n\tid\n\tcontext\n\tstate\n\ttargetUrl\n\tcreatedAt\n\t${isRequired}\n}\n`;\n}\n\nfunction gqlCheckContexts(fragment: CheckContextsFragment, index: number, after: string | undefined): string {\n\tconst args = after != null ? `first: ${checkContextsPageSize}, after: ${after}` : `first: ${checkContextsPageSize}`;\n\treturn `\nstatusCheckRollup {\n\tcontexts(${args}) {\n\t\tpageInfo {\n\t\t\thasNextPage\n\t\t\tendCursor\n\t\t}\n\t\tnodes {\n\t\t\t${gqlCheckContextNodes(fragment, index)}\n\t\t}\n\t}\n}\n`;\n}\n\nexport function gqlPullRequestCheckRunsFragment(fragment: CheckContextsFragment, index: number): string {\n\t// KEEP: the same arguments as the full fragment's `commits(last: 1)`, so GraphQL merges the two selections.\n\treturn `\ncommits(last: 1) {\n\tnodes {\n\t\tcommit {\n\t\t\tid\n\t\t\t${gqlCheckContexts(fragment, index, undefined)}\n\t\t}\n\t}\n}\n`;\n}\n\nexport function isCheckContextsError(error: GraphqlAliasError): boolean {\n\tconst path: readonly unknown[] | undefined = error.path;\n\tconst at = path?.indexOf('statusCheckRollup') ?? -1;\n\t// KEEP: only under `nodes`; `contexts` and its `pageInfo` are non-null, so an error there nulls the whole rollup.\n\treturn at !== -1 && path?.[at + 1] === 'contexts' && path[at + 2] === 'nodes';\n}\n\nfunction losesCheckContexts(\n\terrors: readonly GraphqlAliasError[],\n\tprefix: readonly (string | number)[],\n\tcontexts: GitHubCheckContexts<GitHubCheckContextEtagNode> | undefined,\n): boolean {\n\treturn errors.some(e => {\n\t\tconst path: readonly unknown[] | undefined = e.path;\n\t\tif (path == null || !isCheckContextsError(e) || !prefix.every((key, i) => path[i] === key)) return false;\n\n\t\tconst tail = path.slice(path.indexOf('statusCheckRollup') + 2);\n\t\tconst index = tail[1];\n\t\treturn typeof index !== 'number' || tail.length === 2 || contexts?.nodes?.[index] == null;\n\t});\n}\n\ninterface CheckContextsTarget<N extends GitHubCheckContextEtagNode> {\n\treadonly number: number;\n\treadonly commit:\n\t\t| { readonly id?: string; readonly statusCheckRollup: { readonly contexts?: GitHubCheckContexts<N> } | null }\n\t\t| undefined;\n\treadonly errorPath: readonly (string | number)[];\n}\n\ntype CommitCheckContextsPage<N extends GitHubCheckContextEtagNode> = Record<\n\tstring,\n\t{ statusCheckRollup?: { contexts?: GitHubCheckContexts<N> } | null } | null | undefined\n>;\n\nfunction gqlCommitCheckContextsPageQuery(fragment: CheckContextsFragment, count: number): string {\n\tconst params: string[] = [];\n\tconst fields: string[] = [];\n\tfor (let j = 0; j < count; j++) {\n\t\tparams.push(`$c${j}: ID!`, `$a${j}: String!`);\n\t\tif (readsRequired(fragment)) {\n\t\t\tparams.push(`$k${j}: Int!`);\n\t\t}\n\t\tfields.push(`c${j}: node(id: $c${j}) {\n\t... on Commit {\n\t\t${gqlCheckContexts(fragment, j, `$a${j}`)}\n\t}\n}`);\n\t}\n\n\treturn `query getCommitCheckContextsPage(\n\t${params.join('\\n\\t')}\n) {\n\t${fields.join('\\n\\t')}\n}`;\n}\n\nexport async function readCheckContexts<N extends GitHubCheckContextEtagNode>(\n\tgraphql: AliasedGraphql,\n\tfragment: CheckContextsFragment,\n\ttargets: readonly (CheckContextsTarget<N> | undefined)[],\n\terrors: readonly GraphqlAliasError[],\n\tscope: ScopedLogger | undefined,\n): Promise<(GitHubCheckContextsRead<N> | undefined)[]> {\n\ttype Read = { contexts: (N | null)[]; truncated: boolean };\n\ttype Pending = { read: Read; number: number; commitId: string; after: string };\n\n\tlet pending: Pending[] = [];\n\tconst follow = (\n\t\tread: Read,\n\t\tnumber: number,\n\t\tcommitId: string | undefined,\n\t\tcontexts: GitHubCheckContexts<N> | undefined,\n\t): void => {\n\t\tif (!contexts?.pageInfo.hasNextPage) return;\n\n\t\tif (commitId == null || contexts.pageInfo.endCursor == null) {\n\t\t\tread.truncated = true;\n\t\t\treturn;\n\t\t}\n\n\t\tpending.push({ read: read, number: number, commitId: commitId, after: contexts.pageInfo.endCursor });\n\t};\n\n\tconst reads = targets.map((target): Read | undefined => {\n\t\tif (target == null) return undefined;\n\n\t\tconst contexts = target.commit?.statusCheckRollup?.contexts;\n\t\tconst read: Read = {\n\t\t\tcontexts: [...(contexts?.nodes ?? [])],\n\t\t\ttruncated: losesCheckContexts(errors, target.errorPath, contexts),\n\t\t};\n\t\tfollow(read, target.number, target.commit?.id, contexts);\n\t\treturn read;\n\t});\n\n\tfor (let count = checkContextsPageSize; pending.length > 0; count += checkContextsPageSize) {\n\t\tconst current = pending;\n\t\tpending = [];\n\t\tif (count >= checkContextsLimit) {\n\t\t\tfor (const p of current) {\n\t\t\t\tp.read.truncated = true;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tfor (const page of chunk(current, aliasedQueryChunkSize)) {\n\t\t\tconst variables: Record<string, unknown> = {};\n\t\t\tpage.forEach((p, j) => {\n\t\t\t\tvariables[`c${j}`] = p.commitId;\n\t\t\t\tvariables[`a${j}`] = p.after;\n\t\t\t\tif (readsRequired(fragment)) {\n\t\t\t\t\tvariables[`k${j}`] = p.number;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tlet rsp:\n\t\t\t\t| { readonly data: CommitCheckContextsPage<N>; readonly errors: readonly GraphqlAliasError[] }\n\t\t\t\t| undefined;\n\t\t\ttry {\n\t\t\t\trsp = await graphql<CommitCheckContextsPage<N>>(\n\t\t\t\t\tgqlCommitCheckContextsPageQuery(fragment, page.length),\n\t\t\t\t\tvariables,\n\t\t\t\t);\n\t\t\t} catch (ex) {\n\t\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t\tscope?.warn(`failed to read a page of check runs; ex=${ex}`);\n\t\t\t}\n\n\t\t\tpage.forEach((p, j) => {\n\t\t\t\tconst alias = `c${j}`;\n\t\t\t\tconst contexts = rsp?.data[alias]?.statusCheckRollup?.contexts;\n\t\t\t\tif (\n\t\t\t\t\trsp == null ||\n\t\t\t\t\tcontexts == null ||\n\t\t\t\t\trsp.errors.some(e => e.path?.[0] === alias && !isCheckContextsError(e))\n\t\t\t\t) {\n\t\t\t\t\tp.read.truncated = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tp.read.contexts.push(...(contexts.nodes ?? []));\n\t\t\t\tif (losesCheckContexts(rsp.errors, [alias], contexts)) {\n\t\t\t\t\tp.read.truncated = true;\n\t\t\t\t}\n\t\t\t\tfollow(p.read, p.number, p.commitId, contexts);\n\t\t\t});\n\t\t}\n\t}\n\n\treturn reads;\n}\n"],"mappings":";;;;AAWA,MAAa,4BAAmD,EAAE,MAAM,OAAO;AAE/E,MAAM,wBAAwB;AAC9B,MAAM,qBAAqB;AAE3B,SAAS,cAAc,UAA0C;CAChE,OAAO,SAAS,SAAS,SAAS,SAAS;AAC5C;AAEA,SAAS,qBAAqB,UAAiC,OAAuB;CACrF,IAAI,SAAS,SAAS,QACrB,OAAO;;;;;;;;;;;;;;;;;;;;CAuBR,MAAM,aAAa,SAAS,gBAAgB,mCAAmC,MAAM,KAAK;CAC1F,OAAO;;;;;;;;;;;;;GAaL,WAAW;;;;;;;;;;;;;;;;;;GAkBX,WAAW;;;AAGd;AAEA,SAAS,iBAAiB,UAAiC,OAAe,OAAmC;CAE5G,OAAO;;YADM,SAAS,OAAO,UAAU,sBAAsB,WAAW,UAAU,UAAU,wBAG5E;;;;;;KAMZ,qBAAqB,UAAU,KAAK,EAAE;;;;;AAK3C;AAEA,SAAgB,gCAAgC,UAAiC,OAAuB;CAEvG,OAAO;;;;;KAKH,iBAAiB,UAAU,OAAO,KAAA,CAAS,EAAE;;;;;AAKlD;AAEA,SAAgB,qBAAqB,OAAmC;CACvE,MAAM,OAAuC,MAAM;CACnD,MAAM,KAAK,MA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