@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.
Files changed (82) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/dist/git/models/pullRequest.d.ts +55 -1
  3. package/dist/git/models/pullRequest.js +5 -1
  4. package/dist/git/models/pullRequest.js.map +1 -1
  5. package/dist/git/models/pullRequestActivity.d.ts +55 -0
  6. package/dist/git/models/pullRequestActivity.js +0 -0
  7. package/dist/git/utils/pullRequest.utils.js +3 -1
  8. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  9. package/dist/git/watching/worktreeSummary.d.ts +1 -0
  10. package/dist/git/watching/worktreeSummary.js +34 -2
  11. package/dist/git/watching/worktreeSummary.js.map +1 -1
  12. package/dist/plus/git-github/api/aliasedQuery.d.ts +19 -0
  13. package/dist/plus/git-github/api/aliasedQuery.js +21 -0
  14. package/dist/plus/git-github/api/aliasedQuery.js.map +1 -0
  15. package/dist/plus/git-github/api/cancellation.d.ts +4 -0
  16. package/dist/plus/git-github/api/cancellation.js +9 -0
  17. package/dist/plus/git-github/api/cancellation.js.map +1 -0
  18. package/dist/plus/git-github/api/checkRunLogs.d.ts +31 -0
  19. package/dist/plus/git-github/api/checkRunLogs.js +252 -0
  20. package/dist/plus/git-github/api/checkRunLogs.js.map +1 -0
  21. package/dist/plus/git-github/api/checkRuns.d.ts +26 -0
  22. package/dist/plus/git-github/api/checkRuns.js +191 -0
  23. package/dist/plus/git-github/api/checkRuns.js.map +1 -0
  24. package/dist/plus/git-github/api/github.d.ts +25 -2
  25. package/dist/plus/git-github/api/github.js +169 -37
  26. package/dist/plus/git-github/api/github.js.map +1 -1
  27. package/dist/plus/git-github/api/issueWrites.d.ts +51 -0
  28. package/dist/plus/git-github/api/issueWrites.js +192 -0
  29. package/dist/plus/git-github/api/issueWrites.js.map +1 -0
  30. package/dist/plus/git-github/api/pullRequestActivity.d.ts +19 -0
  31. package/dist/plus/git-github/api/pullRequestActivity.js +355 -0
  32. package/dist/plus/git-github/api/pullRequestActivity.js.map +1 -0
  33. package/dist/plus/git-github/models.d.ts +100 -4
  34. package/dist/plus/git-github/models.js +135 -3
  35. package/dist/plus/git-github/models.js.map +1 -1
  36. package/dist/plus/integrations/authentication/rejectedTokenTracker.d.ts +7 -8
  37. package/dist/plus/integrations/authentication/rejectedTokenTracker.js +7 -8
  38. package/dist/plus/integrations/authentication/rejectedTokenTracker.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 +6 -2
  43. package/dist/plus/integrations/index.js.map +1 -1
  44. package/dist/plus/integrations/integrationService.d.ts +31 -1
  45. package/dist/plus/integrations/integrationService.js +45 -0
  46. package/dist/plus/integrations/integrationService.js.map +1 -1
  47. package/dist/plus/integrations/manager.d.ts +86 -0
  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 +26 -5
  52. package/dist/plus/integrations/models/integration.js +35 -10
  53. package/dist/plus/integrations/models/integration.js.map +1 -1
  54. package/dist/plus/integrations/providers/asana.d.ts +4 -5
  55. package/dist/plus/integrations/providers/asana.js +53 -12
  56. package/dist/plus/integrations/providers/asana.js.map +1 -1
  57. package/dist/plus/integrations/providers/github.d.ts +18 -3
  58. package/dist/plus/integrations/providers/github.js +90 -5
  59. package/dist/plus/integrations/providers/github.js.map +1 -1
  60. package/dist/plus/integrations/providers/linear.js +6 -6
  61. package/dist/plus/integrations/providers/linear.js.map +1 -1
  62. package/dist/plus/integrations/providers/models.d.ts +6 -15
  63. package/dist/plus/integrations/providers/models.js +1 -1
  64. package/dist/plus/integrations/providers/models.js.map +1 -1
  65. package/dist/plus/integrations/providers/providersApi.d.ts +1 -6
  66. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  67. package/dist/plus/integrations/reads/etag.js +20 -5
  68. package/dist/plus/integrations/reads/etag.js.map +1 -1
  69. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +36 -0
  70. package/dist/plus/integrations/reads/pullRequestActivity.js +103 -0
  71. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -0
  72. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +4 -1
  73. package/dist/plus/integrations/reads/pullRequestBatch.js +5 -2
  74. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  75. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +2 -0
  76. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  77. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  78. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +27 -0
  79. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +92 -0
  80. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -0
  81. package/docs/integrations.md +115 -5
  82. package/package.json +2 -2
@@ -5,7 +5,7 @@ import { isIssueResourceDescriptor } from "../../../git/utils/resourceDescriptor
5
5
  import { IntegrationReadUnavailableError, toError } from "../errors.js";
6
6
  import { throwIfCallerContractError, toCollectionScopeFailure } from "../collectionMetadata.js";
7
7
  import { collectProviderPagedResult, mergeCollectionMetadata } from "./utils/providerPaging.js";
8
- import { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from "./models.js";
8
+ import { fromProviderIssue, providersMetadata, toIssueProviderState, toIssueShape, toProviderIssueStates } from "./models.js";
9
9
  import { toTokenWithInfo } from "../authentication/models.js";
10
10
  import { IssuesIntegration, groupProjectIssuesSearches } from "../models/issuesIntegration.js";
11
11
  //#region ../plus/integrations/src/providers/asana.ts
@@ -176,11 +176,10 @@ var AsanaIntegration = class extends IssuesIntegration {
176
176
  * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,
177
177
  * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.
178
178
  *
179
- * A known limitation: an unscoped task read reports only the first project Asana lists for a task, so a task in
180
- * several projects is attributed to that one alone, and is left out when that project isn't requested even if
181
- * another of its projects is. The per-project fallback lists it under every requested project instead. Falling
182
- * back whenever a task's project is outside the search would avoid this, but most searches hold such a task, so
183
- * nearly every search would drain each project in full.
179
+ * A task can be in several projects (a sprint board and each customer's own board, say), and an unscoped task read
180
+ * reports only the first one Asana lists as its `project`. So it is filed under every requested project among its
181
+ * memberships (`projectMemberships`), with its section in that project as its state, as the per-project fallback
182
+ * would list it.
184
183
  */
185
184
  async searchProviderProjectIssues(session, requests) {
186
185
  const projects = requests.map((request) => request.project).filter(isAsanaProjectDescriptor);
@@ -193,14 +192,13 @@ var AsanaIntegration = class extends IssuesIntegration {
193
192
  if (drain.truncated || drain.metadata != null && drain.metadata.completeness !== "complete") return;
194
193
  const indexById = new Map(projects.map((project, index) => [project.id, index]));
195
194
  const split = projects.map(() => []);
196
- for (const issue of drain.values) {
197
- const index = issue.project?.id != null ? indexById.get(issue.project.id) : void 0;
198
- if (index == null) continue;
199
- const shape = toIssueShape(issue, this, { projection: "project" });
195
+ for (const task of drain.values) {
196
+ const shape = toIssueShape(task, this, { projection: "project" });
200
197
  if (shape == null) continue;
201
- split[index].push({
198
+ for (const { index, state } of toRequestedProjectPlacements(task, indexById)) split[index].push({
202
199
  ...shape,
203
- project: toIssueProject(projects[index])
200
+ project: toIssueProject(projects[index]),
201
+ providerState: toIssueProviderState(state)
204
202
  });
205
203
  }
206
204
  return split;
@@ -309,6 +307,49 @@ var AsanaIntegration = class extends IssuesIntegration {
309
307
  function isAsanaProjectDescriptor(project) {
310
308
  return isIssueResourceDescriptor(project) && typeof project.resourceId === "string";
311
309
  }
310
+ /**
311
+ * Each requested project a task is in, by its index in the read, with the task's state as that project would list it:
312
+ * its section there, since the unscoped read reports the first membership's.
313
+ */
314
+ function toRequestedProjectPlacements(issue, indexById) {
315
+ const memberships = issue.projectMemberships;
316
+ if (memberships == null) {
317
+ const index = issue.project?.id != null ? indexById.get(issue.project.id) : void 0;
318
+ return index != null ? [{
319
+ index,
320
+ state: issue.state
321
+ }] : [];
322
+ }
323
+ const placements = [];
324
+ for (const membership of memberships) {
325
+ const index = indexById.get(membership.project.id);
326
+ if (index == null || placements.some((p) => p.index === index)) continue;
327
+ placements.push({
328
+ index,
329
+ state: getProjectMembershipState(issue, membership)
330
+ });
331
+ }
332
+ return placements;
333
+ }
334
+ /**
335
+ * Mirrors provider-apis' state for a task read scoped to the membership's project; the parity test in `asana.test.ts`
336
+ * runs both through provider-apis' own normalization to keep them agreeing.
337
+ */
338
+ function getProjectMembershipState(issue, membership) {
339
+ if (issue.project?.id === membership.project.id) return issue.state;
340
+ const completed = issue.closedDate != null;
341
+ if (membership.section != null) return {
342
+ id: membership.section.id,
343
+ name: membership.section.name,
344
+ color: null,
345
+ ...completed ? { category: "DONE" } : {}
346
+ };
347
+ return completed ? {
348
+ name: "Completed",
349
+ color: null,
350
+ category: "DONE"
351
+ } : null;
352
+ }
312
353
  function toIssueProject(project) {
313
354
  return {
314
355
  id: project.id,
@@ -1 +1 @@
1
- {"version":3,"file":"asana.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asana.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, IssueProject, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { throwIfCallerContractError, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IntegrationReadUnavailableError, toError } from '../errors.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration } from '../models/issuesIntegration.js';\nimport type { ProviderApiCollectionResult, ProviderIssue } from './models.js';\nimport { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from './models.js';\nimport { collectProviderPagedResult, mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata.asana;\ntype AsanaIntegrationId = typeof metadata.id;\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n/** The workspace and project discovery backstop: provider-apis pages them 100 at a time, so 2,000 of each. */\nconst maxDiscoveryPages = 20;\n/** The task drain's backstop, per project or per workspace: 1,000 tasks at the SDK's 100-per-page. */\nconst maxTaskPages = 10;\n\n/** An Asana project, naming the workspace it belongs to so its tasks can be encoded and its account resolved. */\nexport interface AsanaProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n\tresourceName: string;\n}\n\nexport class AsanaIntegration extends IssuesIntegration<AsanaIntegrationId> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\toverride get id(): AsanaIntegrationId {\n\t\treturn metadata.id;\n\t}\n\tprotected override get key(): 'asana' {\n\t\treturn 'asana';\n\t}\n\toverride get name(): string {\n\t\treturn metadata.name;\n\t}\n\toverride get domain(): string {\n\t\treturn metadata.domain;\n\t}\n\n\t/**\n\t * Always asks Asana: the host's current-account cache decides when this runs. An Asana user is the same in every\n\t * workspace, so the answer is lent briefly to the per-workspace lookup a tracker read makes right after it.\n\t */\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst account = await this.fetchAccount(session);\n\t\tif (account != null) {\n\t\t\tthis._recentAccounts.set(session.accessToken, Promise.resolve(account));\n\t\t}\n\t\treturn account;\n\t}\n\n\tprotected override getProviderUncachedAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this.fetchAccount(session);\n\t}\n\n\tprotected override getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._recentAccounts.clear();\n\t}\n\n\tprivate readonly _recentAccounts = new PromiseCache<string, Account | undefined>({\n\t\tcapacity: 10,\n\t\tcreateTTL: recentAccountTTL,\n\t});\n\n\tprivate async fetchAccount(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getAsanaCurrentUser(toTokenWithInfo(this.id, session));\n\t\tif (user == null) return undefined;\n\n\t\treturn {\n\t\t\tprovider: this,\n\t\t\tid: user.id,\n\t\t\tname: user.name ?? undefined,\n\t\t\t// Asana has no usernames; the SDK reports the display name as the handle.\n\t\t\tusername: user.username ?? undefined,\n\t\t\temail: user.email ?? undefined,\n\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t};\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<IssueResourceDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst workspaces = await collectProviderPagedResult(\n\t\t\tcursor => api.getAsanaWorkspacesForCurrentUser(tokenWithInfo, { cursor: cursor }),\n\t\t\tmaxDiscoveryPages,\n\t\t);\n\t\t// Resource discovery has no completeness to report, so a user past the backstop is logged rather than refused:\n\t\t// the workspaces read still hold their projects.\n\t\tif (workspaces.truncated) {\n\t\t\tLogger.warn(`Asana workspace discovery stopped after ${workspaces.values.length} workspaces`);\n\t\t}\n\t\treturn workspaces.values.map(w => ({ key: w.id, id: w.id, name: w.name }));\n\t}\n\n\tprotected override async getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<AsanaProjectDescriptor[] | undefined> {\n\t\treturn (await this.getProviderProjectsForResourcesWithMetadata(session, resources)).values;\n\t}\n\n\t/**\n\t * Each workspace's unarchived projects, drained per workspace. A workspace whose drain failed or ran out of pages\n\t * keeps what it read and is recorded in the metadata, so one large or unreadable workspace doesn't hide the rest.\n\t */\n\tprotected override async getProviderProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<AsanaProjectDescriptor>> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\tconst values: AsanaProjectDescriptor[] = [];\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tfor (const workspace of resources.filter(isIssueResourceDescriptor)) {\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tconst projects = await collectProviderPagedResult(\n\t\t\t\tcursor => api.getAsanaProjectsForWorkspace(tokenWithInfo, workspace.id, { cursor: cursor }),\n\t\t\t\tmaxDiscoveryPages,\n\t\t\t\tscope,\n\t\t\t);\n\t\t\tvalues.push(\n\t\t\t\t...projects.values.map(p => ({\n\t\t\t\t\tkey: p.id,\n\t\t\t\t\tid: p.id,\n\t\t\t\t\tname: p.name,\n\t\t\t\t\tresourceId: workspace.id,\n\t\t\t\t\tresourceName: workspace.name,\n\t\t\t\t})),\n\t\t\t);\n\t\t\tcollectionMetadata = mergeCollectionMetadata(\n\t\t\t\tcollectionMetadata,\n\t\t\t\tprojects.truncated && !projects.metadata?.failures?.length\n\t\t\t\t\t? mergeCollectionMetadata(projects.metadata, {\n\t\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\t\tomissions: [{ kind: 'pagination-incomplete', scope: scope }],\n\t\t\t\t\t\t})\n\t\t\t\t\t: projects.metadata,\n\t\t\t);\n\t\t}\n\n\t\treturn collectionMetadata != null ? { values: values, metadata: collectionMetadata } : { values: values };\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\t/**\n\t * A project's tasks, narrowed to the viewer's by assignee after the drain: Asana's task list takes a project or\n\t * an assignee, never both. So a user-scoped read of a busy project spends its page budget on other people's\n\t * tasks, and a truncated one can't be recovered by a narrower scope.\n\t */\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tif (!isAsanaProjectDescriptor(project)) return undefined;\n\n\t\tlet viewerId: string | undefined;\n\t\tif (options?.user != null) {\n\t\t\tviewerId = options.userId ?? (await this.getProviderAccountForResource(session, project))?.id;\n\t\t\t// Without the viewer the read can't be scoped to \"my issues\": the unfiltered project would leak everyone\n\t\t\t// else's tasks, and an empty list would read as \"nothing assigned to me\".\n\t\t\tif (viewerId == null) {\n\t\t\t\tthrow new IntegrationReadUnavailableError(\n\t\t\t\t\tmetadata.name,\n\t\t\t\t\t'could not resolve the current user to scope issues to',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst drain = await this.drainTasks(session, { projectId: project.id }, options, {\n\t\t\tproviderId: this.id,\n\t\t\tresourceId: project.resourceId,\n\t\t\tprojectId: project.id,\n\t\t});\n\n\t\tconst issueProject = toIssueProject(project);\n\t\tconst values = drain.values.flatMap(issue => {\n\t\t\tif (viewerId != null && !issue.assignees.some(a => a.id === viewerId)) return [];\n\n\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn shape == null ? [] : [{ ...shape, project: issueProject } satisfies IssueShape];\n\t\t});\n\n\t\treturn drain.truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: drain.metadata }\n\t\t\t: { values: values, truncated: false, metadata: drain.metadata };\n\t}\n\n\t/**\n\t * Searches every project of one workspace together when the read is scoped to the viewer: Asana's \"my tasks\" read\n\t * takes the workspace and the assignee, so one drain answers all of them, where reading project by project would\n\t * drain every task of every project only to keep the viewer's.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(requests, ({ project, options }) =>\n\t\t\toptions.user != null && isAsanaProjectDescriptor(project)\n\t\t\t\t? [\n\t\t\t\t\t\tproject.resourceId,\n\t\t\t\t\t\toptions.user,\n\t\t\t\t\t\toptions.userId ?? '',\n\t\t\t\t\t\toptions.sort ?? '',\n\t\t\t\t\t\toptions.state ?? '',\n\t\t\t\t\t\toptions.filters?.join(',') ?? '',\n\t\t\t\t\t].join('\\0')\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\t/**\n\t * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,\n\t * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.\n\t *\n\t * A known limitation: an unscoped task read reports only the first project Asana lists for a task, so a task in\n\t * several projects is attributed to that one alone, and is left out when that project isn't requested even if\n\t * another of its projects is. The per-project fallback lists it under every requested project instead. Falling\n\t * back whenever a task's project is outside the search would avoid this, but most searches hold such a task, so\n\t * nearly every search would drain each project in full.\n\t */\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\tconst projects = requests.map(request => request.project).filter(isAsanaProjectDescriptor);\n\t\tif (projects.length !== requests.length) return undefined;\n\n\t\t// Every request of a search shares the workspace and every option read here (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tconst drain = await this.drainTasks(\n\t\t\tsession,\n\t\t\t{ workspaceId: projects[0].resourceId },\n\t\t\toptions,\n\t\t\t// Never published: an incomplete search is read again project by project, which records its own failures.\n\t\t\t{ providerId: this.id, resourceId: projects[0].resourceId },\n\t\t);\n\t\t// An incomplete search says nothing about which of its projects it covered, so only the per-project reads can\n\t\t// report each one's completeness.\n\t\tif (drain.truncated || (drain.metadata != null && drain.metadata.completeness !== 'complete')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst indexById = new Map(projects.map((project, index) => [project.id, index]));\n\t\tconst split = projects.map((): IssueShape[] => []);\n\t\tfor (const issue of drain.values) {\n\t\t\tconst index = issue.project?.id != null ? indexById.get(issue.project.id) : undefined;\n\t\t\tif (index == null) continue;\n\n\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\tif (shape == null) continue;\n\n\t\t\tsplit[index].push({ ...shape, project: toIssueProject(projects[index]) });\n\t\t}\n\t\treturn split;\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * The tasks assigned to the viewer, one drain per workspace (Asana requires the workspace alongside the\n\t * assignee). Reads every workspace the user belongs to unless `resources` names some. A workspace that can't be\n\t * read is recorded in the metadata and the others are still returned; only when none could be read does the read\n\t * throw. Cancellation stops between workspaces and is not reported as truncation: the caller asked for the read to\n\t * stop.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst workspaces = (resources ?? (await this.getProviderResourcesForUser(session)) ?? []).filter(\n\t\t\tisIssueResourceDescriptor,\n\t\t);\n\n\t\tconst values: IssueShape[] = [];\n\t\tlet truncated = false;\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tlet firstError: Error | undefined;\n\t\tlet workspacesRead = 0;\n\t\tfor (const workspace of workspaces) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tlet drain: Awaited<ReturnType<AsanaIntegration['drainTasks']>>;\n\t\t\ttry {\n\t\t\t\tdrain = await this.drainTasks(session, { workspaceId: workspace.id }, options, scope);\n\t\t\t} catch (ex) {\n\t\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t\tthrowIfCallerContractError(ex);\n\n\t\t\t\tfirstError ??= toError(ex);\n\t\t\t\ttruncated = true;\n\t\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(scope, ex)],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tworkspacesRead++;\n\t\t\ttruncated ||= drain.truncated;\n\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, drain.metadata);\n\t\t\tfor (const issue of drain.values) {\n\t\t\t\tconst shape = toIssueShape(issue, this, { projection: 'account' });\n\t\t\t\tif (shape != null) {\n\t\t\t\t\tvalues.push({ ...shape, project: toAsanaIssueProject(issue, workspace) });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Every workspace failed: an empty \"my issues\" would read as \"nothing assigned to me\".\n\t\tif (workspacesRead === 0 && firstError != null) throw firstError;\n\n\t\treturn { values: values, truncated: truncated, metadata: collectionMetadata };\n\t}\n\n\t/**\n\t * Follows a task read's cursor up to {@link maxTaskPages}. `truncated` is set when the backstop stopped it with\n\t * pages left, or when a page after the first failed (recorded under `scope`, keeping the prefix). A failure on the\n\t * first page throws, so the caller sees an error rather than an empty success.\n\t */\n\tprivate async drainTasks(\n\t\tsession: ProviderAuthenticationSession,\n\t\tread: { projectId: string } | { workspaceId: string },\n\t\toptions: Pick<IssuesForProjectOptions, 'state' | 'sort'> | undefined,\n\t\tscope: CollectionScopeFailure['scope'],\n\t): Promise<{ values: ProviderIssue[]; truncated: boolean; metadata?: CollectionMetadata }> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tlet pagesRead = 0;\n\t\tlet firstPageError: Error | undefined;\n\t\tconst drain = await collectProviderPagedResult(\n\t\t\tasync cursor => {\n\t\t\t\tconst pageOptions = { cursor: cursor, states: states, sort: options?.sort };\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await ('projectId' in read\n\t\t\t\t\t\t? api.getAsanaIssuesForProject(tokenWithInfo, read.projectId, pageOptions)\n\t\t\t\t\t\t: api.getAsanaIssuesForCurrentUser(tokenWithInfo, read.workspaceId, pageOptions));\n\t\t\t\t\tpagesRead++;\n\t\t\t\t\treturn page;\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tif (pagesRead === 0) {\n\t\t\t\t\t\tfirstPageError = toError(ex);\n\t\t\t\t\t}\n\t\t\t\t\tthrow ex;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmaxTaskPages,\n\t\t\tscope,\n\t\t);\n\t\tif (firstPageError != null) throw firstPageError;\n\n\t\treturn { values: drain.values, truncated: drain.truncated === true, metadata: drain.metadata };\n\t}\n\n\tprotected override getProviderLinkedIssueOrPullRequest(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t\t_id: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\t// Asana task references are gids in a permalink URL, never a short key a commit message would carry.\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/** `resource` is the task's workspace; `id` is the task gid, which is also what an Asana issue reports as its id. */\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tif (!isIssueResourceDescriptor(resource)) return undefined;\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getAsanaIssue(toTokenWithInfo(this.id, session), id);\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, { projection: 'point', project: toAsanaIssueProject(issue, resource) })\n\t\t\t: undefined;\n\t}\n}\n\nfunction isAsanaProjectDescriptor(project: ResourceDescriptor): project is AsanaProjectDescriptor {\n\treturn isIssueResourceDescriptor(project) && typeof project.resourceId === 'string';\n}\n\nfunction toIssueProject(project: AsanaProjectDescriptor): IssueProject {\n\treturn { id: project.id, name: project.name, resourceId: project.resourceId, resourceName: project.resourceName };\n}\n\n/**\n * The project an issue read outside a project reports. An Asana issue entity identifier is keyed by the task's\n * workspace, which the SDK reports beside the project rather than in it, so this always names the workspace as the\n * resource. A task in no project (only in someone's My Tasks) reports the workspace as its project too, so its\n * branch associations stay round-trippable.\n */\nfunction toAsanaIssueProject(issue: ProviderIssue, workspace: IssueResourceDescriptor): IssueProject {\n\tconst resourceId = issue.workspaceId ?? workspace.id;\n\tconst resourceName = resourceId === workspace.id ? workspace.name : '';\n\treturn issue.project?.id != null\n\t\t? { id: issue.project.id, name: issue.project.name, resourceId: resourceId, resourceName: resourceName }\n\t\t: { id: resourceId, name: resourceName, resourceId: resourceId, resourceName: resourceName };\n}\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,WAAW,kBAAkB;AAEnC,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;;AAEzB,MAAM,oBAAoB;;AAE1B,MAAM,eAAe;AAQrB,IAAa,mBAAb,cAAsC,kBAAsC;CAC3E,eAAqE;CAErE,IAAa,KAAyB;EACrC,OAAO,SAAS;CACjB;CACA,IAAuB,MAAe;EACrC,OAAO;CACR;CACA,IAAa,OAAe;EAC3B,OAAO,SAAS;CACjB;CACA,IAAa,SAAiB;EAC7B,OAAO,SAAS;CACjB;;;;;CAMA,MAAyB,0BACxB,SAC+B;EAC/B,MAAM,UAAU,MAAM,KAAK,aAAa,OAAO;EAC/C,IAAI,WAAW,MACd,KAAK,gBAAgB,IAAI,QAAQ,aAAa,QAAQ,QAAQ,OAAO,CAAC;EAEvE,OAAO;CACR;CAEA,sCACC,SACA,WAC+B;EAC/B,OAAO,KAAK,aAAa,OAAO;CACjC;CAEA,8BACC,SACA,WAC+B;EAC/B,OAAO,KAAK,gBAAgB,YAAY,QAAQ,mBAAmB,KAAK,aAAa,OAAO,GAAG,EAC9F,YAAW,YAAW,WAAW,KAClC,CAAC;CACF;CAEA,uBAAgD;EAC/C,KAAK,gBAAgB,MAAM;CAC5B;CAEA,kBAAmC,IAAI,aAA0C;EAChF,UAAU;EACV,WAAW;CACZ,CAAC;CAED,MAAc,aAAa,SAAsE;EAEhG,MAAM,OAAO,OAAM,MADD,KAAK,gBAAgB,EAAA,CAChB,oBAAoB,gBAAgB,KAAK,IAAI,OAAO,CAAC;EAC5E,IAAI,QAAQ,MAAM,OAAO,KAAA;EAEzB,OAAO;GACN,UAAU;GACV,IAAI,KAAK;GACT,MAAM,KAAK,QAAQ,KAAA;GAEnB,UA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AAM,QAAQ;EAAkB;EAA0B;CAAa,IACrG;EAAE,IAAI;EAAY,MAAM;EAA0B;EAA0B;CAAa;AAC7F"}
1
+ {"version":3,"file":"asana.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asana.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure, IssueProjectMembership } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, IssueProject, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { throwIfCallerContractError, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IntegrationReadUnavailableError, toError } from '../errors.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration } from '../models/issuesIntegration.js';\nimport type { ProviderApiCollectionResult, ProviderIssue } from './models.js';\nimport {\n\tfromProviderIssue,\n\tprovidersMetadata,\n\ttoIssueProviderState,\n\ttoIssueShape,\n\ttoProviderIssueStates,\n} from './models.js';\nimport { collectProviderPagedResult, mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata.asana;\ntype AsanaIntegrationId = typeof metadata.id;\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n/** The workspace and project discovery backstop: provider-apis pages them 100 at a time, so 2,000 of each. */\nconst maxDiscoveryPages = 20;\n/** The task drain's backstop, per project or per workspace: 1,000 tasks at the SDK's 100-per-page. */\nconst maxTaskPages = 10;\n\n/** An Asana project, naming the workspace it belongs to so its tasks can be encoded and its account resolved. */\nexport interface AsanaProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n\tresourceName: string;\n}\n\nexport class AsanaIntegration extends IssuesIntegration<AsanaIntegrationId> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\toverride get id(): AsanaIntegrationId {\n\t\treturn metadata.id;\n\t}\n\tprotected override get key(): 'asana' {\n\t\treturn 'asana';\n\t}\n\toverride get name(): string {\n\t\treturn metadata.name;\n\t}\n\toverride get domain(): string {\n\t\treturn metadata.domain;\n\t}\n\n\t/**\n\t * Always asks Asana: the host's current-account cache decides when this runs. An Asana user is the same in every\n\t * workspace, so the answer is lent briefly to the per-workspace lookup a tracker read makes right after it.\n\t */\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst account = await this.fetchAccount(session);\n\t\tif (account != null) {\n\t\t\tthis._recentAccounts.set(session.accessToken, Promise.resolve(account));\n\t\t}\n\t\treturn account;\n\t}\n\n\tprotected override getProviderUncachedAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this.fetchAccount(session);\n\t}\n\n\tprotected override getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._recentAccounts.clear();\n\t}\n\n\tprivate readonly _recentAccounts = new PromiseCache<string, Account | undefined>({\n\t\tcapacity: 10,\n\t\tcreateTTL: recentAccountTTL,\n\t});\n\n\tprivate async fetchAccount(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getAsanaCurrentUser(toTokenWithInfo(this.id, session));\n\t\tif (user == null) return undefined;\n\n\t\treturn {\n\t\t\tprovider: this,\n\t\t\tid: user.id,\n\t\t\tname: user.name ?? undefined,\n\t\t\t// Asana has no usernames; the SDK reports the display name as the handle.\n\t\t\tusername: user.username ?? undefined,\n\t\t\temail: user.email ?? undefined,\n\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t};\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<IssueResourceDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst workspaces = await collectProviderPagedResult(\n\t\t\tcursor => api.getAsanaWorkspacesForCurrentUser(tokenWithInfo, { cursor: cursor }),\n\t\t\tmaxDiscoveryPages,\n\t\t);\n\t\t// Resource discovery has no completeness to report, so a user past the backstop is logged rather than refused:\n\t\t// the workspaces read still hold their projects.\n\t\tif (workspaces.truncated) {\n\t\t\tLogger.warn(`Asana workspace discovery stopped after ${workspaces.values.length} workspaces`);\n\t\t}\n\t\treturn workspaces.values.map(w => ({ key: w.id, id: w.id, name: w.name }));\n\t}\n\n\tprotected override async getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<AsanaProjectDescriptor[] | undefined> {\n\t\treturn (await this.getProviderProjectsForResourcesWithMetadata(session, resources)).values;\n\t}\n\n\t/**\n\t * Each workspace's unarchived projects, drained per workspace. A workspace whose drain failed or ran out of pages\n\t * keeps what it read and is recorded in the metadata, so one large or unreadable workspace doesn't hide the rest.\n\t */\n\tprotected override async getProviderProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<AsanaProjectDescriptor>> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\tconst values: AsanaProjectDescriptor[] = [];\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tfor (const workspace of resources.filter(isIssueResourceDescriptor)) {\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tconst projects = await collectProviderPagedResult(\n\t\t\t\tcursor => api.getAsanaProjectsForWorkspace(tokenWithInfo, workspace.id, { cursor: cursor }),\n\t\t\t\tmaxDiscoveryPages,\n\t\t\t\tscope,\n\t\t\t);\n\t\t\tvalues.push(\n\t\t\t\t...projects.values.map(p => ({\n\t\t\t\t\tkey: p.id,\n\t\t\t\t\tid: p.id,\n\t\t\t\t\tname: p.name,\n\t\t\t\t\tresourceId: workspace.id,\n\t\t\t\t\tresourceName: workspace.name,\n\t\t\t\t})),\n\t\t\t);\n\t\t\tcollectionMetadata = mergeCollectionMetadata(\n\t\t\t\tcollectionMetadata,\n\t\t\t\tprojects.truncated && !projects.metadata?.failures?.length\n\t\t\t\t\t? mergeCollectionMetadata(projects.metadata, {\n\t\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\t\tomissions: [{ kind: 'pagination-incomplete', scope: scope }],\n\t\t\t\t\t\t})\n\t\t\t\t\t: projects.metadata,\n\t\t\t);\n\t\t}\n\n\t\treturn collectionMetadata != null ? { values: values, metadata: collectionMetadata } : { values: values };\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\t/**\n\t * A project's tasks, narrowed to the viewer's by assignee after the drain: Asana's task list takes a project or\n\t * an assignee, never both. So a user-scoped read of a busy project spends its page budget on other people's\n\t * tasks, and a truncated one can't be recovered by a narrower scope.\n\t */\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tif (!isAsanaProjectDescriptor(project)) return undefined;\n\n\t\tlet viewerId: string | undefined;\n\t\tif (options?.user != null) {\n\t\t\tviewerId = options.userId ?? (await this.getProviderAccountForResource(session, project))?.id;\n\t\t\t// Without the viewer the read can't be scoped to \"my issues\": the unfiltered project would leak everyone\n\t\t\t// else's tasks, and an empty list would read as \"nothing assigned to me\".\n\t\t\tif (viewerId == null) {\n\t\t\t\tthrow new IntegrationReadUnavailableError(\n\t\t\t\t\tmetadata.name,\n\t\t\t\t\t'could not resolve the current user to scope issues to',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst drain = await this.drainTasks(session, { projectId: project.id }, options, {\n\t\t\tproviderId: this.id,\n\t\t\tresourceId: project.resourceId,\n\t\t\tprojectId: project.id,\n\t\t});\n\n\t\tconst issueProject = toIssueProject(project);\n\t\tconst values = drain.values.flatMap(issue => {\n\t\t\tif (viewerId != null && !issue.assignees.some(a => a.id === viewerId)) return [];\n\n\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn shape == null ? [] : [{ ...shape, project: issueProject } satisfies IssueShape];\n\t\t});\n\n\t\treturn drain.truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: drain.metadata }\n\t\t\t: { values: values, truncated: false, metadata: drain.metadata };\n\t}\n\n\t/**\n\t * Searches every project of one workspace together when the read is scoped to the viewer: Asana's \"my tasks\" read\n\t * takes the workspace and the assignee, so one drain answers all of them, where reading project by project would\n\t * drain every task of every project only to keep the viewer's.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(requests, ({ project, options }) =>\n\t\t\toptions.user != null && isAsanaProjectDescriptor(project)\n\t\t\t\t? [\n\t\t\t\t\t\tproject.resourceId,\n\t\t\t\t\t\toptions.user,\n\t\t\t\t\t\toptions.userId ?? '',\n\t\t\t\t\t\toptions.sort ?? '',\n\t\t\t\t\t\toptions.state ?? '',\n\t\t\t\t\t\toptions.filters?.join(',') ?? '',\n\t\t\t\t\t].join('\\0')\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\t/**\n\t * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,\n\t * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.\n\t *\n\t * A task can be in several projects (a sprint board and each customer's own board, say), and an unscoped task read\n\t * reports only the first one Asana lists as its `project`. So it is filed under every requested project among its\n\t * memberships (`projectMemberships`), with its section in that project as its state, as the per-project fallback\n\t * would list it.\n\t */\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\tconst projects = requests.map(request => request.project).filter(isAsanaProjectDescriptor);\n\t\tif (projects.length !== requests.length) return undefined;\n\n\t\t// Every request of a search shares the workspace and every option read here (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tconst drain = await this.drainTasks(\n\t\t\tsession,\n\t\t\t{ workspaceId: projects[0].resourceId },\n\t\t\toptions,\n\t\t\t// Never published: an incomplete search is read again project by project, which records its own failures.\n\t\t\t{ providerId: this.id, resourceId: projects[0].resourceId },\n\t\t);\n\t\t// An incomplete search says nothing about which of its projects it covered, so only the per-project reads can\n\t\t// report each one's completeness.\n\t\tif (drain.truncated || (drain.metadata != null && drain.metadata.completeness !== 'complete')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst indexById = new Map(projects.map((project, index) => [project.id, index]));\n\t\tconst split = projects.map((): IssueShape[] => []);\n\t\tfor (const task of drain.values) {\n\t\t\tconst shape = toIssueShape(task, this, { projection: 'project' });\n\t\t\tif (shape == null) continue;\n\n\t\t\t// Only the section differs between a task's projects: whether it is closed is the task's own.\n\t\t\tfor (const { index, state } of toRequestedProjectPlacements(task, indexById)) {\n\t\t\t\tsplit[index].push({\n\t\t\t\t\t...shape,\n\t\t\t\t\tproject: toIssueProject(projects[index]),\n\t\t\t\t\tproviderState: toIssueProviderState(state),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn split;\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * The tasks assigned to the viewer, one drain per workspace (Asana requires the workspace alongside the\n\t * assignee). Reads every workspace the user belongs to unless `resources` names some. A workspace that can't be\n\t * read is recorded in the metadata and the others are still returned; only when none could be read does the read\n\t * throw. Cancellation stops between workspaces and is not reported as truncation: the caller asked for the read to\n\t * stop.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst workspaces = (resources ?? (await this.getProviderResourcesForUser(session)) ?? []).filter(\n\t\t\tisIssueResourceDescriptor,\n\t\t);\n\n\t\tconst values: IssueShape[] = [];\n\t\tlet truncated = false;\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tlet firstError: Error | undefined;\n\t\tlet workspacesRead = 0;\n\t\tfor (const workspace of workspaces) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tlet drain: Awaited<ReturnType<AsanaIntegration['drainTasks']>>;\n\t\t\ttry {\n\t\t\t\tdrain = await this.drainTasks(session, { workspaceId: workspace.id }, options, scope);\n\t\t\t} catch (ex) {\n\t\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t\tthrowIfCallerContractError(ex);\n\n\t\t\t\tfirstError ??= toError(ex);\n\t\t\t\ttruncated = true;\n\t\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(scope, ex)],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tworkspacesRead++;\n\t\t\ttruncated ||= drain.truncated;\n\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, drain.metadata);\n\t\t\tfor (const issue of drain.values) {\n\t\t\t\tconst shape = toIssueShape(issue, this, { projection: 'account' });\n\t\t\t\tif (shape != null) {\n\t\t\t\t\tvalues.push({ ...shape, project: toAsanaIssueProject(issue, workspace) });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Every workspace failed: an empty \"my issues\" would read as \"nothing assigned to me\".\n\t\tif (workspacesRead === 0 && firstError != null) throw firstError;\n\n\t\treturn { values: values, truncated: truncated, metadata: collectionMetadata };\n\t}\n\n\t/**\n\t * Follows a task read's cursor up to {@link maxTaskPages}. `truncated` is set when the backstop stopped it with\n\t * pages left, or when a page after the first failed (recorded under `scope`, keeping the prefix). A failure on the\n\t * first page throws, so the caller sees an error rather than an empty success.\n\t */\n\tprivate async drainTasks(\n\t\tsession: ProviderAuthenticationSession,\n\t\tread: { projectId: string } | { workspaceId: string },\n\t\toptions: Pick<IssuesForProjectOptions, 'state' | 'sort'> | undefined,\n\t\tscope: CollectionScopeFailure['scope'],\n\t): Promise<{ values: ProviderIssue[]; truncated: boolean; metadata?: CollectionMetadata }> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tlet pagesRead = 0;\n\t\tlet firstPageError: Error | undefined;\n\t\tconst drain = await collectProviderPagedResult(\n\t\t\tasync cursor => {\n\t\t\t\tconst pageOptions = { cursor: cursor, states: states, sort: options?.sort };\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await ('projectId' in read\n\t\t\t\t\t\t? api.getAsanaIssuesForProject(tokenWithInfo, read.projectId, pageOptions)\n\t\t\t\t\t\t: api.getAsanaIssuesForCurrentUser(tokenWithInfo, read.workspaceId, pageOptions));\n\t\t\t\t\tpagesRead++;\n\t\t\t\t\treturn page;\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tif (pagesRead === 0) {\n\t\t\t\t\t\tfirstPageError = toError(ex);\n\t\t\t\t\t}\n\t\t\t\t\tthrow ex;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmaxTaskPages,\n\t\t\tscope,\n\t\t);\n\t\tif (firstPageError != null) throw firstPageError;\n\n\t\treturn { values: drain.values, truncated: drain.truncated === true, metadata: drain.metadata };\n\t}\n\n\tprotected override getProviderLinkedIssueOrPullRequest(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t\t_id: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\t// Asana task references are gids in a permalink URL, never a short key a commit message would carry.\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/** `resource` is the task's workspace; `id` is the task gid, which is also what an Asana issue reports as its id. */\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tif (!isIssueResourceDescriptor(resource)) return undefined;\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getAsanaIssue(toTokenWithInfo(this.id, session), id);\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, { projection: 'point', project: toAsanaIssueProject(issue, resource) })\n\t\t\t: undefined;\n\t}\n}\n\nfunction isAsanaProjectDescriptor(project: ResourceDescriptor): project is AsanaProjectDescriptor {\n\treturn isIssueResourceDescriptor(project) && typeof project.resourceId === 'string';\n}\n\n/**\n * Each requested project a task is in, by its index in the read, with the task's state as that project would list it:\n * its section there, since the unscoped read reports the first membership's.\n */\nfunction toRequestedProjectPlacements(\n\tissue: ProviderIssue,\n\tindexById: ReadonlyMap<string, number>,\n): { index: number; state: ProviderIssue['state'] }[] {\n\tconst memberships = issue.projectMemberships;\n\tif (memberships == null) {\n\t\tconst index = issue.project?.id != null ? indexById.get(issue.project.id) : undefined;\n\t\treturn index != null ? [{ index: index, state: issue.state }] : [];\n\t}\n\n\tconst placements: { index: number; state: ProviderIssue['state'] }[] = [];\n\tfor (const membership of memberships) {\n\t\tconst index = indexById.get(membership.project.id);\n\t\tif (index == null || placements.some(p => p.index === index)) continue;\n\n\t\tplacements.push({ index: index, state: getProjectMembershipState(issue, membership) });\n\t}\n\treturn placements;\n}\n\n/**\n * Mirrors provider-apis' state for a task read scoped to the membership's project; the parity test in `asana.test.ts`\n * runs both through provider-apis' own normalization to keep them agreeing.\n */\nfunction getProjectMembershipState(issue: ProviderIssue, membership: IssueProjectMembership): ProviderIssue['state'] {\n\tif (issue.project?.id === membership.project.id) return issue.state;\n\n\tconst completed = issue.closedDate != null;\n\tif (membership.section != null) {\n\t\treturn {\n\t\t\tid: membership.section.id,\n\t\t\tname: membership.section.name,\n\t\t\tcolor: null,\n\t\t\t...(completed ? { category: 'DONE' as const } : {}),\n\t\t};\n\t}\n\treturn completed ? { name: 'Completed', color: null, category: 'DONE' } : null;\n}\n\nfunction toIssueProject(project: AsanaProjectDescriptor): IssueProject {\n\treturn { id: project.id, name: project.name, resourceId: project.resourceId, resourceName: project.resourceName };\n}\n\n/**\n * The project an issue read outside a project reports. An Asana issue entity identifier is keyed by the task's\n * workspace, which the SDK reports beside the project rather than in it, so this always names the workspace as the\n * resource. A task in no project (only in someone's My Tasks) reports the workspace as its project too, so its\n * branch associations stay round-trippable.\n */\nfunction toAsanaIssueProject(issue: ProviderIssue, workspace: IssueResourceDescriptor): IssueProject {\n\tconst resourceId = issue.workspaceId ?? workspace.id;\n\tconst resourceName = resourceId === workspace.id ? workspace.name : '';\n\treturn issue.project?.id != null\n\t\t? { id: issue.project.id, name: issue.project.name, resourceId: resourceId, resourceName: resourceName }\n\t\t: { id: resourceId, name: resourceName, resourceId: resourceId, resourceName: resourceName };\n}\n"],"mappings":";;;;;;;;;;;AAgCA,MAAM,WAAW,kBAAkB;AAEnC,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;;AAEzB,MAAM,oBAAoB;;AAE1B,MAAM,eAAe;AAQrB,IAAa,mBAAb,cAAsC,kBAAsC;CAC3E,eAAqE;CAErE,IAAa,KAAyB;EACrC,OAAO,SAAS;CACjB;CACA,IAAuB,MAAe;EACrC,OAAO;CACR;CACA,IAAa,OAAe;EAC3B,OAAO,SAAS;CACjB;CACA,IAAa,SAAiB;EAC7B,OAAO,SAAS;CACjB;;;;;CAMA,MAAyB,0BACxB,SAC+B;EAC/B,MAAM,UAAU,MAAM,KAAK,aAAa,OAAO;EAC/C,IAAI,WAAW,MACd,KAAK,gBAAgB,IAAI,QAAQ,aAAa,QAAQ,QAAQ,OAAO,CAAC;EAEvE,OAAO;CACR;CAEA,sCACC,SACA,WAC+B;EAC/B,OAAO,KAAK,aAAa,OAAO;CACjC;CAEA,8BACC,SACA,WAC+B;EAC/B,OAAO,KAAK,gBAAgB,YAAY,QAAQ,mBAAmB,KAAK,aAAa,OAAO,GAAG,EAC9F,YAAW,YAAW,WAAW,KAClC,CAAC;CACF;CAEA,uBAAgD;EAC/C,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Y,MAAM;EAA0B;EAA0B;CAAa;AAC7F"}
@@ -2,11 +2,13 @@ import { Emitter } from "../../../utils/event.js";
2
2
  import { RepositoryDescriptor } from "../../../git/models/resourceDescriptor.js";
3
3
  import { IssueOrPullRequest, IssueOrPullRequestState } from "../../../git/models/issueOrPullRequest.js";
4
4
  import { Issue, IssueSearchCriteria, IssueShape } from "../../../git/models/issue.js";
5
- import { PullRequest, PullRequestFilter, PullRequestMergeMethod, PullRequestMergeQueueActionResult, PullRequestMergeQueueEntry, PullRequestSearchCriteria, PullRequestShape, PullRequestStackInfo, PullRequestStackLayers, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
5
+ import { PullRequest, PullRequestCheckLog, PullRequestFilter, PullRequestMergeMethod, PullRequestMergeQueueActionResult, PullRequestMergeQueueEntry, PullRequestSearchCriteria, PullRequestShape, PullRequestStackInfo, PullRequestStackLayers, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
6
6
  import { Account, UnidentifiedAuthor } from "../../../git/models/author.js";
7
7
  import { DefaultBranch } from "../../../git/models/defaultBranch.js";
8
+ import { PullRequestActivityPage } from "../../../git/models/pullRequestActivity.js";
8
9
  import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
9
10
  import { PullRequestUrlIdentity } from "../../../git/utils/pullRequest.utils.js";
11
+ import { GitHubIssueDelete, GitHubIssueWrite, IssueWriteResult } from "../../git-github/api/issueWrites.js";
10
12
  import { ProviderAuthenticationSession } from "../authentication/models.js";
11
13
  import { GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId } from "../constants.js";
12
14
  import { ProviderOrganization, ProviderWarningCause } from "../results.js";
@@ -15,13 +17,13 @@ import { ProviderPullRequestCount, ProviderPullRequestSearchPage } from "../mode
15
17
  import { ProviderApiPagedResult, ProviderHierarchyResult, ProviderRepoInput, ProviderRepository } from "./models.js";
16
18
  import { ProvidersApi } from "./providersApi.js";
17
19
  import { ProviderIssueSearchPage, SearchMyIssuesOptions } from "../models/issueReads.js";
18
- import { GitHostIntegration, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/gitHostIntegration.js";
20
+ import { GitHostIntegration, PullRequestActivityCoordinate, PullRequestCheckLogCoordinate, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/gitHostIntegration.js";
19
21
  import { IssueEtagFields, IssueEtagInclude, PullRequestEtagFields, PullRequestEtagInclude } from "../models/integration.js";
22
+ import { GitHubIntegrationIds } from "./github/github.utils.js";
20
23
  import { IntegrationConnectionChangeEvent } from "../integrationService.js";
21
24
  import { IntegrationAuthenticationService } from "../authentication/integrationAuthenticationService.js";
22
25
  import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
23
26
  import { IntegrationServiceContext } from "../context.js";
24
- import { GitHubIntegrationIds } from "./github/github.utils.js";
25
27
  //#region ../plus/integrations/src/providers/github.d.ts
26
28
  export type GitHubRepositoryDescriptor = RepositoryDescriptor;
27
29
  declare abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> extends GitHostIntegration<ID, GitHubRepositoryDescriptor> {
@@ -168,6 +170,8 @@ declare abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> ex
168
170
  username?: string;
169
171
  };
170
172
  mergeQueue?: boolean;
173
+ checkRuns?: boolean;
174
+ checkRunsRequired?: boolean;
171
175
  } | undefined, cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined>;
172
176
  /**
173
177
  * The cheap check behind the batch issue read's etags: {@link getProviderIssuesBatch}'s chunks and failure
@@ -182,6 +186,12 @@ declare abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> ex
182
186
  }[], options: {
183
187
  etagIncludes?: readonly IssueEtagInclude[];
184
188
  }, cancellation?: AbortSignal): Promise<PromiseSettledResult<IssueEtagFields | undefined>[] | undefined>;
189
+ protected getProviderPullRequestCheckLogs(session: ProviderAuthenticationSession, targets: readonly PullRequestCheckLogCoordinate[], options: {
190
+ tailLines: number;
191
+ }, cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestCheckLog>[] | undefined>;
192
+ protected getProviderPullRequestActivity(session: ProviderAuthenticationSession, targets: readonly PullRequestActivityCoordinate[], options: {
193
+ limit: number;
194
+ }, cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestActivityPage | undefined>[] | undefined>;
185
195
  /**
186
196
  * The cheap check behind the batch pull request read's etags: {@link getProviderPullRequestsBatch}'s chunks and
187
197
  * failure isolation over {@link GitHubApi.getPullRequestsEtagFieldsBatch}, which selects only a pull request's
@@ -195,6 +205,7 @@ declare abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> ex
195
205
  }[], options: {
196
206
  etagIncludes?: readonly PullRequestEtagInclude[];
197
207
  mergeQueue?: boolean;
208
+ checkRuns?: boolean;
198
209
  }, cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestEtagFields | undefined>[] | undefined>;
199
210
  /**
200
211
  * Finds each branch's pull requests by aliasing a head-ref-name query per distinct repository and branch — see
@@ -226,6 +237,7 @@ declare abstract class GitHubIntegrationBase<ID extends GitHubIntegrationIds> ex
226
237
  };
227
238
  limit: number;
228
239
  mergeQueue?: boolean;
240
+ checkRuns?: boolean;
229
241
  }, cancellation?: AbortSignal): Promise<PromiseSettledResult<{
230
242
  pullRequests: PullRequestShape[];
231
243
  truncated: boolean;
@@ -292,6 +304,9 @@ export declare class GitHubIntegration extends GitHubIntegrationBase<GitCloudHos
292
304
  protected readonly key = GitCloudHostIntegrationId.GitHub;
293
305
  readonly name: string;
294
306
  get domain(): string;
307
+ mutateIssue(connectionId: string, input: GitHubIssueWrite | (GitHubIssueDelete & {
308
+ action: 'delete';
309
+ })): Promise<IssueWriteResult>;
295
310
  protected apiBaseUrlFor(_session: ProviderAuthenticationSession): string | undefined;
296
311
  access(): Promise<boolean>;
297
312
  refresh(): Promise<void>;
@@ -3,7 +3,7 @@ import { batch, mapBounded, mapSettledBounded } from "../../../utils/promise.js"
3
3
  import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
4
4
  import { getGitHubNoReplyAddressParts } from "../../../git/remotes/github.js";
5
5
  import "../../../git/models/pullRequest.js";
6
- import { fromGitHubIssueOrPullRequestState, fromGitHubMergeQueueEntryState, fromGitHubMergeQueueRemoval, fromGitHubPullRequestMergeableState, fromGitHubPullRequestReviewDecision, fromGitHubPullRequestStatusCheckRollupState } from "../../git-github/models.js";
6
+ import { decodeGitHubCheckRunId, fromGitHubCheckContextState, fromGitHubIssueOrPullRequestState, fromGitHubMergeQueueEntryState, fromGitHubMergeQueueRemoval, fromGitHubPullRequestMergeableState, fromGitHubPullRequestReviewDecision, fromGitHubPullRequestStatusCheckRollupState, toGitHubCheckRunId } from "../../git-github/models.js";
7
7
  import { IntegrationReadUnavailableError } from "../errors.js";
8
8
  import "../constants.js";
9
9
  import { toCollectionScopeFailure } from "../collectionMetadata.js";
@@ -11,6 +11,10 @@ import "../providerFilters.js";
11
11
  import { resolveBranchPullRequests } from "./utils/providerPaging.js";
12
12
  import { getProviderPullRequestIdentity, providersMetadata, stampNativePullRequest } from "./models.js";
13
13
  import { toTokenWithInfo } from "../authentication/models.js";
14
+ import { pullRequestCheckRunsEtag } from "../models/integration.js";
15
+ import "../../git-github/api/aliasedQuery.js";
16
+ import { isValidGitHubIssueMutation, issueWriteFailure } from "../../git-github/api/issueWrites.js";
17
+ import { decodePullRequestActivityCursor } from "../../git-github/api/pullRequestActivity.js";
14
18
  import { gitHubPullRequestRelationshipQualifiers } from "../../git-github/api/pullRequestSearchQuery.js";
15
19
  import { GitHostIntegration } from "../models/gitHostIntegration.js";
16
20
  import { getGitHubPullRequestIdentityFromMaybeUrl } from "./github/github.utils.js";
@@ -110,6 +114,13 @@ function toPullRequestEtagFields(node, etagIncludes) {
110
114
  if (etagIncludes.includes("mergeable")) fields.mergeableState = node.mergeable != null ? fromGitHubPullRequestMergeableState(node.mergeable) : void 0;
111
115
  if (etagIncludes.includes("reviewDecision")) fields.reviewDecision = node.reviewDecision != null ? fromGitHubPullRequestReviewDecision(node.reviewDecision) : void 0;
112
116
  if (etagIncludes.includes("checks")) fields.statusCheckRollupState = fromGitHubPullRequestStatusCheckRollupState(node.commits?.nodes?.[0]?.commit.statusCheckRollup?.state);
117
+ if (node.checkRuns != null) fields.checkRuns = pullRequestCheckRunsEtag(node.checkRuns.contexts.flatMap((context) => {
118
+ const state = fromGitHubCheckContextState(context);
119
+ return state != null && context != null ? [{
120
+ ...state,
121
+ id: toGitHubCheckRunId(context)
122
+ }] : [];
123
+ }), node.checkRuns.truncated);
113
124
  return fields;
114
125
  }
115
126
  /** A cheap etag read's issue, as the fields its full row's etag reads, through `fromGitHubIssue`'s own conversions. */
@@ -468,13 +479,17 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
468
479
  if (github == null) return void 0;
469
480
  const currentAccount = options?.currentAccount;
470
481
  const mergeQueue = options?.mergeQueue;
482
+ const checkRuns = options?.checkRuns;
483
+ const checkRunsRequired = options?.checkRunsRequired;
471
484
  return readChunked(coordinates, pullRequestsBatchChunkSize, (chunkCoordinates) => github.getPullRequestsBatch(this, toTokenWithInfo(this.id, session), chunkCoordinates.map((c) => ({
472
485
  owner: c.owner,
473
486
  repo: c.repo,
474
487
  number: c.number
475
488
  })), {
476
489
  baseUrl: this.apiBaseUrlFor(session),
477
- mergeQueue
490
+ mergeQueue,
491
+ checkRuns,
492
+ checkRunsRequired
478
493
  }, cancellation), (pr) => pr != null ? stampNativePullRequest(pr, {
479
494
  currentAccount,
480
495
  projection: "batch"
@@ -498,6 +513,47 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
498
513
  etagIncludes
499
514
  }, cancellation), (node) => node != null ? toIssueEtagFields(node, etagIncludes) : void 0);
500
515
  }
516
+ async getProviderPullRequestCheckLogs(session, targets, options, cancellation) {
517
+ const decoded = [];
518
+ for (const target of targets) {
519
+ const ref = decodeGitHubCheckRunId(target.checkRunId);
520
+ if (ref == null) throw new IntegrationReadUnavailableError(this.name, `check run id '${target.checkRunId}' is not one a pull request read returned.`);
521
+ decoded.push({
522
+ owner: target.owner,
523
+ repo: target.repo,
524
+ ref
525
+ });
526
+ }
527
+ const github = await this.authenticationService.apis.github;
528
+ if (github == null) return void 0;
529
+ const token = toTokenWithInfo(this.id, session);
530
+ const read = {
531
+ baseUrl: this.apiBaseUrlFor(session),
532
+ tailLines: options.tailLines
533
+ };
534
+ return readChunked(decoded, 25, (chunkTargets) => github.getCheckRunLogs(this, token, chunkTargets, read, cancellation), (log) => log);
535
+ }
536
+ async getProviderPullRequestActivity(session, targets, options, cancellation) {
537
+ const decoded = [];
538
+ for (const target of targets) {
539
+ const cursor = target.cursor != null ? decodePullRequestActivityCursor(target.cursor) : void 0;
540
+ if (target.cursor != null && cursor == null) throw new IntegrationReadUnavailableError(this.name, `cursor '${target.cursor}' is not one a pull request activity read returned.`);
541
+ decoded.push({
542
+ owner: target.owner,
543
+ repo: target.repo,
544
+ number: target.number,
545
+ cursor
546
+ });
547
+ }
548
+ const github = await this.authenticationService.apis.github;
549
+ if (github == null) return void 0;
550
+ const token = toTokenWithInfo(this.id, session);
551
+ const read = {
552
+ baseUrl: this.apiBaseUrlFor(session),
553
+ limit: options.limit
554
+ };
555
+ return readChunked(decoded, 25, (chunkTargets) => github.getPullRequestActivity(this, token, chunkTargets, read, cancellation), (page) => page);
556
+ }
501
557
  /**
502
558
  * The cheap check behind the batch pull request read's etags: {@link getProviderPullRequestsBatch}'s chunks and
503
559
  * failure isolation over {@link GitHubApi.getPullRequestsEtagFieldsBatch}, which selects only a pull request's
@@ -508,6 +564,7 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
508
564
  if (github == null) return void 0;
509
565
  const etagIncludes = options.etagIncludes ?? [];
510
566
  const mergeQueue = options.mergeQueue;
567
+ const checkRuns = options.checkRuns === true;
511
568
  return readChunked(coordinates, pullRequestsBatchChunkSize, (chunkCoordinates) => github.getPullRequestsEtagFieldsBatch(this, toTokenWithInfo(this.id, session), chunkCoordinates.map((c) => ({
512
569
  owner: c.owner,
513
570
  repo: c.repo,
@@ -515,7 +572,8 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
515
572
  })), {
516
573
  baseUrl: this.apiBaseUrlFor(session),
517
574
  etagIncludes,
518
- mergeQueue
575
+ mergeQueue,
576
+ checkRuns
519
577
  }, cancellation), (node) => node != null ? toPullRequestEtagFields(node, etagIncludes) : void 0);
520
578
  }
521
579
  /**
@@ -562,7 +620,8 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
562
620
  })), {
563
621
  baseUrl,
564
622
  limit: options.limit,
565
- mergeQueue: options.mergeQueue
623
+ mergeQueue: options.mergeQueue,
624
+ checkRuns: options.checkRuns
566
625
  }, cancellation), (found) => ({
567
626
  pullRequests: found.pullRequests.map((prs) => prs.map((pr) => stampNativePullRequest(pr, {
568
627
  currentAccount,
@@ -603,7 +662,9 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
603
662
  });
604
663
  const extras = await resolveBranchPullRequests(ambiguous.map((a) => targets[a.index]), heads, (coordinates) => this.getProviderPullRequestsBatch(session, coordinates, {
605
664
  currentAccount,
606
- mergeQueue: options.mergeQueue
665
+ mergeQueue: options.mergeQueue,
666
+ checkRuns: options.checkRuns,
667
+ checkRunsRequired: false
607
668
  }, cancellation));
608
669
  const settled = [...slots];
609
670
  ambiguous.forEach((a, i) => {
@@ -793,6 +854,30 @@ var GitHubIntegration = class extends GitHubIntegrationBase {
793
854
  get domain() {
794
855
  return metadata.domain;
795
856
  }
857
+ async mutateIssue(connectionId, input) {
858
+ if (!isValidGitHubIssueMutation(input)) return {
859
+ ok: false,
860
+ reason: "invalid-input"
861
+ };
862
+ try {
863
+ const session = await this.resolveReadSessionOrThrow(connectionId, void 0);
864
+ if (session?.id !== connectionId || !session.accessToken) return {
865
+ ok: false,
866
+ reason: "no-connection"
867
+ };
868
+ const api = await this.authenticationService.apis.github;
869
+ if (api == null) return {
870
+ ok: false,
871
+ reason: "unsupported"
872
+ };
873
+ const result = await api.mutateIssue(this, toTokenWithInfo(this.id, session), input);
874
+ if (result.ok) this.resetRequestExceptionCount("mutateIssue", connectionId);
875
+ else if (result.reason === "no-connection") this.handleConnectionAuthenticationRejection(connectionId, true);
876
+ return result;
877
+ } catch (ex) {
878
+ return issueWriteFailure(ex);
879
+ }
880
+ }
796
881
  apiBaseUrlFor(_session) {}
797
882
  access() {
798
883
  return Promise.resolve(true);