@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.
Files changed (94) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/git/models/issue.d.ts +2 -0
  3. package/dist/git/models/issue.js.map +1 -1
  4. package/dist/git/models/issueOrPullRequest.d.ts +4 -0
  5. package/dist/git/models/pullRequest.d.ts +57 -1
  6. package/dist/git/models/pullRequest.js +5 -1
  7. package/dist/git/models/pullRequest.js.map +1 -1
  8. package/dist/git/models/pullRequestActivity.d.ts +55 -0
  9. package/dist/git/models/pullRequestActivity.js +0 -0
  10. package/dist/git/utils/pullRequest.utils.js +3 -1
  11. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  12. package/dist/git/watching/worktreeSummary.d.ts +1 -0
  13. package/dist/git/watching/worktreeSummary.js +34 -2
  14. package/dist/git/watching/worktreeSummary.js.map +1 -1
  15. package/dist/plus/git-github/api/aliasedQuery.d.ts +19 -0
  16. package/dist/plus/git-github/api/aliasedQuery.js +21 -0
  17. package/dist/plus/git-github/api/aliasedQuery.js.map +1 -0
  18. package/dist/plus/git-github/api/cancellation.d.ts +4 -0
  19. package/dist/plus/git-github/api/cancellation.js +9 -0
  20. package/dist/plus/git-github/api/cancellation.js.map +1 -0
  21. package/dist/plus/git-github/api/checkRunLogs.d.ts +31 -0
  22. package/dist/plus/git-github/api/checkRunLogs.js +252 -0
  23. package/dist/plus/git-github/api/checkRunLogs.js.map +1 -0
  24. package/dist/plus/git-github/api/checkRuns.d.ts +26 -0
  25. package/dist/plus/git-github/api/checkRuns.js +191 -0
  26. package/dist/plus/git-github/api/checkRuns.js.map +1 -0
  27. package/dist/plus/git-github/api/github.d.ts +23 -6
  28. package/dist/plus/git-github/api/github.js +174 -39
  29. package/dist/plus/git-github/api/github.js.map +1 -1
  30. package/dist/plus/git-github/api/issueWrites.d.ts +3 -2
  31. package/dist/plus/git-github/api/issueWrites.js +10 -5
  32. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  33. package/dist/plus/git-github/api/pullRequestActivity.d.ts +19 -0
  34. package/dist/plus/git-github/api/pullRequestActivity.js +355 -0
  35. package/dist/plus/git-github/api/pullRequestActivity.js.map +1 -0
  36. package/dist/plus/git-github/models.d.ts +100 -4
  37. package/dist/plus/git-github/models.js +142 -6
  38. package/dist/plus/git-github/models.js.map +1 -1
  39. package/dist/plus/integrations/fieldPresence.d.ts +10 -5
  40. package/dist/plus/integrations/fieldPresence.js +46 -25
  41. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  42. package/dist/plus/integrations/index.d.ts +5 -2
  43. package/dist/plus/integrations/index.js.map +1 -1
  44. package/dist/plus/integrations/integrationService.d.ts +26 -1
  45. package/dist/plus/integrations/integrationService.js +22 -0
  46. package/dist/plus/integrations/integrationService.js.map +1 -1
  47. package/dist/plus/integrations/manager.d.ts +86 -1
  48. package/dist/plus/integrations/models/gitHostIntegration.d.ts +31 -1
  49. package/dist/plus/integrations/models/gitHostIntegration.js +68 -0
  50. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  51. package/dist/plus/integrations/models/integration.d.ts +21 -2
  52. package/dist/plus/integrations/models/integration.js +20 -1
  53. package/dist/plus/integrations/models/integration.js.map +1 -1
  54. package/dist/plus/integrations/providers/azure/azure.js +20 -14
  55. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  56. package/dist/plus/integrations/providers/azure/models.js +7 -3
  57. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  58. package/dist/plus/integrations/providers/bitbucket/bitbucket.js +18 -13
  59. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  60. package/dist/plus/integrations/providers/bitbucket/models.js +5 -2
  61. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  62. package/dist/plus/integrations/providers/bitbucket-server/models.js +3 -1
  63. package/dist/plus/integrations/providers/bitbucket-server/models.js.map +1 -1
  64. package/dist/plus/integrations/providers/github.d.ts +15 -6
  65. package/dist/plus/integrations/providers/github.js +65 -5
  66. package/dist/plus/integrations/providers/github.js.map +1 -1
  67. package/dist/plus/integrations/providers/gitlab/gitlab.js +12 -6
  68. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  69. package/dist/plus/integrations/providers/gitlab/models.js +5 -2
  70. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  71. package/dist/plus/integrations/providers/jiraIssueByKey.js +3 -1
  72. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  73. package/dist/plus/integrations/providers/models.js +9 -4
  74. package/dist/plus/integrations/providers/models.js.map +1 -1
  75. package/dist/plus/integrations/providers/providerApiClient.js +10 -7
  76. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  77. package/dist/plus/integrations/providers/providersApi.js +3 -1
  78. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  79. package/dist/plus/integrations/reads/etag.js +20 -5
  80. package/dist/plus/integrations/reads/etag.js.map +1 -1
  81. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +36 -0
  82. package/dist/plus/integrations/reads/pullRequestActivity.js +103 -0
  83. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -0
  84. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +4 -1
  85. package/dist/plus/integrations/reads/pullRequestBatch.js +5 -2
  86. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  87. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +2 -0
  88. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  89. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  90. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +27 -0
  91. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +92 -0
  92. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -0
  93. package/docs/integrations.md +111 -14
  94. package/package.json +2 -2
@@ -36,12 +36,13 @@ export type IssueWriteResult = {
36
36
  body: string;
37
37
  state: 'open' | 'closed';
38
38
  };
39
+ deletedFromDifferentRepository?: true;
39
40
  } | {
40
41
  ok: false;
41
42
  reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'rate-limit' | 'unknown';
42
43
  };
43
- type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & {
44
- action: 'delete';
44
+ export type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & {
45
+ action: 'delete' | 'resolve';
45
46
  });
46
47
  type GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;
47
48
  export declare function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean;
@@ -13,7 +13,8 @@ function isValidGitHubIssueMutation(input) {
13
13
  case "create": return isIssueTitle(input.title) && (input.body === void 0 || typeof input.body === "string");
14
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
15
  case "set-state": return input.state === "open" || input.state === "closed" && (input.reason === "completed" || input.reason === "not_planned");
16
- case "delete": return true;
16
+ case "delete":
17
+ case "resolve": return true;
17
18
  default: return false;
18
19
  }
19
20
  }
@@ -131,6 +132,7 @@ async function mutateGitHubIssue(input, graphql) {
131
132
  reason: "not-found"
132
133
  };
133
134
  switch (input.action) {
135
+ case "resolve": return toIssueWriteResult(issue);
134
136
  case "edit": return await writeIssue(graphql, "updateIssue", "UpdateIssueInput", {
135
137
  id: issue.id,
136
138
  title: input.title,
@@ -140,12 +142,12 @@ async function mutateGitHubIssue(input, graphql) {
140
142
  issueId: issue.id,
141
143
  stateReason: input.reason === "completed" ? "COMPLETED" : "NOT_PLANNED"
142
144
  });
143
- case "delete":
145
+ case "delete": {
144
146
  if (issue.viewerCanDelete !== true) return {
145
147
  ok: false,
146
148
  reason: "forbidden"
147
149
  };
148
- return (await graphql(`
150
+ const deletedRepositoryId = (await graphql(`
149
151
  mutation DeleteIssue($issueId: ID!) {
150
152
  deleteIssue(input: { issueId: $issueId }) {
151
153
  repository {
@@ -153,10 +155,12 @@ async function mutateGitHubIssue(input, graphql) {
153
155
  }
154
156
  }
155
157
  }
156
- `, { issueId: issue.id }))?.deleteIssue?.repository?.id === repository.id ? toIssueWriteResult(issue) : {
158
+ `, { issueId: issue.id }))?.deleteIssue?.repository?.id;
159
+ return typeof deletedRepositoryId === "string" && deletedRepositoryId.length > 0 ? toIssueWriteResult(issue, deletedRepositoryId !== repository.id) : {
157
160
  ok: false,
158
161
  reason: "unknown"
159
162
  };
163
+ }
160
164
  }
161
165
  } catch (ex) {
162
166
  return issueWriteFailure(ex);
@@ -171,9 +175,10 @@ async function writeIssue(graphql, mutation, inputType, input) {
171
175
  reason: "unknown"
172
176
  };
173
177
  }
174
- function toIssueWriteResult(issue) {
178
+ function toIssueWriteResult(issue, deletedFromDifferentRepository = false) {
175
179
  return {
176
180
  ok: true,
181
+ ...deletedFromDifferentRepository && { deletedFromDifferentRepository: true },
177
182
  issue: {
178
183
  owner: issue.repository.owner.login,
179
184
  repo: issue.repository.name,
@@ -1 +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":";;;;AA+CA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA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MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
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\t\tdeletedFromDifferentRepository?: true;\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\nexport type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & { action: 'delete' | 'resolve' });\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\tcase 'resolve':\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 'resolve':\n\t\t\t\treturn toIssueWriteResult(issue);\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\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\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, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: 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":";;;;AAgDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,MAAM,IAAI,KACjC,MAAM,SAAS,OACf,MAAM,SAAS,MAEf,OAAO;CAGR,IACC,MAAM,WAAW,aAChB,CAAC,OAAO,UAAU,MAAM,MAAM,KAC9B,MAAM,SAAS,KACf,MAAM,SA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M;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pullRequestActivity.js","names":[],"sources":["../../../../../plus/git-github/src/api/pullRequestActivity.ts"],"sourcesContent":["import type {\n\tPullRequestActivityAuthor,\n\tPullRequestActivityItem,\n\tPullRequestActivityPage,\n} from '@gitlens/git/models/pullRequestActivity.js';\nimport { base64, fromBase64ToString } from '@gitlens/utils/base64.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { ScopedLogger } from '@gitlens/utils/logger.scoped.js';\nimport type { AliasedGraphql, GraphqlAliasError } from './aliasedQuery.js';\nimport { getAliasErrorVerdict } from './aliasedQuery.js';\n\nexport interface GitHubPullRequestActivityCursor {\n\treadonly t: string;\n\treadonly ids: readonly string[];\n}\n\nexport interface GitHubPullRequestActivityTarget {\n\treadonly owner: string;\n\treadonly repo: string;\n\treadonly number: number;\n\treadonly cursor?: GitHubPullRequestActivityCursor;\n}\n\ntype ActivityActorNode = { __typename?: string; login?: string | null; url?: string | null } | null;\n\ntype ActivityCommentFields = {\n\tid: string;\n\turl: string;\n\tbody?: string | null;\n\tpublishedAt?: string | null;\n\tcreatedAt: string;\n\tviewerDidAuthor?: boolean | null;\n\tisMinimized?: boolean | null;\n\tauthor?: ActivityActorNode;\n};\n\ntype ActivityReviewCommentNode = ActivityCommentFields & {\n\tpath: string;\n\tline?: number | null;\n\tstartLine?: number | null;\n\toriginalLine?: number | null;\n\toutdated?: boolean | null;\n\treplyTo?: { id: string } | null;\n\tcommit?: { oid: string } | null;\n};\n\ntype ActivityTimelineNode =\n\t| (ActivityCommentFields & { __typename: 'IssueComment' })\n\t| (ActivityCommentFields & {\n\t\t\t__typename: 'PullRequestReview';\n\t\t\tstate: string;\n\t\t\tsubmittedAt?: string | null;\n\t\t\tcommit?: { oid: string } | null;\n\t\t\tcomments?: { totalCount: number; nodes?: (ActivityReviewCommentNode | null)[] | null } | null;\n\t })\n\t| { __typename: string; id?: string };\n\ntype ActivityNode = Extract<ActivityTimelineNode, { __typename: 'IssueComment' | 'PullRequestReview' }>;\n\ntype ActivityTimelineItems = {\n\tpageInfo: ActivityPageInfo;\n\tnodes?: (ActivityTimelineNode | null)[] | null;\n};\n\ntype ActivityPageInfo = { hasNextPage: boolean; endCursor?: string | null };\n\ntype PullRequestActivityResponse = Record<\n\tstring,\n\t{ pullRequest?: { createdAt: string; timelineItems: ActivityTimelineItems } | null } | null | undefined\n>;\n\ntype ActivityQueryTarget = GitHubPullRequestActivityTarget & { readonly after?: string };\n\ntype TimelineEntry = { node: ActivityNode; publishedAt: Date; second: number; createdSecond: number };\n\ntype Timeline = { createdAt: string; entries: readonly TimelineEntry[]; pageInfo: ActivityPageInfo };\n\ntype StaleTimeline = {\n\tindex: number;\n\ttarget: GitHubPullRequestActivityTarget & { readonly cursor: GitHubPullRequestActivityCursor };\n\ttimeline: Timeline;\n};\n\nconst maxPageSize = 100;\nconst maxFollowPages = 4;\nconst reviewCommentsPageSize = 20;\n\nconst activityItemTypes = 'PULL_REQUEST_REVIEW, ISSUE_COMMENT';\nconst actorFields = 'author { __typename login url }';\nconst reviewCommentFields = `id url body path line startLine originalLine outdated publishedAt createdAt viewerDidAuthor isMinimized replyTo { id } commit { oid } ${actorFields}`;\nconst timelineNodeFields = `pageInfo { hasNextPage endCursor }\n\t\t\t\t\t\tnodes { __typename\n\t\t\t\t\t\t\t... on IssueComment { id url body publishedAt createdAt viewerDidAuthor isMinimized ${actorFields} }\n\t\t\t\t\t\t\t... on PullRequestReview { id url body state publishedAt submittedAt createdAt viewerDidAuthor isMinimized commit { oid }\n\t\t\t\t\t\t\t\t${actorFields}\n\t\t\t\t\t\t\t\tcomments(first: ${reviewCommentsPageSize}) { totalCount nodes { ${reviewCommentFields} } } }\n\t\t\t\t\t\t}`;\n\nexport async function readGitHubPullRequestActivity(\n\tgraphql: AliasedGraphql,\n\ttargets: readonly GitHubPullRequestActivityTarget[],\n\tlimit: number,\n\tscope: ScopedLogger | undefined,\n): Promise<PromiseSettledResult<PullRequestActivityPage | undefined>[]> {\n\tlet timelines: PromiseSettledResult<Timeline | undefined>[];\n\ttry {\n\t\ttimelines = await readTimelines(graphql, targets, limit, scope);\n\t} catch (ex) {\n\t\tif (isCancellationError(ex)) throw ex;\n\n\t\tscope?.warn(`failed to read pull request activity; ex=${ex}`);\n\t\treturn targets.map((): PromiseRejectedResult => ({ status: 'rejected', reason: ex }));\n\t}\n\n\treturn targets.map((target, i): PromiseSettledResult<PullRequestActivityPage | undefined> => {\n\t\tconst slot = timelines[i];\n\t\tif (slot.status === 'rejected') return slot;\n\t\tif (slot.value == null) return { status: 'fulfilled', value: undefined };\n\n\t\ttry {\n\t\t\treturn { status: 'fulfilled', value: toActivityPage(slot.value, target.cursor, limit) };\n\t\t} catch (ex) {\n\t\t\tscope?.warn(`failed to map pull request activity; ${describeTarget(target)}, ex=${ex}`);\n\t\t\treturn { status: 'rejected', reason: ex };\n\t\t}\n\t});\n}\n\nasync function readTimelines(\n\tgraphql: AliasedGraphql,\n\ttargets: readonly GitHubPullRequestActivityTarget[],\n\tlimit: number,\n\tscope: ScopedLogger | undefined,\n): Promise<PromiseSettledResult<Timeline | undefined>[]> {\n\tconst { data, errors } = await queryActivity(graphql, targets, limit);\n\tconst timelines = targets.map((target, i): PromiseSettledResult<Timeline | undefined> => {\n\t\tconst alias = `p${i}`;\n\t\tconst node = data[alias]?.pullRequest;\n\t\tconst verdict = getAliasErrorVerdict(errors, alias, node);\n\t\tif (verdict != null && verdict !== 'absent') return verdict;\n\t\tif (node == null) return { status: 'fulfilled', value: undefined };\n\n\t\ttry {\n\t\t\treturn {\n\t\t\t\tstatus: 'fulfilled',\n\t\t\t\tvalue: {\n\t\t\t\t\tcreatedAt: node.createdAt,\n\t\t\t\t\tentries: toTimelineEntries(node.timelineItems),\n\t\t\t\t\tpageInfo: node.timelineItems.pageInfo,\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\tscope?.warn(`failed to map pull request activity; ${describeTarget(target)}, ex=${ex}`);\n\t\t\treturn { status: 'rejected', reason: ex };\n\t\t}\n\t});\n\n\tconst stale = targets.flatMap((target, i): StaleTimeline[] => {\n\t\tconst slot = timelines[i];\n\t\tconst cursor = target.cursor;\n\t\treturn cursor != null && slot.status === 'fulfilled' && slot.value != null\n\t\t\t? [{ index: i, target: { ...target, cursor: cursor }, timeline: slot.value }]\n\t\t\t: [];\n\t});\n\tconst followed = await readPastStalePages(graphql, stale, limit, scope);\n\tstale.forEach((s, i) => {\n\t\ttimelines[s.index] = { status: 'fulfilled', value: followed[i] };\n\t});\n\treturn timelines;\n}\n\nasync function queryActivity(\n\tgraphql: AliasedGraphql,\n\ttargets: readonly ActivityQueryTarget[],\n\tlimit: number,\n): Promise<{ readonly data: PullRequestActivityResponse; readonly errors: readonly GraphqlAliasError[] }> {\n\tconst variables: Record<string, unknown> = {};\n\ttargets.forEach((target, i) => {\n\t\tvariables[`o${i}`] = target.owner;\n\t\tvariables[`n${i}`] = target.repo;\n\t\tvariables[`k${i}`] = target.number;\n\t\tif (target.cursor != null) {\n\t\t\tvariables[`s${i}`] = activitySince(target.cursor);\n\t\t\tif (target.after != null) {\n\t\t\t\tvariables[`a${i}`] = target.after;\n\t\t\t}\n\t\t}\n\t});\n\n\tconst rsp = await graphql<PullRequestActivityResponse>(activityQuery(targets, limit), variables);\n\tif (rsp?.data == null) throw new Error('GitHub returned no data for the pull request activity');\n\n\treturn rsp;\n}\n\nasync function readPastStalePages(\n\tgraphql: AliasedGraphql,\n\tstale: readonly StaleTimeline[],\n\tlimit: number,\n\tscope: ScopedLogger | undefined,\n): Promise<Timeline[]> {\n\tconst timelines = stale.map(s => s.timeline);\n\tlet due = stale.flatMap((s, index) => followFrom(index, s.timeline, s.target.cursor));\n\tfor (let round = 0; round < maxFollowPages && due.length !== 0; round++) {\n\t\tlet answer: { readonly data: PullRequestActivityResponse; readonly errors: readonly GraphqlAliasError[] };\n\t\ttry {\n\t\t\tanswer = await queryActivity(\n\t\t\t\tgraphql,\n\t\t\t\tdue.map(d => ({ ...stale[d.index].target, after: d.after })),\n\t\t\t\tlimit,\n\t\t\t);\n\t\t} catch (ex) {\n\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\tscope?.warn(`failed to read past pull request activity pages; ex=${ex}`);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst { data, errors } = answer;\n\t\tdue = due.flatMap(({ index }, i) => {\n\t\t\tconst alias = `p${i}`;\n\t\t\tconst next = data[alias]?.pullRequest?.timelineItems;\n\t\t\tif (next == null || errors.some(e => e.path?.[0] === alias)) {\n\t\t\t\tscope?.warn(`failed to read past a pull request activity page; ${describeTarget(stale[index].target)}`);\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tconst timeline: Timeline = {\n\t\t\t\tcreatedAt: timelines[index].createdAt,\n\t\t\t\tentries: [...timelines[index].entries, ...toTimelineEntries(next)],\n\t\t\t\tpageInfo: next.pageInfo,\n\t\t\t};\n\t\t\ttimelines[index] = timeline;\n\t\t\treturn followFrom(index, timeline, stale[index].target.cursor);\n\t\t});\n\t}\n\treturn timelines;\n}\n\nfunction followFrom(\n\tindex: number,\n\ttimeline: Timeline,\n\tcursor: GitHubPullRequestActivityCursor,\n): { index: number; after: string }[] {\n\tconst { hasNextPage, endCursor } = timeline.pageInfo;\n\tif (!hasNextPage || endCursor == null) return [];\n\n\tconst since = toEpochSecond(cursor.t);\n\tconst seen = new Set(cursor.ids);\n\treturn timeline.entries.some(i => i.second >= since && !seen.has(i.node.id))\n\t\t? []\n\t\t: [{ index: index, after: endCursor }];\n}\n\nfunction activityQuery(targets: readonly ActivityQueryTarget[], limit: number): string {\n\tconst params: string[] = [];\n\tconst fields: string[] = [];\n\ttargets.forEach((target, i) => {\n\t\tparams.push(`$o${i}: String!`, `$n${i}: String!`, `$k${i}: Int!`);\n\t\tif (target.cursor != null) {\n\t\t\tparams.push(`$s${i}: DateTime!`);\n\t\t}\n\n\t\tconst after = target.cursor != null && target.after != null;\n\t\tif (after) {\n\t\t\tparams.push(`$a${i}: String!`);\n\t\t}\n\n\t\tconst timeline =\n\t\t\ttarget.cursor != null\n\t\t\t\t? `timelineItems(first: ${activityPageSize(limit, target.cursor)}, since: $s${i}, ${after ? `after: $a${i}, ` : ''}itemTypes: [${activityItemTypes}])`\n\t\t\t\t: `timelineItems(last: ${limit}, itemTypes: [${activityItemTypes}])`;\n\t\tfields.push(`p${i}: repository(owner: $o${i}, name: $n${i}) {\n\t\t\t\tpullRequest(number: $k${i}) {\n\t\t\t\t\tcreatedAt\n\t\t\t\t\t${timeline} {\n\t\t\t\t\t\t${timelineNodeFields}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}`);\n\t});\n\treturn `query getPullRequestActivity(\n\t\t\t${params.join('\\n\\t\\t\\t')}\n\t\t) {\n\t\t\t${fields.join('\\n\\t\\t\\t')}\n\t\t}`;\n}\n\nfunction activityPageSize(limit: number, cursor: GitHubPullRequestActivityCursor): number {\n\treturn Math.min(maxPageSize, limit + cursor.ids.length);\n}\n\nfunction activitySince(cursor: GitHubPullRequestActivityCursor): string {\n\treturn new Date(toEpochSecond(cursor.t) * 1000 - 1000).toISOString();\n}\n\nfunction describeTarget(target: GitHubPullRequestActivityTarget): string {\n\treturn `${target.owner}/${target.repo}#${target.number}`;\n}\n\nexport function encodePullRequestActivityCursor(cursor: GitHubPullRequestActivityCursor): string {\n\treturn base64(JSON.stringify({ v: 1, t: cursor.t, ids: cursor.ids }))\n\t\t.replace(/\\+/g, '-')\n\t\t.replace(/\\//g, '_')\n\t\t.replace(/=+$/, '');\n}\n\nexport function decodePullRequestActivityCursor(cursor: string): GitHubPullRequestActivityCursor | undefined {\n\tif (!/^[A-Za-z0-9_-]+$/.test(cursor)) return undefined;\n\n\tlet parsed: unknown;\n\ttry {\n\t\tconst padded = cursor\n\t\t\t.replace(/-/g, '+')\n\t\t\t.replace(/_/g, '/')\n\t\t\t.padEnd(Math.ceil(cursor.length / 4) * 4, '=');\n\t\tparsed = JSON.parse(fromBase64ToString(padded));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (parsed == null || typeof parsed !== 'object') return undefined;\n\n\tconst { v, t, ids } = parsed as { v?: unknown; t?: unknown; ids?: unknown };\n\tif (v !== 1 || typeof t !== 'string' || Number.isNaN(Date.parse(t))) return undefined;\n\tif (!Array.isArray(ids) || !ids.every((id): id is string => typeof id === 'string')) return undefined;\n\n\treturn { t: t, ids: ids };\n}\n\nfunction toTimelineEntries(items: ActivityTimelineItems): TimelineEntry[] {\n\tconst entries: TimelineEntry[] = [];\n\tfor (const item of items.nodes ?? []) {\n\t\tif (item?.id == null || !isActivityNode(item)) continue;\n\t\tif (item.__typename === 'PullRequestReview' && item.state === 'PENDING') continue;\n\n\t\tconst publishedAt = new Date(activityTime(item));\n\t\tentries.push({\n\t\t\tnode: item,\n\t\t\tpublishedAt: publishedAt,\n\t\t\tsecond: toEpochSecond(publishedAt),\n\t\t\tcreatedSecond: toEpochSecond(item.createdAt),\n\t\t});\n\t}\n\treturn entries;\n}\n\nfunction toActivityPage(\n\ttimeline: Timeline,\n\tcursor: GitHubPullRequestActivityCursor | undefined,\n\tlimit: number,\n): PullRequestActivityPage {\n\tconst returned = timeline.entries;\n\n\tif (cursor == null) {\n\t\treturn {\n\t\t\titems: returned.flatMap(i => toActivityItems(i.node, i.publishedAt)),\n\t\t\tcursor: encodePullRequestActivityCursor(baselineCursor(returned, timeline.createdAt)),\n\t\t\thasMore: false,\n\t\t};\n\t}\n\n\tconst since = toEpochSecond(cursor.t);\n\tconst seen = new Set(cursor.ids);\n\tconst inWindow = returned.filter(i => i.second >= since);\n\tconst fresh = inWindow.filter(i => !seen.has(i.node.id));\n\tconst kept = fresh.slice(0, limit);\n\tconst lastKept = kept.at(-1);\n\tconst cut = fresh.length > kept.length || timeline.pageInfo.hasNextPage;\n\treturn {\n\t\titems: kept.flatMap(i => toActivityItems(i.node, i.publishedAt)),\n\t\tcursor: encodePullRequestActivityCursor(\n\t\t\tlastKept != null\n\t\t\t\t? resumeCursor(cursor, returned, inWindow, kept, lastKept, fresh.slice(limit), cut)\n\t\t\t\t: cursor,\n\t\t),\n\t\thasMore: cut,\n\t};\n}\n\nfunction activityTime(node: ActivityNode): string {\n\treturn node.__typename === 'PullRequestReview'\n\t\t? (node.submittedAt ?? node.publishedAt ?? node.createdAt)\n\t\t: (node.publishedAt ?? node.createdAt);\n}\n\nfunction baselineCursor(timeline: readonly TimelineEntry[], createdAt: string): GitHubPullRequestActivityCursor {\n\tif (timeline.length === 0) return { t: toIsoSecond(toEpochSecond(createdAt)), ids: [] };\n\n\tconst t = Math.max(...timeline.map(i => i.second));\n\treturn { t: toIsoSecond(t), ids: timeline.filter(i => i.second === t).map(i => i.node.id) };\n}\n\nfunction resumeCursor(\n\tcursor: GitHubPullRequestActivityCursor,\n\treturned: readonly TimelineEntry[],\n\tinWindow: readonly TimelineEntry[],\n\tkept: readonly TimelineEntry[],\n\tlastKept: TimelineEntry,\n\ttrimmed: readonly TimelineEntry[],\n\tcut: boolean,\n): GitHubPullRequestActivityCursor {\n\tlet t: number;\n\tif (cut) {\n\t\tt = Math.max(\n\t\t\ttoEpochSecond(cursor.t),\n\t\t\tMath.min(lastKept.second, lastKept.createdSecond, ...trimmed.map(i => i.second)),\n\t\t);\n\t} else {\n\t\tt = Math.max(...kept.map(i => i.second));\n\t}\n\n\tconst delivered = new Set([...cursor.ids, ...kept.map(i => i.node.id)]);\n\tconst ids = inWindow.filter(i => i.second >= t && delivered.has(i.node.id)).map(i => i.node.id);\n\tif (cut) {\n\t\tconst present = new Set(returned.map(i => i.node.id));\n\t\tids.push(...cursor.ids.filter(id => !present.has(id)));\n\t}\n\treturn { t: toIsoSecond(t), ids: [...new Set(ids)] };\n}\n\nfunction isActivityNode(node: ActivityTimelineNode): node is ActivityNode {\n\treturn node.__typename === 'IssueComment' || node.__typename === 'PullRequestReview';\n}\n\nfunction toActivityItems(node: ActivityNode, publishedAt: Date): PullRequestActivityItem[] {\n\tconst base = {\n\t\tid: node.id,\n\t\turl: node.url,\n\t\t...authorOf(node.author),\n\t\tpublishedAt: publishedAt,\n\t\tbyViewer: node.viewerDidAuthor === true,\n\t\tisMinimized: node.isMinimized === true,\n\t};\n\tif (node.__typename === 'IssueComment') return [{ kind: 'comment', ...base, body: node.body ?? '' }];\n\n\tconst comments = (node.comments?.nodes ?? []).filter((c): c is ActivityReviewCommentNode => c != null);\n\tconst items: PullRequestActivityItem[] = [\n\t\t{\n\t\t\tkind: 'review',\n\t\t\t...base,\n\t\t\tstate: fromGitHubReviewState(node.state),\n\t\t\tbody: node.body ?? '',\n\t\t\t...(node.commit?.oid != null ? { commitSha: node.commit.oid } : {}),\n\t\t\t...((node.comments?.totalCount ?? 0) > comments.length ? { commentsTruncated: true as const } : {}),\n\t\t},\n\t];\n\n\tconst ordered = comments\n\t\t.map(c => ({ comment: c, createdAt: Date.parse(c.createdAt) }))\n\t\t.sort((a, b) => a.createdAt - b.createdAt);\n\tfor (const { comment } of ordered) {\n\t\titems.push({\n\t\t\tkind: 'review-comment',\n\t\t\tid: comment.id,\n\t\t\turl: comment.url,\n\t\t\t...authorOf(comment.author),\n\t\t\tpublishedAt: publishedAt,\n\t\t\tbyViewer: comment.viewerDidAuthor === true,\n\t\t\tisMinimized: comment.isMinimized === true,\n\t\t\treviewId: node.id,\n\t\t\tbody: comment.body ?? '',\n\t\t\tpath: comment.path,\n\t\t\t...(comment.line != null ? { line: comment.line } : {}),\n\t\t\t...(comment.startLine != null ? { startLine: comment.startLine } : {}),\n\t\t\t...(comment.originalLine != null ? { originalLine: comment.originalLine } : {}),\n\t\t\toutdated: comment.outdated === true,\n\t\t\t...(comment.replyTo?.id != null ? { inReplyTo: comment.replyTo.id } : {}),\n\t\t\t...(comment.commit?.oid != null ? { commitSha: comment.commit.oid } : {}),\n\t\t});\n\t}\n\treturn items;\n}\n\nfunction authorOf(actor: ActivityActorNode | undefined): { author?: PullRequestActivityAuthor } {\n\tif (actor?.login == null) return {};\n\n\treturn {\n\t\tauthor: {\n\t\t\tlogin: actor.login,\n\t\t\t...(actor.url != null ? { url: actor.url } : {}),\n\t\t\tisBot: actor.__typename === 'Bot',\n\t\t},\n\t};\n}\n\nfunction fromGitHubReviewState(state: string): 'approved' | 'changes-requested' | 'commented' | 'dismissed' {\n\tswitch (state) {\n\t\tcase 'APPROVED':\n\t\t\treturn 'approved';\n\t\tcase 'CHANGES_REQUESTED':\n\t\t\treturn 'changes-requested';\n\t\tcase 'DISMISSED':\n\t\t\treturn 'dismissed';\n\t\tdefault:\n\t\t\treturn 'commented';\n\t}\n}\n\nfunction toIsoSecond(second: number): string {\n\treturn new Date(second * 1000).toISOString();\n}\n\nfunction toEpochSecond(time: string | Date): number {\n\treturn Math.floor((typeof time === 'string' ? Date.parse(time) : time.getTime()) / 1000);\n}\n"],"mappings":";;;;AAmFA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAE/B,MAAM,oBAAoB;AAC1B,MAAM,cAAc;AAEpB,MAAM,qBAAqB;;6FAEkE,YAAY;;UAE/F,YAAY;0BACI,uBAAuB,yBAAyB,yIAN2F,cAMvE;;AAG9F,eAAsB,8BACrB,SACA,SACA,OACA,OACuE;CACvE,IAAI;CACJ,IAAI;EACH,YAAY,MAAM,cAAc,SAAS,SAAS,OAAO,KAAK;CAC/D,SAAS,IAAI;EACZ,IAAI,oBAAoB,EAAE,GAAG,MAAM;EAEnC,OAAO,KAAK,4CAA4C,IAAI;EAC5D,OAAO,QAAQ,WAAkC;GAAE,QAAQ;GAAY,QAAQ;EAAG,EAAE;CACrF;CAEA,OAAO,QAAQ,KAAK,QAAQ,MAAiE;EAC5F,MAAM,OAAO,UAAU;EACvB,IAAI,KAAK,WAAW,YAAY,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