@gitkraken/core-gitlens 0.39.0 → 0.41.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 +29 -1
- package/dist/git/models/pullRequest.d.ts +55 -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 +25 -2
- package/dist/plus/git-github/api/github.js +169 -37
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +51 -0
- package/dist/plus/git-github/api/issueWrites.js +192 -0
- package/dist/plus/git-github/api/issueWrites.js.map +1 -0
- 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 +135 -3
- package/dist/plus/git-github/models.js.map +1 -1
- package/dist/plus/integrations/authentication/rejectedTokenTracker.d.ts +7 -8
- package/dist/plus/integrations/authentication/rejectedTokenTracker.js +7 -8
- package/dist/plus/integrations/authentication/rejectedTokenTracker.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 +6 -2
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +31 -1
- package/dist/plus/integrations/integrationService.js +45 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +86 -0
- 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 +26 -5
- package/dist/plus/integrations/models/integration.js +35 -10
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/providers/asana.d.ts +4 -5
- package/dist/plus/integrations/providers/asana.js +53 -12
- package/dist/plus/integrations/providers/asana.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +18 -3
- package/dist/plus/integrations/providers/github.js +90 -5
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/linear.js +6 -6
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/models.d.ts +6 -15
- package/dist/plus/integrations/providers/models.js +1 -1
- package/dist/plus/integrations/providers/models.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +1 -6
- 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 +115 -5
- package/package.json +2 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RequestParameters } from "@octokit/types";
|
|
2
|
+
//#region ../plus/git-github/src/api/issueWrites.d.ts
|
|
3
|
+
type GitHubIssueWriteTarget = {
|
|
4
|
+
owner: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
};
|
|
7
|
+
export type GitHubIssueDelete = GitHubIssueWriteTarget & {
|
|
8
|
+
number: number;
|
|
9
|
+
expectedNodeId: string;
|
|
10
|
+
};
|
|
11
|
+
export type GitHubIssueWrite = (GitHubIssueWriteTarget & {
|
|
12
|
+
action: 'create';
|
|
13
|
+
title: string;
|
|
14
|
+
body?: string;
|
|
15
|
+
}) | (GitHubIssueDelete & ({
|
|
16
|
+
action: 'edit';
|
|
17
|
+
title?: string;
|
|
18
|
+
body?: string;
|
|
19
|
+
} | {
|
|
20
|
+
action: 'set-state';
|
|
21
|
+
state: 'open';
|
|
22
|
+
} | {
|
|
23
|
+
action: 'set-state';
|
|
24
|
+
state: 'closed';
|
|
25
|
+
reason: 'completed' | 'not_planned';
|
|
26
|
+
}));
|
|
27
|
+
export type IssueWriteResult = {
|
|
28
|
+
ok: true;
|
|
29
|
+
issue: {
|
|
30
|
+
owner: string;
|
|
31
|
+
repo: string;
|
|
32
|
+
number: number;
|
|
33
|
+
nodeId: string;
|
|
34
|
+
url: string;
|
|
35
|
+
title: string;
|
|
36
|
+
body: string;
|
|
37
|
+
state: 'open' | 'closed';
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'rate-limit' | 'unknown';
|
|
42
|
+
};
|
|
43
|
+
type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & {
|
|
44
|
+
action: 'delete';
|
|
45
|
+
});
|
|
46
|
+
type GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;
|
|
47
|
+
export declare function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean;
|
|
48
|
+
export declare function issueWriteFailure(ex: unknown): IssueWriteResult;
|
|
49
|
+
export declare function mutateGitHubIssue(input: GitHubIssueMutation, graphql: GraphqlRequest): Promise<IssueWriteResult>;
|
|
50
|
+
//#endregion
|
|
51
|
+
//# sourceMappingURL=issueWrites.d.ts.map
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { RequestRateLimitError } from "../../../git/errors.js";
|
|
2
|
+
import { GraphqlResponseError } from "@octokit/graphql";
|
|
3
|
+
import { RequestError } from "@octokit/request-error";
|
|
4
|
+
//#region ../plus/git-github/src/api/issueWrites.ts
|
|
5
|
+
const issueFields = `
|
|
6
|
+
id number url title body state
|
|
7
|
+
repository { id owner { login } name }
|
|
8
|
+
`;
|
|
9
|
+
function isValidGitHubIssueMutation(input) {
|
|
10
|
+
if (typeof input.owner !== "string" || !/^[a-z\d_-]+$/i.test(input.owner) || typeof input.repo !== "string" || !/^[a-z\d._-]+$/i.test(input.repo) || input.repo === "." || input.repo === "..") return false;
|
|
11
|
+
if (input.action !== "create" && (!Number.isInteger(input.number) || input.number < 1 || input.number > 2147483647 || typeof input.expectedNodeId !== "string" || !input.expectedNodeId.trim())) return false;
|
|
12
|
+
switch (input.action) {
|
|
13
|
+
case "create": return isIssueTitle(input.title) && (input.body === void 0 || typeof input.body === "string");
|
|
14
|
+
case "edit": return (input.title !== void 0 || input.body !== void 0) && (input.title === void 0 || isIssueTitle(input.title)) && (input.body === void 0 || typeof input.body === "string");
|
|
15
|
+
case "set-state": return input.state === "open" || input.state === "closed" && (input.reason === "completed" || input.reason === "not_planned");
|
|
16
|
+
case "delete": return true;
|
|
17
|
+
default: return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isIssueTitle(title) {
|
|
21
|
+
return typeof title === "string" && title.trim().length > 0;
|
|
22
|
+
}
|
|
23
|
+
function issueWriteFailure(ex) {
|
|
24
|
+
if (RequestRateLimitError.is(ex)) return {
|
|
25
|
+
ok: false,
|
|
26
|
+
reason: "rate-limit"
|
|
27
|
+
};
|
|
28
|
+
if (ex instanceof GraphqlResponseError) {
|
|
29
|
+
if (ex.errors?.some((error) => error.type === "RATE_LIMIT" || error.type === "RATE_LIMITED")) return {
|
|
30
|
+
ok: false,
|
|
31
|
+
reason: "rate-limit"
|
|
32
|
+
};
|
|
33
|
+
switch (ex.errors?.[0]?.type) {
|
|
34
|
+
case "NOT_FOUND": return {
|
|
35
|
+
ok: false,
|
|
36
|
+
reason: "not-found"
|
|
37
|
+
};
|
|
38
|
+
case "FORBIDDEN":
|
|
39
|
+
case "INSUFFICIENT_SCOPES": return {
|
|
40
|
+
ok: false,
|
|
41
|
+
reason: "forbidden"
|
|
42
|
+
};
|
|
43
|
+
case "BAD_USER_INPUT":
|
|
44
|
+
case "UNPROCESSABLE": return {
|
|
45
|
+
ok: false,
|
|
46
|
+
reason: "invalid-input"
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (ex instanceof RequestError) switch (ex.status) {
|
|
51
|
+
case 400:
|
|
52
|
+
case 422: return {
|
|
53
|
+
ok: false,
|
|
54
|
+
reason: "invalid-input"
|
|
55
|
+
};
|
|
56
|
+
case 401: return {
|
|
57
|
+
ok: false,
|
|
58
|
+
reason: "no-connection"
|
|
59
|
+
};
|
|
60
|
+
case 403: return {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: ex.message.toLowerCase().includes("rate limit") ? "rate-limit" : "forbidden"
|
|
63
|
+
};
|
|
64
|
+
case 404:
|
|
65
|
+
case 410: return {
|
|
66
|
+
ok: false,
|
|
67
|
+
reason: "not-found"
|
|
68
|
+
};
|
|
69
|
+
case 429: return {
|
|
70
|
+
ok: false,
|
|
71
|
+
reason: "rate-limit"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
reason: "unknown"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function mutateGitHubIssue(input, graphql) {
|
|
80
|
+
try {
|
|
81
|
+
const { owner, repo } = input;
|
|
82
|
+
const target = input.action === "create" ? await graphql(`
|
|
83
|
+
query IssueCreateTarget($owner: String!, $repo: String!) {
|
|
84
|
+
repository(owner: $owner, name: $repo, followRenames: false) {
|
|
85
|
+
id
|
|
86
|
+
hasIssuesEnabled
|
|
87
|
+
isArchived
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`, {
|
|
91
|
+
owner,
|
|
92
|
+
repo
|
|
93
|
+
}) : await graphql(`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!, $checkDelete: Boolean!) {
|
|
94
|
+
repository(owner: $owner, name: $repo, followRenames: false) {
|
|
95
|
+
id hasIssuesEnabled isArchived
|
|
96
|
+
}
|
|
97
|
+
node(id: $expectedNodeId) {
|
|
98
|
+
__typename
|
|
99
|
+
... on Issue {
|
|
100
|
+
${issueFields}
|
|
101
|
+
viewerCanDelete @include(if: $checkDelete)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}`, {
|
|
105
|
+
owner,
|
|
106
|
+
repo,
|
|
107
|
+
expectedNodeId: input.expectedNodeId,
|
|
108
|
+
checkDelete: input.action === "delete"
|
|
109
|
+
});
|
|
110
|
+
const repository = target?.repository;
|
|
111
|
+
if (repository == null) return {
|
|
112
|
+
ok: false,
|
|
113
|
+
reason: "not-found"
|
|
114
|
+
};
|
|
115
|
+
if (repository.isArchived) return {
|
|
116
|
+
ok: false,
|
|
117
|
+
reason: "forbidden"
|
|
118
|
+
};
|
|
119
|
+
if (!repository.hasIssuesEnabled) return {
|
|
120
|
+
ok: false,
|
|
121
|
+
reason: "unsupported"
|
|
122
|
+
};
|
|
123
|
+
if (input.action === "create") return await writeIssue(graphql, "createIssue", "CreateIssueInput", {
|
|
124
|
+
repositoryId: repository.id,
|
|
125
|
+
title: input.title,
|
|
126
|
+
body: input.body
|
|
127
|
+
});
|
|
128
|
+
const issue = target?.node;
|
|
129
|
+
if (issue?.__typename !== "Issue" || issue.number !== input.number || issue.repository.id !== repository.id || issue.repository.owner.login.toLowerCase() !== owner.toLowerCase() || issue.repository.name.toLowerCase() !== repo.toLowerCase()) return {
|
|
130
|
+
ok: false,
|
|
131
|
+
reason: "not-found"
|
|
132
|
+
};
|
|
133
|
+
switch (input.action) {
|
|
134
|
+
case "edit": return await writeIssue(graphql, "updateIssue", "UpdateIssueInput", {
|
|
135
|
+
id: issue.id,
|
|
136
|
+
title: input.title,
|
|
137
|
+
body: input.body
|
|
138
|
+
});
|
|
139
|
+
case "set-state": return input.state === "open" ? await writeIssue(graphql, "reopenIssue", "ReopenIssueInput", { issueId: issue.id }) : await writeIssue(graphql, "closeIssue", "CloseIssueInput", {
|
|
140
|
+
issueId: issue.id,
|
|
141
|
+
stateReason: input.reason === "completed" ? "COMPLETED" : "NOT_PLANNED"
|
|
142
|
+
});
|
|
143
|
+
case "delete":
|
|
144
|
+
if (issue.viewerCanDelete !== true) return {
|
|
145
|
+
ok: false,
|
|
146
|
+
reason: "forbidden"
|
|
147
|
+
};
|
|
148
|
+
return (await graphql(`
|
|
149
|
+
mutation DeleteIssue($issueId: ID!) {
|
|
150
|
+
deleteIssue(input: { issueId: $issueId }) {
|
|
151
|
+
repository {
|
|
152
|
+
id
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
`, { issueId: issue.id }))?.deleteIssue?.repository?.id === repository.id ? toIssueWriteResult(issue) : {
|
|
157
|
+
ok: false,
|
|
158
|
+
reason: "unknown"
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
} catch (ex) {
|
|
162
|
+
return issueWriteFailure(ex);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function writeIssue(graphql, mutation, inputType, input) {
|
|
166
|
+
const result = await graphql(`mutation WriteIssue($input: ${inputType}!) {
|
|
167
|
+
change: ${mutation}(input: $input) { issue { ${issueFields} } }
|
|
168
|
+
}`, { input });
|
|
169
|
+
return result?.change?.issue != null ? toIssueWriteResult(result.change.issue) : {
|
|
170
|
+
ok: false,
|
|
171
|
+
reason: "unknown"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function toIssueWriteResult(issue) {
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
issue: {
|
|
178
|
+
owner: issue.repository.owner.login,
|
|
179
|
+
repo: issue.repository.name,
|
|
180
|
+
number: issue.number,
|
|
181
|
+
nodeId: issue.id,
|
|
182
|
+
url: issue.url,
|
|
183
|
+
title: issue.title,
|
|
184
|
+
body: issue.body,
|
|
185
|
+
state: issue.state === "CLOSED" ? "closed" : "open"
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { isValidGitHubIssueMutation, issueWriteFailure, mutateGitHubIssue };
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=issueWrites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t };\n\ntype GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & { action: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isIssueTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): IssueWriteResult {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n): Promise<IssueWriteResult> {\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!, $checkDelete: Boolean!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\tviewerCanDelete @include(if: $checkDelete)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t\tcheckDelete: input.action === 'delete',\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\treturn await writeIssue(graphql, 'createIssue', 'CreateIssueInput', {\n\t\t\t\trepositoryId: repository.id,\n\t\t\t\ttitle: input.title,\n\t\t\t\tbody: input.body,\n\t\t\t});\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(graphql, 'updateIssue', 'UpdateIssueInput', {\n\t\t\t\t\tid: issue.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t});\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(graphql, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id })\n\t\t\t\t\t: await writeIssue(graphql, 'closeIssue', 'CloseIssueInput', {\n\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t});\n\t\t\tcase 'delete': {\n\t\t\t\tif (issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\t\t\tconst result = await graphql<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,\n\t\t\t\t\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\treturn result?.deleteIssue?.repository?.id === repository.id\n\t\t\t\t\t? toIssueWriteResult(issue)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\treturn issueWriteFailure(ex);\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\treturn result?.change?.issue != null ? toIssueWriteResult(result.change.issue) : { ok: false, reason: 'unknown' };\n}\n\nfunction toIssueWriteResult(issue: IssueNode): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScopedLogger } from "../../../utils/logger.scoped.js";
|
|
2
|
+
import { PullRequestActivityPage } from "../../../git/models/pullRequestActivity.js";
|
|
3
|
+
import { AliasedGraphql } from "./aliasedQuery.js";
|
|
4
|
+
//#region ../plus/git-github/src/api/pullRequestActivity.d.ts
|
|
5
|
+
export interface GitHubPullRequestActivityCursor {
|
|
6
|
+
readonly t: string;
|
|
7
|
+
readonly ids: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface GitHubPullRequestActivityTarget {
|
|
10
|
+
readonly owner: string;
|
|
11
|
+
readonly repo: string;
|
|
12
|
+
readonly number: number;
|
|
13
|
+
readonly cursor?: GitHubPullRequestActivityCursor;
|
|
14
|
+
}
|
|
15
|
+
export declare function readGitHubPullRequestActivity(graphql: AliasedGraphql, targets: readonly GitHubPullRequestActivityTarget[], limit: number, scope: ScopedLogger | undefined): Promise<PromiseSettledResult<PullRequestActivityPage | undefined>[]>;
|
|
16
|
+
export declare function encodePullRequestActivityCursor(cursor: GitHubPullRequestActivityCursor): string;
|
|
17
|
+
export declare function decodePullRequestActivityCursor(cursor: string): GitHubPullRequestActivityCursor | undefined;
|
|
18
|
+
//#endregion
|
|
19
|
+
//# sourceMappingURL=pullRequestActivity.d.ts.map
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
2
|
+
import { base64, fromBase64ToString } from "../../../utils/base64.js";
|
|
3
|
+
import { getAliasErrorVerdict } from "./aliasedQuery.js";
|
|
4
|
+
//#region ../plus/git-github/src/api/pullRequestActivity.ts
|
|
5
|
+
const maxPageSize = 100;
|
|
6
|
+
const maxFollowPages = 4;
|
|
7
|
+
const reviewCommentsPageSize = 20;
|
|
8
|
+
const activityItemTypes = "PULL_REQUEST_REVIEW, ISSUE_COMMENT";
|
|
9
|
+
const actorFields = "author { __typename login url }";
|
|
10
|
+
const timelineNodeFields = `pageInfo { hasNextPage endCursor }
|
|
11
|
+
nodes { __typename
|
|
12
|
+
... on IssueComment { id url body publishedAt createdAt viewerDidAuthor isMinimized ${actorFields} }
|
|
13
|
+
... on PullRequestReview { id url body state publishedAt submittedAt createdAt viewerDidAuthor isMinimized commit { oid }
|
|
14
|
+
${actorFields}
|
|
15
|
+
comments(first: ${reviewCommentsPageSize}) { totalCount nodes { ${`id url body path line startLine originalLine outdated publishedAt createdAt viewerDidAuthor isMinimized replyTo { id } commit { oid } ${actorFields}`} } } }
|
|
16
|
+
}`;
|
|
17
|
+
async function readGitHubPullRequestActivity(graphql, targets, limit, scope) {
|
|
18
|
+
let timelines;
|
|
19
|
+
try {
|
|
20
|
+
timelines = await readTimelines(graphql, targets, limit, scope);
|
|
21
|
+
} catch (ex) {
|
|
22
|
+
if (isCancellationError(ex)) throw ex;
|
|
23
|
+
scope?.warn(`failed to read pull request activity; ex=${ex}`);
|
|
24
|
+
return targets.map(() => ({
|
|
25
|
+
status: "rejected",
|
|
26
|
+
reason: ex
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
return targets.map((target, i) => {
|
|
30
|
+
const slot = timelines[i];
|
|
31
|
+
if (slot.status === "rejected") return slot;
|
|
32
|
+
if (slot.value == null) return {
|
|
33
|
+
status: "fulfilled",
|
|
34
|
+
value: void 0
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
return {
|
|
38
|
+
status: "fulfilled",
|
|
39
|
+
value: toActivityPage(slot.value, target.cursor, limit)
|
|
40
|
+
};
|
|
41
|
+
} catch (ex) {
|
|
42
|
+
scope?.warn(`failed to map pull request activity; ${describeTarget(target)}, ex=${ex}`);
|
|
43
|
+
return {
|
|
44
|
+
status: "rejected",
|
|
45
|
+
reason: ex
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function readTimelines(graphql, targets, limit, scope) {
|
|
51
|
+
const { data, errors } = await queryActivity(graphql, targets, limit);
|
|
52
|
+
const timelines = targets.map((target, i) => {
|
|
53
|
+
const alias = `p${i}`;
|
|
54
|
+
const node = data[alias]?.pullRequest;
|
|
55
|
+
const verdict = getAliasErrorVerdict(errors, alias, node);
|
|
56
|
+
if (verdict != null && verdict !== "absent") return verdict;
|
|
57
|
+
if (node == null) return {
|
|
58
|
+
status: "fulfilled",
|
|
59
|
+
value: void 0
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
return {
|
|
63
|
+
status: "fulfilled",
|
|
64
|
+
value: {
|
|
65
|
+
createdAt: node.createdAt,
|
|
66
|
+
entries: toTimelineEntries(node.timelineItems),
|
|
67
|
+
pageInfo: node.timelineItems.pageInfo
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
} catch (ex) {
|
|
71
|
+
scope?.warn(`failed to map pull request activity; ${describeTarget(target)}, ex=${ex}`);
|
|
72
|
+
return {
|
|
73
|
+
status: "rejected",
|
|
74
|
+
reason: ex
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const stale = targets.flatMap((target, i) => {
|
|
79
|
+
const slot = timelines[i];
|
|
80
|
+
const cursor = target.cursor;
|
|
81
|
+
return cursor != null && slot.status === "fulfilled" && slot.value != null ? [{
|
|
82
|
+
index: i,
|
|
83
|
+
target: {
|
|
84
|
+
...target,
|
|
85
|
+
cursor
|
|
86
|
+
},
|
|
87
|
+
timeline: slot.value
|
|
88
|
+
}] : [];
|
|
89
|
+
});
|
|
90
|
+
const followed = await readPastStalePages(graphql, stale, limit, scope);
|
|
91
|
+
stale.forEach((s, i) => {
|
|
92
|
+
timelines[s.index] = {
|
|
93
|
+
status: "fulfilled",
|
|
94
|
+
value: followed[i]
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return timelines;
|
|
98
|
+
}
|
|
99
|
+
async function queryActivity(graphql, targets, limit) {
|
|
100
|
+
const variables = {};
|
|
101
|
+
targets.forEach((target, i) => {
|
|
102
|
+
variables[`o${i}`] = target.owner;
|
|
103
|
+
variables[`n${i}`] = target.repo;
|
|
104
|
+
variables[`k${i}`] = target.number;
|
|
105
|
+
if (target.cursor != null) {
|
|
106
|
+
variables[`s${i}`] = activitySince(target.cursor);
|
|
107
|
+
if (target.after != null) variables[`a${i}`] = target.after;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const rsp = await graphql(activityQuery(targets, limit), variables);
|
|
111
|
+
if (rsp?.data == null) throw new Error("GitHub returned no data for the pull request activity");
|
|
112
|
+
return rsp;
|
|
113
|
+
}
|
|
114
|
+
async function readPastStalePages(graphql, stale, limit, scope) {
|
|
115
|
+
const timelines = stale.map((s) => s.timeline);
|
|
116
|
+
let due = stale.flatMap((s, index) => followFrom(index, s.timeline, s.target.cursor));
|
|
117
|
+
for (let round = 0; round < maxFollowPages && due.length !== 0; round++) {
|
|
118
|
+
let answer;
|
|
119
|
+
try {
|
|
120
|
+
answer = await queryActivity(graphql, due.map((d) => ({
|
|
121
|
+
...stale[d.index].target,
|
|
122
|
+
after: d.after
|
|
123
|
+
})), limit);
|
|
124
|
+
} catch (ex) {
|
|
125
|
+
if (isCancellationError(ex)) throw ex;
|
|
126
|
+
scope?.warn(`failed to read past pull request activity pages; ex=${ex}`);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const { data, errors } = answer;
|
|
130
|
+
due = due.flatMap(({ index }, i) => {
|
|
131
|
+
const alias = `p${i}`;
|
|
132
|
+
const next = data[alias]?.pullRequest?.timelineItems;
|
|
133
|
+
if (next == null || errors.some((e) => e.path?.[0] === alias)) {
|
|
134
|
+
scope?.warn(`failed to read past a pull request activity page; ${describeTarget(stale[index].target)}`);
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const timeline = {
|
|
138
|
+
createdAt: timelines[index].createdAt,
|
|
139
|
+
entries: [...timelines[index].entries, ...toTimelineEntries(next)],
|
|
140
|
+
pageInfo: next.pageInfo
|
|
141
|
+
};
|
|
142
|
+
timelines[index] = timeline;
|
|
143
|
+
return followFrom(index, timeline, stale[index].target.cursor);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return timelines;
|
|
147
|
+
}
|
|
148
|
+
function followFrom(index, timeline, cursor) {
|
|
149
|
+
const { hasNextPage, endCursor } = timeline.pageInfo;
|
|
150
|
+
if (!hasNextPage || endCursor == null) return [];
|
|
151
|
+
const since = toEpochSecond(cursor.t);
|
|
152
|
+
const seen = new Set(cursor.ids);
|
|
153
|
+
return timeline.entries.some((i) => i.second >= since && !seen.has(i.node.id)) ? [] : [{
|
|
154
|
+
index,
|
|
155
|
+
after: endCursor
|
|
156
|
+
}];
|
|
157
|
+
}
|
|
158
|
+
function activityQuery(targets, limit) {
|
|
159
|
+
const params = [];
|
|
160
|
+
const fields = [];
|
|
161
|
+
targets.forEach((target, i) => {
|
|
162
|
+
params.push(`$o${i}: String!`, `$n${i}: String!`, `$k${i}: Int!`);
|
|
163
|
+
if (target.cursor != null) params.push(`$s${i}: DateTime!`);
|
|
164
|
+
const after = target.cursor != null && target.after != null;
|
|
165
|
+
if (after) params.push(`$a${i}: String!`);
|
|
166
|
+
const timeline = target.cursor != null ? `timelineItems(first: ${activityPageSize(limit, target.cursor)}, since: $s${i}, ${after ? `after: $a${i}, ` : ""}itemTypes: [${activityItemTypes}])` : `timelineItems(last: ${limit}, itemTypes: [${activityItemTypes}])`;
|
|
167
|
+
fields.push(`p${i}: repository(owner: $o${i}, name: $n${i}) {
|
|
168
|
+
pullRequest(number: $k${i}) {
|
|
169
|
+
createdAt
|
|
170
|
+
${timeline} {
|
|
171
|
+
${timelineNodeFields}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}`);
|
|
175
|
+
});
|
|
176
|
+
return `query getPullRequestActivity(
|
|
177
|
+
${params.join("\n ")}
|
|
178
|
+
) {
|
|
179
|
+
${fields.join("\n ")}
|
|
180
|
+
}`;
|
|
181
|
+
}
|
|
182
|
+
function activityPageSize(limit, cursor) {
|
|
183
|
+
return Math.min(maxPageSize, limit + cursor.ids.length);
|
|
184
|
+
}
|
|
185
|
+
function activitySince(cursor) {
|
|
186
|
+
return (/* @__PURE__ */ new Date(toEpochSecond(cursor.t) * 1e3 - 1e3)).toISOString();
|
|
187
|
+
}
|
|
188
|
+
function describeTarget(target) {
|
|
189
|
+
return `${target.owner}/${target.repo}#${target.number}`;
|
|
190
|
+
}
|
|
191
|
+
function encodePullRequestActivityCursor(cursor) {
|
|
192
|
+
return base64(JSON.stringify({
|
|
193
|
+
v: 1,
|
|
194
|
+
t: cursor.t,
|
|
195
|
+
ids: cursor.ids
|
|
196
|
+
})).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
197
|
+
}
|
|
198
|
+
function decodePullRequestActivityCursor(cursor) {
|
|
199
|
+
if (!/^[A-Za-z0-9_-]+$/.test(cursor)) return void 0;
|
|
200
|
+
let parsed;
|
|
201
|
+
try {
|
|
202
|
+
const padded = cursor.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(cursor.length / 4) * 4, "=");
|
|
203
|
+
parsed = JSON.parse(fromBase64ToString(padded));
|
|
204
|
+
} catch {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (parsed == null || typeof parsed !== "object") return void 0;
|
|
208
|
+
const { v, t, ids } = parsed;
|
|
209
|
+
if (v !== 1 || typeof t !== "string" || Number.isNaN(Date.parse(t))) return void 0;
|
|
210
|
+
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string")) return void 0;
|
|
211
|
+
return {
|
|
212
|
+
t,
|
|
213
|
+
ids
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function toTimelineEntries(items) {
|
|
217
|
+
const entries = [];
|
|
218
|
+
for (const item of items.nodes ?? []) {
|
|
219
|
+
if (item?.id == null || !isActivityNode(item)) continue;
|
|
220
|
+
if (item.__typename === "PullRequestReview" && item.state === "PENDING") continue;
|
|
221
|
+
const publishedAt = new Date(activityTime(item));
|
|
222
|
+
entries.push({
|
|
223
|
+
node: item,
|
|
224
|
+
publishedAt,
|
|
225
|
+
second: toEpochSecond(publishedAt),
|
|
226
|
+
createdSecond: toEpochSecond(item.createdAt)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return entries;
|
|
230
|
+
}
|
|
231
|
+
function toActivityPage(timeline, cursor, limit) {
|
|
232
|
+
const returned = timeline.entries;
|
|
233
|
+
if (cursor == null) return {
|
|
234
|
+
items: returned.flatMap((i) => toActivityItems(i.node, i.publishedAt)),
|
|
235
|
+
cursor: encodePullRequestActivityCursor(baselineCursor(returned, timeline.createdAt)),
|
|
236
|
+
hasMore: false
|
|
237
|
+
};
|
|
238
|
+
const since = toEpochSecond(cursor.t);
|
|
239
|
+
const seen = new Set(cursor.ids);
|
|
240
|
+
const inWindow = returned.filter((i) => i.second >= since);
|
|
241
|
+
const fresh = inWindow.filter((i) => !seen.has(i.node.id));
|
|
242
|
+
const kept = fresh.slice(0, limit);
|
|
243
|
+
const lastKept = kept.at(-1);
|
|
244
|
+
const cut = fresh.length > kept.length || timeline.pageInfo.hasNextPage;
|
|
245
|
+
return {
|
|
246
|
+
items: kept.flatMap((i) => toActivityItems(i.node, i.publishedAt)),
|
|
247
|
+
cursor: encodePullRequestActivityCursor(lastKept != null ? resumeCursor(cursor, returned, inWindow, kept, lastKept, fresh.slice(limit), cut) : cursor),
|
|
248
|
+
hasMore: cut
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function activityTime(node) {
|
|
252
|
+
return node.__typename === "PullRequestReview" ? node.submittedAt ?? node.publishedAt ?? node.createdAt : node.publishedAt ?? node.createdAt;
|
|
253
|
+
}
|
|
254
|
+
function baselineCursor(timeline, createdAt) {
|
|
255
|
+
if (timeline.length === 0) return {
|
|
256
|
+
t: toIsoSecond(toEpochSecond(createdAt)),
|
|
257
|
+
ids: []
|
|
258
|
+
};
|
|
259
|
+
const t = Math.max(...timeline.map((i) => i.second));
|
|
260
|
+
return {
|
|
261
|
+
t: toIsoSecond(t),
|
|
262
|
+
ids: timeline.filter((i) => i.second === t).map((i) => i.node.id)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function resumeCursor(cursor, returned, inWindow, kept, lastKept, trimmed, cut) {
|
|
266
|
+
let t;
|
|
267
|
+
if (cut) t = Math.max(toEpochSecond(cursor.t), Math.min(lastKept.second, lastKept.createdSecond, ...trimmed.map((i) => i.second)));
|
|
268
|
+
else t = Math.max(...kept.map((i) => i.second));
|
|
269
|
+
const delivered = /* @__PURE__ */ new Set([...cursor.ids, ...kept.map((i) => i.node.id)]);
|
|
270
|
+
const ids = inWindow.filter((i) => i.second >= t && delivered.has(i.node.id)).map((i) => i.node.id);
|
|
271
|
+
if (cut) {
|
|
272
|
+
const present = new Set(returned.map((i) => i.node.id));
|
|
273
|
+
ids.push(...cursor.ids.filter((id) => !present.has(id)));
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
t: toIsoSecond(t),
|
|
277
|
+
ids: [...new Set(ids)]
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function isActivityNode(node) {
|
|
281
|
+
return node.__typename === "IssueComment" || node.__typename === "PullRequestReview";
|
|
282
|
+
}
|
|
283
|
+
function toActivityItems(node, publishedAt) {
|
|
284
|
+
const base = {
|
|
285
|
+
id: node.id,
|
|
286
|
+
url: node.url,
|
|
287
|
+
...authorOf(node.author),
|
|
288
|
+
publishedAt,
|
|
289
|
+
byViewer: node.viewerDidAuthor === true,
|
|
290
|
+
isMinimized: node.isMinimized === true
|
|
291
|
+
};
|
|
292
|
+
if (node.__typename === "IssueComment") return [{
|
|
293
|
+
kind: "comment",
|
|
294
|
+
...base,
|
|
295
|
+
body: node.body ?? ""
|
|
296
|
+
}];
|
|
297
|
+
const comments = (node.comments?.nodes ?? []).filter((c) => c != null);
|
|
298
|
+
const items = [{
|
|
299
|
+
kind: "review",
|
|
300
|
+
...base,
|
|
301
|
+
state: fromGitHubReviewState(node.state),
|
|
302
|
+
body: node.body ?? "",
|
|
303
|
+
...node.commit?.oid != null ? { commitSha: node.commit.oid } : {},
|
|
304
|
+
...(node.comments?.totalCount ?? 0) > comments.length ? { commentsTruncated: true } : {}
|
|
305
|
+
}];
|
|
306
|
+
const ordered = comments.map((c) => ({
|
|
307
|
+
comment: c,
|
|
308
|
+
createdAt: Date.parse(c.createdAt)
|
|
309
|
+
})).sort((a, b) => a.createdAt - b.createdAt);
|
|
310
|
+
for (const { comment } of ordered) items.push({
|
|
311
|
+
kind: "review-comment",
|
|
312
|
+
id: comment.id,
|
|
313
|
+
url: comment.url,
|
|
314
|
+
...authorOf(comment.author),
|
|
315
|
+
publishedAt,
|
|
316
|
+
byViewer: comment.viewerDidAuthor === true,
|
|
317
|
+
isMinimized: comment.isMinimized === true,
|
|
318
|
+
reviewId: node.id,
|
|
319
|
+
body: comment.body ?? "",
|
|
320
|
+
path: comment.path,
|
|
321
|
+
...comment.line != null ? { line: comment.line } : {},
|
|
322
|
+
...comment.startLine != null ? { startLine: comment.startLine } : {},
|
|
323
|
+
...comment.originalLine != null ? { originalLine: comment.originalLine } : {},
|
|
324
|
+
outdated: comment.outdated === true,
|
|
325
|
+
...comment.replyTo?.id != null ? { inReplyTo: comment.replyTo.id } : {},
|
|
326
|
+
...comment.commit?.oid != null ? { commitSha: comment.commit.oid } : {}
|
|
327
|
+
});
|
|
328
|
+
return items;
|
|
329
|
+
}
|
|
330
|
+
function authorOf(actor) {
|
|
331
|
+
if (actor?.login == null) return {};
|
|
332
|
+
return { author: {
|
|
333
|
+
login: actor.login,
|
|
334
|
+
...actor.url != null ? { url: actor.url } : {},
|
|
335
|
+
isBot: actor.__typename === "Bot"
|
|
336
|
+
} };
|
|
337
|
+
}
|
|
338
|
+
function fromGitHubReviewState(state) {
|
|
339
|
+
switch (state) {
|
|
340
|
+
case "APPROVED": return "approved";
|
|
341
|
+
case "CHANGES_REQUESTED": return "changes-requested";
|
|
342
|
+
case "DISMISSED": return "dismissed";
|
|
343
|
+
default: return "commented";
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function toIsoSecond(second) {
|
|
347
|
+
return (/* @__PURE__ */ new Date(second * 1e3)).toISOString();
|
|
348
|
+
}
|
|
349
|
+
function toEpochSecond(time) {
|
|
350
|
+
return Math.floor((typeof time === "string" ? Date.parse(time) : time.getTime()) / 1e3);
|
|
351
|
+
}
|
|
352
|
+
//#endregion
|
|
353
|
+
export { decodePullRequestActivityCursor, encodePullRequestActivityCursor, readGitHubPullRequestActivity };
|
|
354
|
+
|
|
355
|
+
//# sourceMappingURL=pullRequestActivity.js.map
|