@leitwerk-dev/github 0.0.0-bootstrap.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -1
- package/dist/LICENSE +13 -0
- package/dist/authorization.d.ts +12 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/binding.d.ts +4 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/capability.d.ts +8 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/chunk-PVE52UFH.js +318 -0
- package/dist/chunk-PVE52UFH.js.map +1 -0
- package/dist/client.d.ts +111 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/external.d.ts +85 -0
- package/dist/external.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +809 -0
- package/dist/index.js.map +1 -0
- package/dist/issue-provider.d.ts +8 -0
- package/dist/issue-provider.d.ts.map +1 -0
- package/dist/issue-watcher.d.ts +19 -0
- package/dist/issue-watcher.d.ts.map +1 -0
- package/dist/poll-report.d.ts +22 -0
- package/dist/poll-report.d.ts.map +1 -0
- package/dist/provider.d.ts +6 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/testing.d.ts +81 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +297 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools.d.ts +5 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +55 -14
- package/src/authorization.ts +54 -0
- package/src/binding.ts +6 -0
- package/src/capability.ts +13 -0
- package/src/client.ts +421 -0
- package/src/external.ts +139 -0
- package/src/index.ts +45 -0
- package/src/issue-provider.ts +278 -0
- package/src/issue-watcher.ts +30 -0
- package/src/poll-report.ts +47 -0
- package/src/provider.ts +216 -0
- package/src/testing.ts +384 -0
- package/src/tools.ts +304 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/capability.ts","../src/provider.ts","../src/external.ts","../src/issue-provider.ts","../src/issue-watcher.ts","../src/poll-report.ts","../src/tools.ts","../src/binding.ts"],"sourcesContent":["import type { ExternalWriteLogRepoLike } from \"@leitwerk-dev/external-writes\";\nimport { coreHostCapabilities, type LeitwerkExtensionModule } from \"@leitwerk-dev/process-sdk\";\nimport { type GitHubIntegration, githubIntegration } from \"./capability.js\";\nimport { GitHubClient, parseGitHubProfiles } from \"./client.js\";\nimport { createGitHubProvider } from \"./provider.js\";\nimport { registerGitHubTools } from \"./tools.js\";\n\nexport const manifest = { id: \"github\", version: \"0.1.9\" } as const;\n\nconst extension: LeitwerkExtensionModule = {\n\tmanifest,\n\tsetupServer(api, config) {\n\t\tconst profiles = parseGitHubProfiles(config);\n\t\tconst integration: GitHubIntegration = {\n\t\t\tclient(profile) {\n\t\t\t\tconst value = profiles.get(profile);\n\t\t\t\tif (!value) throw new Error(`Unknown GitHub profile '${profile}'`);\n\t\t\t\treturn new GitHubClient(value);\n\t\t\t},\n\t\t};\n\t\tsetupGitHubIntegration(api, integration);\n\t},\n};\n\nexport * from \"./capability.js\";\nexport * from \"./client.js\";\nexport * from \"./external.js\";\nexport default extension;\n\n/** Register shared tools and polling with an explicit integration. */\nexport function setupGitHubIntegration(\n\tapi: Parameters<NonNullable<LeitwerkExtensionModule[\"setupServer\"]>>[0],\n\tintegration: GitHubIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tapi.provide(githubIntegration, integration);\n\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\tif (!deps || Array.isArray(deps)) return;\n\tregisterGitHubTools(api, integration, deps.externalWrites as ExternalWriteLogRepoLike);\n\treturn createGitHubProvider(deps, integration, options);\n}\n\nexport * from \"./binding.js\";\n\nexport * from \"./issue-watcher.js\";\n","import { createCapabilityToken } from \"@leitwerk-dev/process-sdk\";\nimport type { GitHubClient } from \"./client.js\";\n\n/** Public contract shared by HTTP and local adapters. */\nexport type GitHubClientLike = Pick<GitHubClient, keyof GitHubClient>;\n\nexport interface GitHubIntegration {\n\tclient(profile: string): GitHubClientLike;\n}\n\nexport const githubIntegration = createCapabilityToken<GitHubIntegration>(\n\t\"@leitwerk-private/github.integration\",\n);\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\nimport type { CoreServerSetupDeps } from \"@leitwerk-dev/process-sdk\";\nimport { conflictEvidence, createConflictReporter } from \"@leitwerk-dev/repository-rebase\";\nimport { createPollSchedule, emptyPollResult } from \"@leitwerk-dev/watcher-utils\";\nimport type { GitHubIntegration } from \"./capability.js\";\nimport {\n\tdescribeGitHubEvent,\n\tGITHUB_PR_STATE_KIND,\n\tGITHUB_RELEASE_KIND,\n\ttype GitHubPullRequestSourceConfig,\n} from \"./external.js\";\nimport { createGitHubIssuePolling } from \"./issue-provider.js\";\nimport { githubPollReporter } from \"./poll-report.js\";\n\nfunction parse(value: unknown): GitHubPullRequestSourceConfig | null {\n\tconst config = asUnknownRecord(value) ?? {};\n\tif (\n\t\t[\"profile\", \"owner\", \"repo\", \"headSha\"].some(\n\t\t\t(key) => typeof config[key] !== \"string\" || !(config[key] as string).trim(),\n\t\t) ||\n\t\ttypeof config.prNumber !== \"number\"\n\t)\n\t\treturn null;\n\treturn {\n\t\tprofile: config.profile as string,\n\t\towner: config.owner as string,\n\t\trepo: config.repo as string,\n\t\tprNumber: config.prNumber,\n\t\theadSha: config.headSha as string,\n\t\tlastConflictKey: typeof config.lastConflictKey === \"string\" ? config.lastConflictKey : null,\n\t\tfeedbackCursor: typeof config.feedbackCursor === \"number\" ? config.feedbackCursor : 0,\n\t\tpollInterval: typeof config.pollInterval === \"string\" ? config.pollInterval : \"30s\",\n\t\tdisabled: config.disabled === true,\n\t\teventKinds: Array.isArray(config.eventKinds)\n\t\t\t? config.eventKinds.filter(\n\t\t\t\t\t(value): value is \"checks\" | \"feedback\" | \"merged\" | \"closed\" | \"merge_conflict\" =>\n\t\t\t\t\t\t[\"checks\", \"feedback\", \"merged\", \"closed\", \"merge_conflict\"].includes(String(value)),\n\t\t\t\t)\n\t\t\t: undefined,\n\t\tcheckStatuses: Array.isArray(config.checkStatuses)\n\t\t\t? config.checkStatuses.filter((value): value is \"pending\" | \"success\" | \"failure\" =>\n\t\t\t\t\t[\"pending\", \"success\", \"failure\"].includes(String(value)),\n\t\t\t\t)\n\t\t\t: undefined,\n\t};\n}\n\nexport function createGitHubProvider(\n\tdeps: CoreServerSetupDeps,\n\tintegration: GitHubIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tconst due = createPollSchedule();\n\tconst pollIssues = createGitHubIssuePolling(deps, integration, options);\n\tconst reportConflict = createConflictReporter(deps.externalSources, GITHUB_PR_STATE_KIND);\n\treturn deps.polling.create({\n\t\tid: \"github\",\n\t\tpollInterval: () => \"5s\",\n\t\tisEnabled: () => true,\n\t\tdefaultIntervalMs: 5_000,\n\t\tasync pollOnce() {\n\t\t\tconst result = emptyPollResult();\n\t\t\tconst report = githubPollReporter(deps.externalSources, result);\n\t\t\tawait pollIssues(result);\n\t\t\tawait report.poll(GITHUB_PR_STATE_KIND, async (armed) => {\n\t\t\t\tconst config = parse(armed.resolved);\n\t\t\t\tif (!config) {\n\t\t\t\t\tresult.errors.push(`${armed.id}:invalid_config`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (config.disabled) return;\n\t\t\t\tconst key = `${armed.instanceId}:${armed.id}:${armed.generation ?? \"\"}`;\n\t\t\t\tconst now = options.now?.() ?? Date.now();\n\t\t\t\tif (!due(key, config.pollInterval, now)) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst client = integration.client(config.profile);\n\t\t\t\t\tconst pr = await client.getPullRequest(config.owner, config.repo, config.prNumber);\n\t\t\t\t\tif (!config.eventKinds || config.eventKinds.includes(\"merge_conflict\")) {\n\t\t\t\t\t\tconst conflict = conflictEvidence(config, pr, \"github\");\n\t\t\t\t\t\t// GitHub's PR base SHA can lag the branch even while its state is behind.\n\t\t\t\t\t\tif (conflict?.reason === \"behind\") {\n\t\t\t\t\t\t\tconst branch = await client.getCommit(config.owner, config.repo, conflict.baseBranch);\n\t\t\t\t\t\t\tconflict.baseSha = branch.sha;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tawait reportConflict(report, armed, conflict, config.lastConflictKey, {\n\t\t\t\t\t\t\t\tsummary: `PR #${pr.number} mergeability: ${pr.mergeable == null ? \"unresolved\" : (pr.mergeable_state ?? String(pr.mergeable))}`,\n\t\t\t\t\t\t\t\tobservedAt: new Date(now).toISOString(),\n\t\t\t\t\t\t\t\tsubject: `${config.owner}/${config.repo}#${pr.number}`,\n\t\t\t\t\t\t\t\trevision: `${pr.head.sha}:${conflict?.baseSha ?? pr.base.sha}`,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tif (config.eventKinds?.length === 1) return;\n\t\t\t\t\t}\n\t\t\t\t\tlet event: Record<string, unknown> | null = null;\n\t\t\t\t\tlet mergeKey = \"\";\n\t\t\t\t\tif (pr.merged || pr.state === \"closed\") {\n\t\t\t\t\t\tevent = {\n\t\t\t\t\t\t\tkind: pr.merged ? \"merged\" : \"closed\",\n\t\t\t\t\t\t\tpullRequest: pr,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tmergeKey = `terminal:${pr.number}:${pr.merged}`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (pr.head.sha !== config.headSha) return;\n\t\t\t\t\t\tconst readsFeedback = !config.eventKinds || config.eventKinds.includes(\"feedback\");\n\t\t\t\t\t\tconst readsChecks = !config.eventKinds || config.eventKinds.includes(\"checks\");\n\t\t\t\t\t\tconst [feedback, checks] = await Promise.all([\n\t\t\t\t\t\t\treadsFeedback\n\t\t\t\t\t\t\t\t? client.listActionablePullRequestFeedback(\n\t\t\t\t\t\t\t\t\t\tconfig.owner,\n\t\t\t\t\t\t\t\t\t\tconfig.repo,\n\t\t\t\t\t\t\t\t\t\tconfig.prNumber,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: Promise.resolve([]),\n\t\t\t\t\t\t\treadsChecks || (deps.externalSources.observe && armed.generation)\n\t\t\t\t\t\t\t\t? client\n\t\t\t\t\t\t\t\t\t\t.getCheckSummary(config.owner, config.repo, config.headSha)\n\t\t\t\t\t\t\t\t\t\t.catch(async (error) => {\n\t\t\t\t\t\t\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\t\t\t\t\t\t\trefreshError:\n\t\t\t\t\t\t\t\t\t\t\t\t\terror instanceof Error ? error.message : \"Checks refresh failed\",\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\tif (readsChecks) throw error;\n\t\t\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t: Promise.resolve(null),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\tif (checks && checks.headSha !== config.headSha) return;\n\t\t\t\t\t\tconst refreshed = await client.getPullRequest(\n\t\t\t\t\t\t\tconfig.owner,\n\t\t\t\t\t\t\tconfig.repo,\n\t\t\t\t\t\t\tconfig.prNumber,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\trefreshed.state !== \"open\" ||\n\t\t\t\t\t\t\trefreshed.merged ||\n\t\t\t\t\t\t\trefreshed.head.sha !== config.headSha\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tif (checks && deps.externalSources.observe && armed.generation) {\n\t\t\t\t\t\t\tconst description = describeGitHubEvent({ kind: \"checks\", checks });\n\t\t\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\t\t\tobservation: {\n\t\t\t\t\t\t\t\t\t...description,\n\t\t\t\t\t\t\t\t\tobservedAt: new Date(now).toISOString(),\n\t\t\t\t\t\t\t\t\tsubject: `${config.owner}/${config.repo}#${config.prNumber}`,\n\t\t\t\t\t\t\t\t\trevision: checks.headSha,\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\tconst unseen = feedback.filter(\n\t\t\t\t\t\t\t(item) => item.id > config.feedbackCursor && item.author !== client.profile.botLogin,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (unseen.length) {\n\t\t\t\t\t\t\tconst feedbackCursor = Math.max(...unseen.map((item) => item.id));\n\t\t\t\t\t\t\tevent = { kind: \"feedback\", feedback, feedbackCursor };\n\t\t\t\t\t\t\tmergeKey = `feedback:${feedbackCursor}`;\n\t\t\t\t\t\t} else if (readsChecks && checks && checks.status !== \"pending\") {\n\t\t\t\t\t\t\tevent = { kind: \"checks\", checks };\n\t\t\t\t\t\t\tmergeKey = `checks:${checks.headSha}:${checks.status}`;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t!event ||\n\t\t\t\t\t\t(config.eventKinds &&\n\t\t\t\t\t\t\t!config.eventKinds.includes(\n\t\t\t\t\t\t\t\tString(event.kind) as (typeof config.eventKinds)[number],\n\t\t\t\t\t\t\t)) ||\n\t\t\t\t\t\t(event.kind === \"checks\" &&\n\t\t\t\t\t\t\tconfig.checkStatuses &&\n\t\t\t\t\t\t\t!config.checkStatuses.includes(\n\t\t\t\t\t\t\t\t(event.checks as { status: \"pending\" | \"success\" | \"failure\" }).status,\n\t\t\t\t\t\t\t))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn;\n\t\t\t\t\tawait report.fire(armed, event, mergeKey);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\trefreshError: error instanceof Error ? error.message : \"PR refresh failed\",\n\t\t\t\t\t});\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t});\n\t\t\tawait report.poll(GITHUB_RELEASE_KIND, async (armed) => {\n\t\t\t\tconst config = asUnknownRecord(armed.resolved) ?? {};\n\t\t\t\tif (\n\t\t\t\t\ttypeof config.profile !== \"string\" ||\n\t\t\t\t\ttypeof config.owner !== \"string\" ||\n\t\t\t\t\ttypeof config.repo !== \"string\" ||\n\t\t\t\t\ttypeof config.mergeSha !== \"string\"\n\t\t\t\t)\n\t\t\t\t\treturn;\n\t\t\t\tif (config.disabled === true) return;\n\t\t\t\tconst key = `${armed.instanceId}:${armed.id}:${armed.generation ?? \"\"}`;\n\t\t\t\tconst now = options.now?.() ?? Date.now();\n\t\t\t\tif (!due(key, typeof config.pollInterval === \"string\" ? config.pollInterval : \"30s\", now))\n\t\t\t\t\treturn;\n\t\t\t\tconst client = integration.client(config.profile);\n\t\t\t\tfor (const release of await client.listReleases(config.owner, config.repo)) {\n\t\t\t\t\tif (release.draft || release.prerelease) continue;\n\t\t\t\t\tconst commit = await client.getCommit(config.owner, config.repo, release.tag_name);\n\t\t\t\t\tif (!(await client.isAncestor(config.owner, config.repo, config.mergeSha, commit.sha)))\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tawait report.fire(\n\t\t\t\t\t\tarmed,\n\t\t\t\t\t\t{ release, commitSha: commit.sha },\n\t\t\t\t\t\t`${release.id}:${commit.sha}`,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn result;\n\t\t},\n\t});\n}\n","import {\n\tdefineExternalActionSource,\n\ttype ExternalEventDescription,\n} from \"@leitwerk-dev/process-sdk\";\nimport { describeConflict } from \"@leitwerk-dev/repository-rebase\";\n\nexport const GITHUB_PR_STATE_KIND = \"@leitwerk-private/github.pr_state\";\n\nexport interface GitHubPullRequestSourceConfig {\n\tprofile: string;\n\towner: string;\n\trepo: string;\n\tprNumber: number;\n\theadSha: string;\n\tfeedbackCursor: number;\n\tlastConflictKey?: string | null;\n\tpollInterval?: string;\n\tdisabled?: boolean;\n\teventKinds?: Array<\"checks\" | \"feedback\" | \"merged\" | \"closed\" | \"merge_conflict\">;\n\tcheckStatuses?: Array<\"pending\" | \"success\" | \"failure\">;\n}\n\nexport const GITHUB_RELEASE_KIND = \"@leitwerk-private/github.release\";\n\nexport interface GitHubReleaseSourceConfig {\n\tprofile: string;\n\towner: string;\n\trepo: string;\n\tmergeSha: string;\n\tpollInterval?: string;\n\tdisabled?: boolean;\n}\n\nexport function describeGitHubEvent(event: unknown): ExternalEventDescription {\n\tconst value = event as {\n\t\tkind?: string;\n\t\tchecks?: {\n\t\t\theadSha: string;\n\t\t\tstatus: string;\n\t\t\tfailed: Array<{ name: string; url: string | null }>;\n\t\t};\n\t\tpullRequest?: { number: number; merged?: boolean; state?: string };\n\t};\n\tif (value.kind === \"merge_conflict\") return describeConflict(event);\n\tif (value.checks) {\n\t\tconst checks = value.checks;\n\t\treturn {\n\t\t\tsummary: `Checks ${checks.status} on ${checks.headSha}${checks.failed.length ? `: ${checks.failed.map((check) => check.name).join(\", \")}` : \"\"}`,\n\t\t\tlinks: checks.failed.flatMap((check, index) =>\n\t\t\t\tcheck.url\n\t\t\t\t\t? [{ id: `check-${index}`, label: check.name, url: check.url, kind: \"pipeline\" as const }]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t};\n\t}\n\treturn {\n\t\tsummary:\n\t\t\tvalue.kind === \"merged\" || value.kind === \"closed\" || value.pullRequest\n\t\t\t\t? `PR #${value.pullRequest?.number} ${value.kind ?? (value.pullRequest?.merged ? \"merged\" : \"closed\")}`\n\t\t\t\t: value.kind === \"feedback\"\n\t\t\t\t\t? \"Pull request feedback received\"\n\t\t\t\t\t: \"GitHub event received\",\n\t};\n}\n\nexport const GITHUB_PR_TERMINAL_KIND = \"@leitwerk-public/github.pr_terminal\";\nexport const GITHUB_PR_FEEDBACK_KIND = \"@leitwerk-public/github.pr_feedback\";\nexport const GITHUB_ISSUE_CANCELLED_KIND = \"@leitwerk-public/github.issue_cancelled\";\n\nexport interface GitHubPullRequestTerminalSourceConfig {\n\tprofile: string;\n\towner: string;\n\trepo: string;\n\tprNumber: number;\n\tpollInterval?: string;\n\tterminalOutcome?: \"merged\" | \"closed\";\n\tdisabled?: boolean;\n}\n\nexport interface GitHubFeedbackSourceConfig extends GitHubPullRequestTerminalSourceConfig {\n\tconversationCursor: number;\n\treviewCursor: number;\n\tinlineCursor: number;\n\tquietPeriodMs: number;\n}\n\nexport interface GitHubIssueCancelledSourceConfig {\n\tprofile: string;\n\towner: string;\n\trepo: string;\n\tissueNumber: number;\n\ttriggerLabel: string;\n\tpollInterval?: string;\n}\n\nexport const GITHUB_CHECKS_KIND = \"@leitwerk-public/github.checks\";\n\nexport const githubExternal = {\n\tchecks: defineExternalActionSource<{\n\t\tprofile: string;\n\t\towner: string;\n\t\trepo: string;\n\t\tprNumber: number;\n\t\theadSha: string;\n\t}>({\n\t\tkind: GITHUB_CHECKS_KIND,\n\t\tdescribeEvent: describeGitHubEvent,\n\t\tlabel: \"GitHub Actions failures\",\n\t}),\n\tissueCancelled: defineExternalActionSource<GitHubIssueCancelledSourceConfig>({\n\t\tkind: GITHUB_ISSUE_CANCELLED_KIND,\n\t\tdescribeEvent: () => ({ summary: \"Source issue cancelled\" }),\n\t\tlabel: \"GitHub source issue cancelled\",\n\t\tdescription: \"Fires when the source issue closes or loses its trigger label\",\n\t}),\n\tpullRequestTerminal: defineExternalActionSource<GitHubPullRequestTerminalSourceConfig>({\n\t\tkind: GITHUB_PR_TERMINAL_KIND,\n\t\tdescribeEvent: describeGitHubEvent,\n\t\tlabel: \"GitHub pull request merged or closed\",\n\t\tdescription: \"Fires when the tracked pull request reaches a terminal state\",\n\t}),\n\tpullRequestFeedback: defineExternalActionSource<GitHubFeedbackSourceConfig>({\n\t\tkind: GITHUB_PR_FEEDBACK_KIND,\n\t\tdescribeEvent: () => ({ summary: \"Pull request feedback received\" }),\n\t\tlabel: \"GitHub pull request feedback\",\n\t\tdescription: \"Fires after unseen human feedback has been quiet long enough to batch\",\n\t}),\n\treleaseContaining: defineExternalActionSource<GitHubReleaseSourceConfig>({\n\t\tkind: GITHUB_RELEASE_KIND,\n\t\tlabel: \"Published GitHub release\",\n\t\tdescription: \"Fires when a published release contains the tracked merge commit\",\n\t}),\n\tpullRequestState: defineExternalActionSource<GitHubPullRequestSourceConfig>({\n\t\tkind: GITHUB_PR_STATE_KIND,\n\t\tdescribeEvent: describeGitHubEvent,\n\t\tlabel: \"GitHub pull request state\",\n\t\tdescription: \"Fires for failed or successful checks, review feedback, and terminal PR state\",\n\t}),\n};\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\nimport {\n\ttype CoreServerSetupDeps,\n\ttype ExternalSourceArmingLike,\n\tmatchesRepository as matchesConfiguredRepository,\n\tparseRepositoryFeedbackConfig as parseFeedbackConfig,\n\tparseRepositoryIssueCancelledConfig as parseIssueCancelledConfig,\n\tparseRepositoryPullRequestConfig as parsePrConfig,\n\ttype RegisteredProcessWatcherLike,\n\trepositoryFeedbackBatch,\n} from \"@leitwerk-dev/process-sdk\";\nimport { sameSubscription } from \"@leitwerk-dev/repository-rebase\";\nimport { createPollSchedule, type emptyPollResult } from \"@leitwerk-dev/watcher-utils\";\nimport type { GitHubIntegration } from \"./capability.js\";\nimport type { GitHubIssue, GitHubRepository } from \"./client.js\";\nimport {\n\tdescribeGitHubEvent,\n\tGITHUB_CHECKS_KIND,\n\tGITHUB_ISSUE_CANCELLED_KIND,\n\tGITHUB_PR_FEEDBACK_KIND,\n\tGITHUB_PR_TERMINAL_KIND,\n} from \"./external.js\";\nimport {\n\ttype GitHubIssueWatcherConfig,\n\ttype GitHubIssueWatcherEvent,\n\tgithubIssueWatcherSource,\n} from \"./issue-watcher.js\";\nimport { githubPollReporter } from \"./poll-report.js\";\n\nfunction hasLabel(issue: GitHubIssue, label: string): boolean {\n\treturn issue.labels.some((candidate) => candidate.name === label);\n}\n\nfunction externalId(repo: GitHubRepository, issue: GitHubIssue): string {\n\treturn `github:${repo.full_name}#${issue.number}`;\n}\n\nexport { matchesConfiguredRepository };\n\nexport function createGitHubIssuePolling(\n\tdeps: CoreServerSetupDeps,\n\tintegration: GitHubIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tconst now = options.now ?? Date.now;\n\tconst due = createPollSchedule(now);\n\n\tasync function discover(\n\t\twatcher: RegisteredProcessWatcherLike<GitHubIssueWatcherConfig, GitHubIssueWatcherEvent>,\n\t\tresult: ReturnType<typeof emptyPollResult>,\n\t) {\n\t\tconst config = watcher.config;\n\t\tconst client = integration.client(config.profile);\n\t\tfor (const repo of await client.listRepositories()) {\n\t\t\tif (!matchesConfiguredRepository(config, repo)) continue;\n\t\t\tfor (const issue of await client.listOpenIssues(repo.owner.login, repo.name)) {\n\t\t\t\tif (!hasLabel(issue, config.labels.trigger) || hasLabel(issue, config.labels.done))\n\t\t\t\t\tcontinue;\n\t\t\t\tconst id = externalId(repo, issue);\n\t\t\t\ttry {\n\t\t\t\t\tif (deps.processes.listAll().some((process) => process.externalId === id)) {\n\t\t\t\t\t\tresult.skipped.push(id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst authorized = await client.authorizedTrigger(\n\t\t\t\t\t\trepo.owner.login,\n\t\t\t\t\t\trepo.name,\n\t\t\t\t\t\tissue.number,\n\t\t\t\t\t\tconfig.labels.trigger,\n\t\t\t\t\t\tconfig.labels.done,\n\t\t\t\t\t);\n\t\t\t\t\tif (!authorized) {\n\t\t\t\t\t\tresult.skipped.push(`${id}:unauthorized`);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst event: GitHubIssueWatcherEvent = {\n\t\t\t\t\t\tprofile: config.profile,\n\t\t\t\t\t\trepository: repo,\n\t\t\t\t\t\tissue: authorized.issue,\n\t\t\t\t\t\tauthorization: {\n\t\t\t\t\t\t\tactor: authorized.actor,\n\t\t\t\t\t\t\teventId: authorized.eventId,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlabels: config.labels,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst guardedWatcher = {\n\t\t\t\t\t\t...watcher,\n\t\t\t\t\t\tasync resolveLaunchAttempt(...args: Parameters<typeof watcher.resolveLaunchAttempt>) {\n\t\t\t\t\t\t\tconst attempt = await watcher.resolveLaunchAttempt(...args);\n\t\t\t\t\t\t\tif (!attempt) return null;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...attempt,\n\t\t\t\t\t\t\t\tpreparationChecks: [\n\t\t\t\t\t\t\t\t\t...attempt.preparationChecks,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"github-trigger-authorization\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"Check GitHub trigger authorization\",\n\t\t\t\t\t\t\t\t\t\tasync run() {\n\t\t\t\t\t\t\t\t\t\t\tconst rechecked = await client.authorizedTrigger(\n\t\t\t\t\t\t\t\t\t\t\t\trepo.owner.login,\n\t\t\t\t\t\t\t\t\t\t\t\trepo.name,\n\t\t\t\t\t\t\t\t\t\t\t\tissue.number,\n\t\t\t\t\t\t\t\t\t\t\t\tconfig.labels.trigger,\n\t\t\t\t\t\t\t\t\t\t\t\tconfig.labels.done,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t!rechecked ||\n\t\t\t\t\t\t\t\t\t\t\t\trechecked.eventId !== authorized.eventId ||\n\t\t\t\t\t\t\t\t\t\t\t\trechecked.actor !== authorized.actor\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(\"GitHub trigger authorization changed before launch\");\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\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\tconst launched = await deps.launchRuns.startWatcher(guardedWatcher, event, {\n\t\t\t\t\t\tidempotencyKey: id,\n\t\t\t\t\t});\n\t\t\t\t\tif (launched.error) result.errors.push(`${id}:launch_failed:${launched.error}`);\n\t\t\t\t\telse if (launched.process) result.created.push(id);\n\t\t\t\t\telse result.skipped.push(id);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tresult.errors.push(\n\t\t\t\t\t\t`${id}:${error instanceof Error ? error.message : \"discovery_failed\"}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tasync function pollExternal(result: ReturnType<typeof emptyPollResult>) {\n\t\tconst report = githubPollReporter(deps.externalSources, result);\n\t\tconst terminalArmings = deps.externalSources.listArmed(GITHUB_PR_TERMINAL_KIND);\n\t\tconst terminalInstances = new Set<string>();\n\t\tasync function poll<C extends { pollInterval?: string; disabled?: boolean }>(\n\t\t\tkind: string,\n\t\t\tparse: (value: unknown) => C | null,\n\t\t\tread: (config: C, armed: ExternalSourceArmingLike) => Promise<void>,\n\t\t) {\n\t\t\tconst armings =\n\t\t\t\tkind === GITHUB_PR_TERMINAL_KIND ? terminalArmings : deps.externalSources.listArmed(kind);\n\t\t\tfor (const armed of armings) {\n\t\t\t\tif (kind !== GITHUB_PR_TERMINAL_KIND && terminalInstances.has(armed.instanceId)) continue;\n\t\t\t\tconst config = parse(armed.resolved);\n\t\t\t\tconst key = `${armed.instanceId}:${armed.id}:${armed.generation ?? \"\"}`;\n\t\t\t\tif (!config || !due(key, config.pollInterval ?? \"30s\") || config.disabled) continue;\n\t\t\t\ttry {\n\t\t\t\t\tawait read(config, armed);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\trefreshError: error instanceof Error ? error.message : \"GitHub refresh failed\",\n\t\t\t\t\t});\n\t\t\t\t\tconst fallback = kind === GITHUB_CHECKS_KIND ? \"checks_failed\" : \"poll_failed\";\n\t\t\t\t\tresult.errors.push(`${armed.id}:${error instanceof Error ? error.message : fallback}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tawait poll(GITHUB_PR_TERMINAL_KIND, parsePrConfig, async (config, armed) => {\n\t\t\tconst pr = await integration\n\t\t\t\t.client(config.profile)\n\t\t\t\t.getPullRequest(config.owner, config.repo, config.prNumber);\n\t\t\tif (!pr.merged && pr.state !== \"closed\") return;\n\t\t\tif (\n\t\t\t\t!deps.externalSources\n\t\t\t\t\t.listArmed(GITHUB_PR_TERMINAL_KIND)\n\t\t\t\t\t.some((current) => sameSubscription(armed, current))\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tterminalInstances.add(armed.instanceId);\n\t\t\tconst outcome = pr.merged ? \"merged\" : \"closed\";\n\t\t\tif (config.terminalOutcome && config.terminalOutcome !== outcome) return;\n\t\t\tawait report.fire(armed, { pullRequest: pr }, `${pr.number}:${outcome}`);\n\t\t});\n\n\t\tawait poll(\n\t\t\tGITHUB_CHECKS_KIND,\n\t\t\t(value) => ({ pollInterval: \"30s\", config: asUnknownRecord(value) ?? {} }),\n\t\t\tasync ({ config }, armed) => {\n\t\t\t\tconst client = integration.client(String(config.profile));\n\t\t\t\tconst pr = await client.getPullRequest(\n\t\t\t\t\tString(config.owner),\n\t\t\t\t\tString(config.repo),\n\t\t\t\t\tNumber(config.prNumber),\n\t\t\t\t);\n\t\t\t\tif (pr.state !== \"open\" || pr.head.sha !== config.headSha) return;\n\t\t\t\tconst checks = await client.getCheckSummary(\n\t\t\t\t\tString(config.owner),\n\t\t\t\t\tString(config.repo),\n\t\t\t\t\tString(config.headSha),\n\t\t\t\t);\n\t\t\t\tif (checks.headSha !== config.headSha) return;\n\t\t\t\tconst refreshed = await client.getPullRequest(\n\t\t\t\t\tString(config.owner),\n\t\t\t\t\tString(config.repo),\n\t\t\t\t\tNumber(config.prNumber),\n\t\t\t\t);\n\t\t\t\tif (refreshed.state !== \"open\" || refreshed.merged || refreshed.head.sha !== checks.headSha)\n\t\t\t\t\treturn;\n\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\tobservation: {\n\t\t\t\t\t\t...describeGitHubEvent({ checks }),\n\t\t\t\t\t\tobservedAt: new Date(now()).toISOString(),\n\t\t\t\t\t\tsubject: `${config.owner}/${config.repo}#${config.prNumber}`,\n\t\t\t\t\t\trevision: checks.headSha,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (checks.status !== \"failure\") return;\n\t\t\t\tawait report.fire(\n\t\t\t\t\tarmed,\n\t\t\t\t\t{ checks },\n\t\t\t\t\t`${checks.headSha}:${checks.failed.map((run) => run.url).join(\":\")}`,\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\n\t\tawait poll(GITHUB_ISSUE_CANCELLED_KIND, parseIssueCancelledConfig, async (config, armed) => {\n\t\t\tconst issue = await integration\n\t\t\t\t.client(config.profile)\n\t\t\t\t.getIssue(config.owner, config.repo, config.issueNumber);\n\t\t\tconst reason =\n\t\t\t\tissue.state === \"closed\"\n\t\t\t\t\t? \"issue_closed\"\n\t\t\t\t\t: hasLabel(issue, config.triggerLabel)\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: \"trigger_label_removed\";\n\t\t\tif (!reason) return;\n\t\t\t// A merge may close the issue between terminal polls. Preserve terminal\n\t\t\t// reconciliation instead of treating that close as cancellation.\n\t\t\tconst terminal = terminalArmings\n\t\t\t\t.filter((candidate) => candidate.instanceId === armed.instanceId)\n\t\t\t\t.map((candidate) => parsePrConfig(candidate.resolved))\n\t\t\t\t.find((candidate) => candidate && !candidate.disabled);\n\t\t\tif (terminal) {\n\t\t\t\tconst pr = await integration\n\t\t\t\t\t.client(terminal.profile)\n\t\t\t\t\t.getPullRequest(terminal.owner, terminal.repo, terminal.prNumber);\n\t\t\t\tif (pr.merged || pr.state === \"closed\") {\n\t\t\t\t\tterminalInstances.add(armed.instanceId);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait report.fire(armed, { issue, reason }, `${issue.number}:${reason}`);\n\t\t});\n\t\tawait poll(GITHUB_PR_FEEDBACK_KIND, parseFeedbackConfig, async (config, armed) => {\n\t\t\tconst client = integration.client(config.profile);\n\t\t\tconst pr = await client.getPullRequest(config.owner, config.repo, config.prNumber);\n\t\t\tif (pr.merged || pr.state !== \"open\") return;\n\t\t\tconst unseen = (\n\t\t\t\tawait client.listActionablePullRequestFeedback(config.owner, config.repo, config.prNumber)\n\t\t\t).filter((item) => item.id > config[`${item.kind}Cursor`]);\n\n\t\t\tconst batch = repositoryFeedbackBatch(unseen, config, now());\n\t\t\tif (batch) await report.fire(armed, batch.event, batch.mergeKey);\n\t\t});\n\t}\n\n\treturn async (result: ReturnType<typeof emptyPollResult>) => {\n\t\tconst watchers = deps.processWatchers?.listBySource(githubIssueWatcherSource) ?? [];\n\t\tfor (const watcher of watchers) {\n\t\t\tif (\n\t\t\t\t!watcher.enabled ||\n\t\t\t\t!due(`${watcher.processId}:${watcher.watcherId}`, watcher.config.pollInterval)\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\ttry {\n\t\t\t\tawait discover(watcher, result);\n\t\t\t} catch (error) {\n\t\t\t\tresult.errors.push(\n\t\t\t\t\t`${watcher.processId}:${watcher.watcherId}:${error instanceof Error ? error.message : \"discovery_failed\"}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tawait pollExternal(result);\n\t};\n}\n","import {\n\tdefineProcessWatcherSource,\n\tparseRepositoryIssueWatcherConfig,\n\tpresentRepositoryIssueWatcherConfig,\n\ttype RepositoryIssueWatcherConfig,\n} from \"@leitwerk-dev/process-sdk\";\nimport type { GitHubIssue, GitHubRepository } from \"./client.js\";\n\nexport interface GitHubIssueWatcherConfig extends RepositoryIssueWatcherConfig {}\n\nexport interface GitHubIssueWatcherEvent {\n\tauthorization: { actor: string; eventId: number };\n\tprofile: string;\n\trepository: GitHubRepository;\n\tissue: GitHubIssue;\n\tlabels: {\n\t\ttrigger: string;\n\t\tdone: string;\n\t};\n}\n\nexport const githubIssueWatcherSource = defineProcessWatcherSource<\n\tGitHubIssueWatcherConfig,\n\tGitHubIssueWatcherEvent\n>({\n\tid: \"@leitwerk-public/github.issue\",\n\tlabel: \"GitHub issue\",\n\tparseConfig: (raw) => parseRepositoryIssueWatcherConfig(raw, \"github_issue\", true),\n\tpresentConfig: presentRepositoryIssueWatcherConfig,\n});\n","import {\n\tcreateExternalSourcePollReporter,\n\ttype ExternalSourceArmingLike,\n\ttype ExternalSourceServiceLike,\n} from \"@leitwerk-dev/process-sdk\";\nimport { sameSubscription } from \"@leitwerk-dev/repository-rebase\";\nimport {\n\tGITHUB_CHECKS_KIND,\n\tGITHUB_ISSUE_CANCELLED_KIND,\n\tGITHUB_PR_FEEDBACK_KIND,\n\tGITHUB_PR_STATE_KIND,\n\tGITHUB_PR_TERMINAL_KIND,\n\tGITHUB_RELEASE_KIND,\n} from \"./external.js\";\n\nexport function githubPollReporter(\n\tsources: ExternalSourceServiceLike,\n\tresult: { created: string[]; errors: string[] },\n) {\n\tconst report = createExternalSourcePollReporter(sources, result, { forwardGeneration: true });\n\tconst current = (armed: ExternalSourceArmingLike) =>\n\t\t[\n\t\t\tGITHUB_CHECKS_KIND,\n\t\t\tGITHUB_PR_STATE_KIND,\n\t\t\tGITHUB_PR_TERMINAL_KIND,\n\t\t\tGITHUB_PR_FEEDBACK_KIND,\n\t\t\tGITHUB_ISSUE_CANCELLED_KIND,\n\t\t\tGITHUB_RELEASE_KIND,\n\t\t].some((kind) => sources.listArmed(kind).some((value) => sameSubscription(armed, value)));\n\treturn {\n\t\t...report,\n\t\tasync fire(\n\t\t\tarmed: Parameters<typeof report.fire>[0],\n\t\t\tevent: Record<string, unknown>,\n\t\t\tmergeKey: string,\n\t\t) {\n\t\t\tif (!current(armed as ExternalSourceArmingLike)) return false;\n\t\t\treturn report.fire(armed, event, mergeKey);\n\t\t},\n\t\tobserve(\n\t\t\tarmed: Parameters<typeof report.observe>[0],\n\t\t\tinput: Parameters<typeof report.observe>[1],\n\t\t) {\n\t\t\tif (current(armed as ExternalSourceArmingLike)) return report.observe(armed, input);\n\t\t},\n\t};\n}\n","import {\n\tcreateWriteIdentity,\n\ttype ExternalWriteLogRepoLike,\n\tensureWrite,\n\trecordWriteIfMissing,\n} from \"@leitwerk-dev/external-writes\";\nimport {\n\ttype IntegrationToolExecutionContext,\n\tnumberArg,\n\tobjectArg,\n\tprojectParameters,\n\ttype ServerExtensionAPI,\n\tstringArg,\n} from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitHubProjectBinding } from \"./binding.js\";\nimport type { GitHubIntegration } from \"./capability.js\";\nimport { assertGitHubRepository } from \"./client.js\";\n\nconst object = (value: unknown) => objectArg(value, \"Expected an object\");\n\nasync function reconcileComment(\n\tcomments: Promise<Array<{ body?: unknown }>>,\n\tmarker: string,\n\tbody: () => string,\n\tpost: (body: string) => Promise<unknown>,\n) {\n\tconst existing = (await comments).find((comment) => String(comment.body).includes(marker));\n\treturn existing ?? post(`${body()}\\n\\n${marker}`);\n}\n\nexport function registerGitHubTools(\n\tapi: ServerExtensionAPI,\n\tintegration: GitHubIntegration,\n\twrites: ExternalWriteLogRepoLike,\n) {\n\tconst target = (ctx: IntegrationToolExecutionContext) => {\n\t\tconst binding = resolveGitHubProjectBinding(ctx);\n\t\tassertGitHubRepository(\n\t\t\tintegration.client(binding.profile).profile,\n\t\t\tbinding.owner,\n\t\t\tbinding.repo,\n\t\t);\n\t\treturn binding;\n\t};\n\tapi.tool({\n\t\tname: \"github_resolve_git_identity\",\n\t\tdescription: \"Resolve the configured GitHub Git identity\",\n\t\tparameters: {\n\t\t\ttype: \"object\",\n\t\t\tproperties: { projectKey: { type: \"string\" } },\n\t\t\trequired: [\"projectKey\"],\n\t\t},\n\t\tasync execute(ctx) {\n\t\t\tconst t = target(ctx);\n\t\t\treturn integration.client(t.profile).resolveGitIdentity(t.profile);\n\t\t},\n\t});\n\tfor (const name of [\n\t\t\"github_ensure_label\",\n\t\t\"github_update_issue\",\n\t\t\"github_add_issue_comment\",\n\t\t\"github_add_pull_request_feedback_reaction\",\n\t\t\"github_reply_to_pull_request_feedback\",\n\t] as const) {\n\t\tapi.tool({\n\t\t\tname,\n\t\t\tdescription: \"Reconcile GitHub delivery in the current process project\",\n\t\t\tparameters: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tprojectKey: { type: \"string\" },\n\t\t\t\t\tissueNumber: { type: \"integer\" },\n\t\t\t\t\tpullRequestNumber: { type: \"integer\" },\n\t\t\t\t\tname: { type: \"string\" },\n\t\t\t\t\tpatch: { type: \"object\" },\n\t\t\t\t\tbody: { type: \"string\" },\n\t\t\t\t\tfeedbackKind: { type: \"string\" },\n\t\t\t\t\tfeedbackId: { type: \"integer\" },\n\t\t\t\t\twriteKey: { type: \"string\" },\n\t\t\t\t},\n\t\t\t\trequired: [\"projectKey\"],\n\t\t\t},\n\t\t\tasync execute(ctx, args) {\n\t\t\t\tconst input = object(args);\n\t\t\t\tconst t = target(ctx);\n\t\t\t\tconst client = integration.client(t.profile);\n\t\t\t\tconst key =\n\t\t\t\t\ttypeof input.writeKey === \"string\" ? stringArg(input, \"writeKey\") : ctx.idempotencyKey;\n\t\t\t\tconst marker = `<!-- leitwerk-write:${ctx.process.id}:${key} -->`;\n\t\t\t\tlet value: unknown;\n\t\t\t\tconst result = await ensureWrite(\n\t\t\t\t\twrites,\n\t\t\t\t\tctx.process.id,\n\t\t\t\t\tcreateWriteIdentity(name, key),\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tif (name === \"github_ensure_label\")\n\t\t\t\t\t\t\tvalue = await client.ensureLabel(t.owner, t.repo, stringArg(input, \"name\"));\n\t\t\t\t\t\telse if (name === \"github_update_issue\") {\n\t\t\t\t\t\t\tconst issueNumber = numberArg(input, \"issueNumber\");\n\t\t\t\t\t\t\tconst current = await client.getIssue(t.owner, t.repo, issueNumber);\n\t\t\t\t\t\t\tconst patch = object(input.patch);\n\t\t\t\t\t\t\tconst same = Object.entries(patch).every(\n\t\t\t\t\t\t\t\t([key, expected]) =>\n\t\t\t\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\t\t\t\tkey === \"labels\"\n\t\t\t\t\t\t\t\t\t\t\t? current.labels.map((label) => label.name).sort()\n\t\t\t\t\t\t\t\t\t\t\t: object(current)[key],\n\t\t\t\t\t\t\t\t\t) ===\n\t\t\t\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\t\t\t\tkey === \"labels\" && Array.isArray(expected) ? [...expected].sort() : expected,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tvalue = same\n\t\t\t\t\t\t\t\t? current\n\t\t\t\t\t\t\t\t: await client.updateIssue(t.owner, t.repo, issueNumber, patch);\n\t\t\t\t\t\t} else if (name === \"github_add_pull_request_feedback_reaction\") {\n\t\t\t\t\t\t\tconst kind = stringArg(input, \"feedbackKind\");\n\t\t\t\t\t\t\tconst id = numberArg(input, \"feedbackId\");\n\t\t\t\t\t\t\tconst reactions = await client.listFeedbackReactions(t.owner, t.repo, kind, id);\n\t\t\t\t\t\t\tvalue =\n\t\t\t\t\t\t\t\treactions.find(\n\t\t\t\t\t\t\t\t\t(reaction) =>\n\t\t\t\t\t\t\t\t\t\treaction.content === \"eyes\" &&\n\t\t\t\t\t\t\t\t\t\treaction.user.login.toLowerCase() === client.profile.botLogin.toLowerCase(),\n\t\t\t\t\t\t\t\t) ?? (await client.addFeedbackReaction(t.owner, t.repo, kind, id));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst issueNumber = numberArg(\n\t\t\t\t\t\t\t\t{ issueNumber: input.issueNumber ?? input.pullRequestNumber },\n\t\t\t\t\t\t\t\t\"issueNumber\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tvalue = await reconcileComment(\n\t\t\t\t\t\t\t\tname === \"github_reply_to_pull_request_feedback\"\n\t\t\t\t\t\t\t\t\t? client.listFeedbackReplies(\n\t\t\t\t\t\t\t\t\t\t\tt.owner,\n\t\t\t\t\t\t\t\t\t\t\tt.repo,\n\t\t\t\t\t\t\t\t\t\t\tissueNumber,\n\t\t\t\t\t\t\t\t\t\t\tstringArg(input, \"feedbackKind\"),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: client.listIssueComments(t.owner, t.repo, issueNumber),\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\t() => stringArg(input, \"body\"),\n\t\t\t\t\t\t\t\t(body) =>\n\t\t\t\t\t\t\t\t\tname === \"github_add_issue_comment\"\n\t\t\t\t\t\t\t\t\t\t? client.addIssueComment(t.owner, t.repo, issueNumber, body)\n\t\t\t\t\t\t\t\t\t\t: client.replyFeedback(\n\t\t\t\t\t\t\t\t\t\t\t\tt.owner,\n\t\t\t\t\t\t\t\t\t\t\t\tt.repo,\n\t\t\t\t\t\t\t\t\t\t\t\tissueNumber,\n\t\t\t\t\t\t\t\t\t\t\t\tstringArg(input, \"feedbackKind\"),\n\t\t\t\t\t\t\t\t\t\t\t\tnumberArg(input, \"feedbackId\"),\n\t\t\t\t\t\t\t\t\t\t\t\tbody,\n\t\t\t\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\treturn { value };\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (name === \"github_ensure_label\") return { name: stringArg(input, \"name\") };\n\t\t\t\treturn value ?? result;\n\t\t\t},\n\t\t});\n\t}\n\n\tapi.tool<Record<string, unknown>>({\n\t\tname: \"github_ensure_pull_request\",\n\t\tdescription: \"Create a GitHub pull request unless the branch pair already has one\",\n\t\tparameters: projectParameters({\n\t\t\ttitle: { type: \"string\" },\n\t\t\tbody: { type: \"string\" },\n\t\t\thead: { type: \"string\" },\n\t\t\tbase: { type: \"string\" },\n\t\t}),\n\t\tasync execute(ctx, input) {\n\t\t\tconst t = target(ctx);\n\t\t\tconst client = integration.client(t.profile);\n\t\t\tconst head = stringArg(input, \"head\");\n\t\t\tconst base = stringArg(input, \"base\");\n\t\t\tif (head !== ctx.project?.workBranch || base !== ctx.project?.baseBranch)\n\t\t\t\tthrow new Error(\"Pull request branches must match the process project\");\n\t\t\tconst find = async () =>\n\t\t\t\t(await client.listPullRequests(t.owner, t.repo, \"all\")).find(\n\t\t\t\t\t(candidate) => candidate.head.ref === head && candidate.base.ref === base,\n\t\t\t\t) ?? null;\n\t\t\tlet pr = await find();\n\t\t\tconst identity = createWriteIdentity(\"github.ensure_pr\", ctx.idempotencyKey);\n\t\t\tif (!pr) {\n\t\t\t\ttry {\n\t\t\t\t\tawait ensureWrite(writes, ctx.process.id, identity, async () => {\n\t\t\t\t\t\tpr = await client.createPullRequest(t.owner, t.repo, {\n\t\t\t\t\t\t\ttitle: stringArg(input, \"title\"),\n\t\t\t\t\t\t\tbody: stringArg(input, \"body\"),\n\t\t\t\t\t\t\thead,\n\t\t\t\t\t\t\tbase,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn { number: pr.number, url: pr.html_url };\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tpr = await find();\n\t\t\t\t\tif (!pr) throw error;\n\t\t\t\t}\n\t\t\t\tpr ??= await find();\n\t\t\t}\n\t\t\tif (!pr) throw new Error(\"GitHub pull request creation could not be reconciled\");\n\t\t\trecordWriteIfMissing(writes, ctx.process.id, identity, {\n\t\t\t\tnumber: pr.number,\n\t\t\t\turl: pr.html_url,\n\t\t\t});\n\t\t\treturn pr;\n\t\t},\n\t});\n\tfor (const [name, description, numberName, method] of [\n\t\t[\n\t\t\t\"github_get_issue\",\n\t\t\t\"Read a GitHub issue in the current process project\",\n\t\t\t\"issueNumber\",\n\t\t\t\"getIssue\",\n\t\t],\n\t\t[\n\t\t\t\"github_get_pull_request\",\n\t\t\t\"Read a GitHub pull request in the current process project\",\n\t\t\t\"pullRequestNumber\",\n\t\t\t\"getPullRequest\",\n\t\t],\n\t\t[\n\t\t\t\"github_list_pull_request_feedback\",\n\t\t\t\"Read GitHub pull request conversation, reviews, and inline comments\",\n\t\t\t\"pullRequestNumber\",\n\t\t\t\"listActionablePullRequestFeedback\",\n\t\t],\n\t] as const) {\n\t\tapi.tool<Record<string, unknown>>({\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tparameters: projectParameters({ [numberName]: { type: \"integer\" } }),\n\t\t\tasync execute(ctx, input) {\n\t\t\t\tconst t = target(ctx);\n\t\t\t\treturn integration\n\t\t\t\t\t.client(t.profile)\n\t\t\t\t\t[method](t.owner, t.repo, numberArg(input, numberName), ctx.signal);\n\t\t\t},\n\t\t});\n\t}\n\tapi.tool<Record<string, unknown>>({\n\t\tname: \"github_get_checks\",\n\t\tdescription: \"Read GitHub Actions check runs for a commit\",\n\t\tparameters: projectParameters({ headSha: { type: \"string\" } }),\n\t\tasync execute(ctx, input) {\n\t\t\tconst t = target(ctx);\n\t\t\treturn integration\n\t\t\t\t.client(t.profile)\n\t\t\t\t.getCheckSummary(t.owner, t.repo, stringArg(input, \"headSha\"));\n\t\t},\n\t});\n\tfor (const definition of [\n\t\t{ name: \"github_add_pull_request_comment\", update: false },\n\t\t{ name: \"github_update_pull_request\", update: true },\n\t] as const) {\n\t\tapi.tool<Record<string, unknown>>({\n\t\t\tname: definition.name,\n\t\t\tdescription: definition.update\n\t\t\t\t? \"Update a GitHub pull request\"\n\t\t\t\t: \"Comment on a GitHub pull request\",\n\t\t\tparameters: projectParameters(\n\t\t\t\t{\n\t\t\t\t\tpullRequestNumber: { type: \"integer\" },\n\t\t\t\t\t...(definition.update\n\t\t\t\t\t\t? { patch: { type: \"object\" } }\n\t\t\t\t\t\t: { body: { type: \"string\" }, writeKey: { type: \"string\" } }),\n\t\t\t\t},\n\t\t\t\t[\"pullRequestNumber\", definition.update ? \"patch\" : \"body\"],\n\t\t\t),\n\t\t\tasync execute(ctx, input) {\n\t\t\t\tconst t = target(ctx);\n\t\t\t\tconst pr = numberArg(input, \"pullRequestNumber\");\n\t\t\t\tconst key =\n\t\t\t\t\t!definition.update && typeof input.writeKey === \"string\"\n\t\t\t\t\t\t? stringArg(input, \"writeKey\")\n\t\t\t\t\t\t: ctx.idempotencyKey;\n\t\t\t\treturn ensureWrite(\n\t\t\t\t\twrites,\n\t\t\t\t\tctx.process.id,\n\t\t\t\t\tcreateWriteIdentity(definition.update ? \"github.update_pr\" : \"github.comment\", key),\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tif (definition.update)\n\t\t\t\t\t\t\tawait integration\n\t\t\t\t\t\t\t\t.client(t.profile)\n\t\t\t\t\t\t\t\t.updatePullRequest(t.owner, t.repo, pr, object(input.patch), ctx.signal);\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconst client = integration.client(t.profile);\n\t\t\t\t\t\t\tawait reconcileComment(\n\t\t\t\t\t\t\t\tclient.listIssueComments(t.owner, t.repo, pr, ctx.signal),\n\t\t\t\t\t\t\t\t`<!-- leitwerk-write:${ctx.process.id}:${key} -->`,\n\t\t\t\t\t\t\t\t() => stringArg(input, \"body\"),\n\t\t\t\t\t\t\t\t(body) => client.addIssueComment(t.owner, t.repo, pr, body, ctx.signal),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { owner: t.owner, repo: t.repo, pullRequestNumber: pr };\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n}\n","import { resolveRepositoryProjectBinding } from \"@leitwerk-dev/process-sdk\";\n\nexport type { RepositoryProjectBinding as GitHubProjectBinding } from \"@leitwerk-dev/process-sdk\";\nexport const resolveGitHubProjectBinding = (\n\tctx: Parameters<typeof resolveRepositoryProjectBinding>[0],\n) => resolveRepositoryProjectBinding(ctx, \"github\");\n"],"mappings":";;;;;;;AACA,SAAS,4BAA0D;;;ACDnE,SAAS,6BAA6B;AAU/B,IAAM,oBAAoB;AAAA,EAChC;AACD;;;ACZA,SAAS,mBAAAA,wBAAuB;AAEhC,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,sBAAAC,qBAAoB,uBAAuB;;;ACHpD;AAAA,EACC;AAAA,OAEM;AACP,SAAS,wBAAwB;AAE1B,IAAM,uBAAuB;AAgB7B,IAAM,sBAAsB;AAW5B,SAAS,oBAAoB,OAA0C;AAC7E,QAAM,QAAQ;AASd,MAAI,MAAM,SAAS,iBA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AAO;AAC3C,oBAAM;AAAA,gBACL,OAAO,kBAAkB,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI,MAAM;AAAA,gBACxD,uBAAuB,IAAI,QAAQ,EAAE,IAAI,GAAG;AAAA,gBAC5C,MAAM,UAAU,OAAO,MAAM;AAAA,gBAC7B,CAAC,SAAS,OAAO,gBAAgB,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM,IAAI,MAAM;AAAA,cACvE;AAAA,YACD;AACA,mBAAO,EAAE,OAAO,EAAE,OAAO,MAAM,EAAE,MAAM,mBAAmB,GAAG;AAAA,UAC9D;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AACD;;;APxSO,IAAM,WAAW,EAAE,IAAI,UAAU,SAAS,QAAQ;AAEzD,IAAM,YAAqC;AAAA,EAC1C;AAAA,EACA,YAAY,KAAK,QAAQ;AACxB,UAAM,WAAW,oBAAoB,MAAM;AAC3C,UAAM,cAAiC;AAAA,MACtC,OAAO,SAAS;AACf,cAAM,QAAQ,SAAS,IAAI,OAAO;AAClC,YAAI,CAAC,MAAO,OAAM,IAAI,MAAM,2BAA2B,OAAO,GAAG;AACjE,eAAO,IAAI,aAAa,KAAK;AAAA,MAC9B;AAAA,IACD;AACA,2BAAuB,KAAK,WAAW;AAAA,EACxC;AACD;AAKA,IAAO,gBAAQ;AAGR,SAAS,uBACf,KACA,aACA,UAAkC,CAAC,GAClC;AACD,MAAI,QAAQ,mBAAmB,WAAW;AAC1C,QAAM,OAAO,IAAI,IAAI,qBAAqB,WAAW;AACrD,MAAI,CAAC,QAAQ,MAAM,QAAQ,IAAI,EAAG;AAClC,sBAAoB,KAAK,aAAa,KAAK,cAA0C;AACrF,SAAO,qBAAqB,MAAM,aAAa,OAAO;AACvD;","names":["asUnknownRecord","createPollSchedule","sameSubscription","parse","sameSubscription","asUnknownRecord","value","createPollSchedule","key"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CoreServerSetupDeps, matchesRepository as matchesConfiguredRepository } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { type emptyPollResult } from "@leitwerk-dev/watcher-utils";
|
|
3
|
+
import type { GitHubIntegration } from "./capability.js";
|
|
4
|
+
export { matchesConfiguredRepository };
|
|
5
|
+
export declare function createGitHubIssuePolling(deps: CoreServerSetupDeps, integration: GitHubIntegration, options?: {
|
|
6
|
+
now?: () => number;
|
|
7
|
+
}): (result: ReturnType<typeof emptyPollResult>) => Promise<void>;
|
|
8
|
+
//# sourceMappingURL=issue-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue-provider.d.ts","sourceRoot":"","sources":["../src/issue-provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,mBAAmB,EAExB,iBAAiB,IAAI,2BAA2B,EAMhD,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAwBzD,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAEvC,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,mBAAmB,EACzB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO,IAyNtB,QAAQ,UAAU,CAAC,OAAO,eAAe,CAAC,mBAkBxD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RepositoryIssueWatcherConfig } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { GitHubIssue, GitHubRepository } from "./client.js";
|
|
3
|
+
export interface GitHubIssueWatcherConfig extends RepositoryIssueWatcherConfig {
|
|
4
|
+
}
|
|
5
|
+
export interface GitHubIssueWatcherEvent {
|
|
6
|
+
authorization: {
|
|
7
|
+
actor: string;
|
|
8
|
+
eventId: number;
|
|
9
|
+
};
|
|
10
|
+
profile: string;
|
|
11
|
+
repository: GitHubRepository;
|
|
12
|
+
issue: GitHubIssue;
|
|
13
|
+
labels: {
|
|
14
|
+
trigger: string;
|
|
15
|
+
done: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare const githubIssueWatcherSource: import("@leitwerk-dev/process-sdk").ProcessWatcherSource<GitHubIssueWatcherConfig, GitHubIssueWatcherEvent>;
|
|
19
|
+
//# sourceMappingURL=issue-watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue-watcher.d.ts","sourceRoot":"","sources":["../src/issue-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,4BAA4B,EACjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;CAAG;AAEjF,MAAM,WAAW,uBAAuB;IACvC,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;CACF;AAED,eAAO,MAAM,wBAAwB,6GAQnC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ExternalSourceArmingLike, type ExternalSourceServiceLike } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
export declare function githubPollReporter(sources: ExternalSourceServiceLike, result: {
|
|
3
|
+
created: string[];
|
|
4
|
+
errors: string[];
|
|
5
|
+
}): {
|
|
6
|
+
fire(armed: Parameters<(armed: {
|
|
7
|
+
id: string;
|
|
8
|
+
instanceId: string;
|
|
9
|
+
generation?: string | undefined;
|
|
10
|
+
}, event: Record<string, unknown>, mergeKey: string) => Promise<boolean>>[0], event: Record<string, unknown>, mergeKey: string): Promise<boolean>;
|
|
11
|
+
observe(armed: Parameters<(armed: {
|
|
12
|
+
id: string;
|
|
13
|
+
instanceId: string;
|
|
14
|
+
generation?: string | undefined;
|
|
15
|
+
}, input: Pick<import("@leitwerk-dev/process-sdk").ExternalObservationInput, "observation" | "refreshError">) => Promise<import("@leitwerk-dev/process-sdk").ActionExecutionResultLike> | undefined>[0], input: Parameters<(armed: {
|
|
16
|
+
id: string;
|
|
17
|
+
instanceId: string;
|
|
18
|
+
generation?: string | undefined;
|
|
19
|
+
}, input: Pick<import("@leitwerk-dev/process-sdk").ExternalObservationInput, "observation" | "refreshError">) => Promise<import("@leitwerk-dev/process-sdk").ActionExecutionResultLike> | undefined>[1]): Promise<import("@leitwerk-dev/process-sdk").ActionExecutionResultLike> | undefined;
|
|
20
|
+
poll(kind: string, read: (armed: ExternalSourceArmingLike) => Promise<void>): Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=poll-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll-report.d.ts","sourceRoot":"","sources":["../src/poll-report.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,MAAM,2BAA2B,CAAC;AAWnC,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,yBAAyB,EAClC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE;gBAetC,UAAU;;;;6EAAoB,CAAC,CAAC,CAAC,SACjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACpB,MAAM;mBAMT,UAAU;;;;wMAAuB,CAAC,CAAC,CAAC,SACpC,UAAU;;;;wMAAuB,CAAC,CAAC,CAAC;;EAK7C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CoreServerSetupDeps } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { GitHubIntegration } from "./capability.js";
|
|
3
|
+
export declare function createGitHubProvider(deps: CoreServerSetupDeps, integration: GitHubIntegration, options?: {
|
|
4
|
+
now?: () => number;
|
|
5
|
+
}): import("@leitwerk-dev/process-sdk").PollingHandleLike<import("@leitwerk-dev/watcher-utils").PollResult>;
|
|
6
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA2CzD,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,mBAAmB,EACzB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO,2GAqKpC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { LocalForgeStore, type LocalRepositorySeed } from "@leitwerk-dev/test-support/local-git";
|
|
2
|
+
import type { GitHubClientLike } from "./capability.js";
|
|
3
|
+
import type { GitHubCheckSummary, GitHubFeedbackItem, GitHubIssue, GitHubLabelEvent, GitHubPullRequest, GitHubRelease } from "./client.js";
|
|
4
|
+
export interface LocalGitHubRepository {
|
|
5
|
+
repository: ReturnType<LocalGitHubAdapter["newRepository"]>;
|
|
6
|
+
issues: GitHubIssue[];
|
|
7
|
+
pulls: GitHubPullRequest[];
|
|
8
|
+
comments: Record<string, Array<ReturnType<LocalGitHubAdapter["newComment"]>>>;
|
|
9
|
+
feedback: Record<string, GitHubFeedbackItem[]>;
|
|
10
|
+
checks: Record<string, GitHubCheckSummary>;
|
|
11
|
+
releases: GitHubRelease[];
|
|
12
|
+
assets: Record<string, string>;
|
|
13
|
+
labels: Array<{
|
|
14
|
+
id: number;
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
labelEvents: Record<string, GitHubLabelEvent[]>;
|
|
18
|
+
reactions: Record<string, Array<{
|
|
19
|
+
id: number;
|
|
20
|
+
content: string;
|
|
21
|
+
user: {
|
|
22
|
+
login: string;
|
|
23
|
+
};
|
|
24
|
+
}>>;
|
|
25
|
+
feedbackEditors: Record<string, string | null>;
|
|
26
|
+
}
|
|
27
|
+
export interface LocalGitHubState {
|
|
28
|
+
version: 1;
|
|
29
|
+
sequence: number;
|
|
30
|
+
repositories: LocalGitHubRepository[];
|
|
31
|
+
failAfterPullRequestWrite: boolean;
|
|
32
|
+
members: string[];
|
|
33
|
+
failAfterWrite: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface LocalGitHubOptions {
|
|
36
|
+
root: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
now?: () => number;
|
|
39
|
+
nextId?: () => number;
|
|
40
|
+
seeds?: LocalRepositorySeed[];
|
|
41
|
+
allowedOrganization?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Persistent local GitHub with actual commit ancestry and configurable release assets. */
|
|
44
|
+
export declare class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {
|
|
45
|
+
constructor(options: LocalGitHubOptions);
|
|
46
|
+
repo(owner: string, name: string): LocalGitHubRepository;
|
|
47
|
+
seed(seed: LocalRepositorySeed): LocalGitHubRepository;
|
|
48
|
+
setChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary): void;
|
|
49
|
+
publishRelease(repo: LocalGitHubRepository, input: {
|
|
50
|
+
tag: string;
|
|
51
|
+
ref: string;
|
|
52
|
+
assets: Record<string, string>;
|
|
53
|
+
draft?: boolean;
|
|
54
|
+
prerelease?: boolean;
|
|
55
|
+
}): GitHubRelease;
|
|
56
|
+
newRepository(seed: LocalRepositorySeed): {
|
|
57
|
+
archived: boolean;
|
|
58
|
+
has_issues: boolean;
|
|
59
|
+
id: number;
|
|
60
|
+
owner: {
|
|
61
|
+
login: string;
|
|
62
|
+
};
|
|
63
|
+
name: string;
|
|
64
|
+
full_name: string;
|
|
65
|
+
ssh_url: string;
|
|
66
|
+
html_url: string;
|
|
67
|
+
default_branch: string;
|
|
68
|
+
};
|
|
69
|
+
setMembership(login: string, member: boolean): void;
|
|
70
|
+
failNextResponse(operation: "comment" | "reply" | "reaction" | "issue" | "label"): void;
|
|
71
|
+
private lostResponse;
|
|
72
|
+
createIssue(repo: LocalGitHubRepository, input: {
|
|
73
|
+
title: string;
|
|
74
|
+
body?: string;
|
|
75
|
+
author?: string;
|
|
76
|
+
}): GitHubIssue;
|
|
77
|
+
setIssueLabel(repo: LocalGitHubRepository, number: number, name: string, actor: string, present?: boolean): GitHubLabelEvent;
|
|
78
|
+
editFeedback(repo: LocalGitHubRepository, number: number, kind: GitHubFeedbackItem["kind"], id: number, body: string, editor: string | null): void;
|
|
79
|
+
client(): GitHubClientLike;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAEjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EACX,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAEhB,iBAAiB,EACjB,aAAa,EACb,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,qBAAqB;IACrC,UAAU,EAAE,UAAU,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,CAAC;IAC5D,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,kB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,MAAM,EAAE,MAAM,GAAG,IAAI;IAUtB,MAAM,IAAI,gBAAgB;CA+K1B"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {
|
|
2
|
+
actionableFeedback,
|
|
3
|
+
assertGitHubRepository,
|
|
4
|
+
authorizedTrigger
|
|
5
|
+
} from "./chunk-PVE52UFH.js";
|
|
6
|
+
|
|
7
|
+
// src/testing.ts
|
|
8
|
+
import { LocalForgeStore } from "@leitwerk-dev/test-support/local-git";
|
|
9
|
+
var LocalGitHubAdapter = class extends LocalForgeStore {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options, "github.json", {
|
|
12
|
+
version: 1,
|
|
13
|
+
sequence: 0,
|
|
14
|
+
repositories: [],
|
|
15
|
+
failAfterPullRequestWrite: false,
|
|
16
|
+
members: [],
|
|
17
|
+
failAfterWrite: null
|
|
18
|
+
});
|
|
19
|
+
this.state.members ??= [];
|
|
20
|
+
this.state.failAfterWrite ??= null;
|
|
21
|
+
for (const r of this.state.repositories) {
|
|
22
|
+
r.labels ??= [];
|
|
23
|
+
r.labelEvents ??= {};
|
|
24
|
+
r.reactions ??= {};
|
|
25
|
+
r.feedbackEditors ??= {};
|
|
26
|
+
}
|
|
27
|
+
for (const seed of options.seeds ?? []) this.seed(seed);
|
|
28
|
+
}
|
|
29
|
+
repo(owner, name) {
|
|
30
|
+
const repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);
|
|
31
|
+
if (!repo) throw new Error("Unknown local GitHub repository");
|
|
32
|
+
return repo;
|
|
33
|
+
}
|
|
34
|
+
seed(seed) {
|
|
35
|
+
const existing = this.state.repositories.find(
|
|
36
|
+
(r) => r.repository.full_name === `${seed.owner}/${seed.name}`
|
|
37
|
+
);
|
|
38
|
+
if (existing) return existing;
|
|
39
|
+
const repo = {
|
|
40
|
+
repository: this.newRepository(seed),
|
|
41
|
+
issues: [],
|
|
42
|
+
pulls: [],
|
|
43
|
+
comments: {},
|
|
44
|
+
feedback: {},
|
|
45
|
+
checks: {},
|
|
46
|
+
releases: [],
|
|
47
|
+
assets: {},
|
|
48
|
+
labels: [],
|
|
49
|
+
labelEvents: {},
|
|
50
|
+
reactions: {},
|
|
51
|
+
feedbackEditors: {}
|
|
52
|
+
};
|
|
53
|
+
this.state.repositories.push(repo);
|
|
54
|
+
this.save();
|
|
55
|
+
return repo;
|
|
56
|
+
}
|
|
57
|
+
setChecks(repo, summary) {
|
|
58
|
+
this.git.head(repo.repository.ssh_url, summary.headSha);
|
|
59
|
+
repo.checks[summary.headSha] = structuredClone(summary);
|
|
60
|
+
this.save();
|
|
61
|
+
}
|
|
62
|
+
publishRelease(repo, input) {
|
|
63
|
+
const commit = this.git.head(repo.repository.ssh_url, input.ref);
|
|
64
|
+
this.git.run(repo.repository.ssh_url, ["check-ref-format", `refs/tags/${input.tag}`]);
|
|
65
|
+
this.git.run(repo.repository.ssh_url, ["tag", "--", input.tag, commit]);
|
|
66
|
+
const id = this.id();
|
|
67
|
+
const release = {
|
|
68
|
+
id,
|
|
69
|
+
tag_name: input.tag,
|
|
70
|
+
target_commitish: commit,
|
|
71
|
+
draft: input.draft ?? false,
|
|
72
|
+
prerelease: input.prerelease ?? false,
|
|
73
|
+
html_url: `${this.options.baseUrl}/__local`,
|
|
74
|
+
assets: Object.entries(input.assets).map(([name, contents]) => {
|
|
75
|
+
const url = `${this.options.baseUrl}/__local/assets/${this.id()}`;
|
|
76
|
+
repo.assets[url] = contents;
|
|
77
|
+
return { name, url, browser_download_url: url };
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
repo.releases.unshift(release);
|
|
81
|
+
this.save();
|
|
82
|
+
return release;
|
|
83
|
+
}
|
|
84
|
+
newRepository(seed) {
|
|
85
|
+
return { ...super.newRepository(seed), archived: false, has_issues: true };
|
|
86
|
+
}
|
|
87
|
+
setMembership(login, member) {
|
|
88
|
+
this.state.members = this.state.members.filter(
|
|
89
|
+
(value) => value.toLowerCase() !== login.toLowerCase()
|
|
90
|
+
);
|
|
91
|
+
if (member) this.state.members.push(login);
|
|
92
|
+
this.save();
|
|
93
|
+
}
|
|
94
|
+
failNextResponse(operation) {
|
|
95
|
+
this.state.failAfterWrite = operation;
|
|
96
|
+
this.save();
|
|
97
|
+
}
|
|
98
|
+
lostResponse(operation) {
|
|
99
|
+
if (this.state.failAfterWrite !== operation) return;
|
|
100
|
+
this.state.failAfterWrite = null;
|
|
101
|
+
this.save();
|
|
102
|
+
throw new Error(`Local GitHub: response lost after ${operation} write`);
|
|
103
|
+
}
|
|
104
|
+
createIssue(repo, input) {
|
|
105
|
+
const number = this.id();
|
|
106
|
+
const issue = {
|
|
107
|
+
number,
|
|
108
|
+
title: input.title,
|
|
109
|
+
body: input.body ?? "",
|
|
110
|
+
state: "open",
|
|
111
|
+
html_url: `${this.options.baseUrl}/__local#issue-${number}`,
|
|
112
|
+
updated_at: this.timestamp(),
|
|
113
|
+
user: { login: input.author ?? "developer" },
|
|
114
|
+
labels: []
|
|
115
|
+
};
|
|
116
|
+
repo.issues.push(issue);
|
|
117
|
+
this.save();
|
|
118
|
+
return issue;
|
|
119
|
+
}
|
|
120
|
+
setIssueLabel(repo, number, name, actor, present = true) {
|
|
121
|
+
const issue = repo.issues.find((value) => value.number === number);
|
|
122
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
123
|
+
issue.labels = issue.labels.filter((label) => label.name !== name);
|
|
124
|
+
if (present) issue.labels.push({ id: this.id(), name });
|
|
125
|
+
const event = {
|
|
126
|
+
id: this.id(),
|
|
127
|
+
event: present ? "labeled" : "unlabeled",
|
|
128
|
+
label: { name },
|
|
129
|
+
actor: { login: actor }
|
|
130
|
+
};
|
|
131
|
+
repo.labelEvents[number] ??= [];
|
|
132
|
+
repo.labelEvents[number].push(event);
|
|
133
|
+
issue.updated_at = this.timestamp();
|
|
134
|
+
this.save();
|
|
135
|
+
return event;
|
|
136
|
+
}
|
|
137
|
+
editFeedback(repo, number, kind, id, body, editor) {
|
|
138
|
+
const item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);
|
|
139
|
+
if (!item) throw new Error("Unknown local GitHub feedback");
|
|
140
|
+
item.body = body;
|
|
141
|
+
item.createdAt = this.timestamp();
|
|
142
|
+
repo.feedbackEditors[`${kind}:${id}`] = editor;
|
|
143
|
+
this.save();
|
|
144
|
+
}
|
|
145
|
+
client() {
|
|
146
|
+
const profile = {
|
|
147
|
+
apiBaseUrl: this.options.baseUrl,
|
|
148
|
+
token: "",
|
|
149
|
+
botLogin: "leitwerk-bot",
|
|
150
|
+
...this.options.allowedOrganization ? { allowedOrganization: this.options.allowedOrganization } : {}
|
|
151
|
+
};
|
|
152
|
+
const repo = (owner, name) => {
|
|
153
|
+
assertGitHubRepository(profile, owner, name);
|
|
154
|
+
return this.repo(owner, name);
|
|
155
|
+
};
|
|
156
|
+
const client = {
|
|
157
|
+
profile,
|
|
158
|
+
listRepositories: async () => this.state.repositories.map((r) => ({ ...r.repository, archived: false, has_issues: true })).filter(
|
|
159
|
+
(r) => !profile.allowedOrganization || r.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase()
|
|
160
|
+
),
|
|
161
|
+
listOpenIssues: async (owner, name) => structuredClone(repo(owner, name).issues.filter((i) => i.state === "open")),
|
|
162
|
+
listIssueEvents: async (owner, name, number) => structuredClone(repo(owner, name).labelEvents[number] ?? []),
|
|
163
|
+
isOrganizationMember: async (login) => !profile.allowedOrganization || this.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),
|
|
164
|
+
authorizedTrigger: async (owner, name, number, trigger, done) => authorizedTrigger(client, owner, name, number, trigger, done),
|
|
165
|
+
resolveGitIdentity: async (name) => ({
|
|
166
|
+
provider: "github",
|
|
167
|
+
profile: name,
|
|
168
|
+
login: profile.botLogin,
|
|
169
|
+
name: "Sandbox Developer",
|
|
170
|
+
email: "developer@sandbox.invalid"
|
|
171
|
+
}),
|
|
172
|
+
ensureLabel: async (owner, name, labelName) => {
|
|
173
|
+
const r = repo(owner, name);
|
|
174
|
+
let label = r.labels.find((value) => value.name === labelName);
|
|
175
|
+
if (!label) {
|
|
176
|
+
label = { id: this.id(), name: labelName };
|
|
177
|
+
r.labels.push(label);
|
|
178
|
+
this.save();
|
|
179
|
+
this.lostResponse("label");
|
|
180
|
+
}
|
|
181
|
+
return structuredClone(label);
|
|
182
|
+
},
|
|
183
|
+
updateIssue: async (owner, name, number, patch) => {
|
|
184
|
+
const issue = repo(owner, name).issues.find((i) => i.number === number);
|
|
185
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
186
|
+
for (const key of ["title", "body", "state"])
|
|
187
|
+
if (typeof patch[key] === "string") issue[key] = patch[key];
|
|
188
|
+
if (Array.isArray(patch.labels))
|
|
189
|
+
issue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));
|
|
190
|
+
issue.updated_at = this.timestamp();
|
|
191
|
+
this.save();
|
|
192
|
+
this.lostResponse("issue");
|
|
193
|
+
return structuredClone(issue);
|
|
194
|
+
},
|
|
195
|
+
listFeedbackReactions: async (owner, name, kind, id) => structuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),
|
|
196
|
+
addFeedbackReaction: async (owner, name, kind, id) => {
|
|
197
|
+
if (!["conversation", "inline"].includes(kind))
|
|
198
|
+
throw new Error("Reviews do not support reactions");
|
|
199
|
+
const r = repo(owner, name);
|
|
200
|
+
r.reactions[`${kind}:${id}`] ??= [];
|
|
201
|
+
const reactions = r.reactions[`${kind}:${id}`];
|
|
202
|
+
let reaction = reactions.find(
|
|
203
|
+
(r2) => r2.content === "eyes" && r2.user.login === profile.botLogin
|
|
204
|
+
);
|
|
205
|
+
if (!reaction) {
|
|
206
|
+
reaction = { id: this.id(), content: "eyes", user: { login: profile.botLogin } };
|
|
207
|
+
reactions.push(reaction);
|
|
208
|
+
this.save();
|
|
209
|
+
this.lostResponse("reaction");
|
|
210
|
+
}
|
|
211
|
+
return structuredClone(reaction);
|
|
212
|
+
},
|
|
213
|
+
listFeedbackReplies: async (owner, name, number, kind) => kind === "inline" ? structuredClone(
|
|
214
|
+
(repo(owner, name).feedback[number] ?? []).filter((f) => f.kind === "inline").map((f) => ({ ...f }))
|
|
215
|
+
) : client.listIssueComments(owner, name, number),
|
|
216
|
+
replyFeedback: async (owner, name, number, kind, _id, body) => {
|
|
217
|
+
if (kind !== "inline") return client.addIssueComment(owner, name, number, body);
|
|
218
|
+
const value = this.addFeedback(repo(owner, name), number, {
|
|
219
|
+
kind: "inline",
|
|
220
|
+
body,
|
|
221
|
+
author: profile.botLogin
|
|
222
|
+
});
|
|
223
|
+
this.lostResponse("reply");
|
|
224
|
+
return structuredClone(value);
|
|
225
|
+
},
|
|
226
|
+
listActionablePullRequestFeedback: async (owner, name, number, signal) => actionableFeedback(
|
|
227
|
+
client,
|
|
228
|
+
await client.listPullRequestFeedback(owner, name, number, signal)
|
|
229
|
+
),
|
|
230
|
+
getIssue: async (owner, name, number) => {
|
|
231
|
+
const issue = repo(owner, name).issues.find((i) => i.number === number);
|
|
232
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
233
|
+
return structuredClone(issue);
|
|
234
|
+
},
|
|
235
|
+
getCommit: async (owner, name, ref) => ({
|
|
236
|
+
sha: this.git.head(repo(owner, name).repository.ssh_url, ref)
|
|
237
|
+
}),
|
|
238
|
+
isAncestor: async (owner, name, ancestor, descendant) => this.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),
|
|
239
|
+
listIssueComments: async (owner, name, number) => structuredClone(repo(owner, name).comments[number] ?? []),
|
|
240
|
+
addIssueComment: async (owner, name, number, body) => {
|
|
241
|
+
const r = repo(owner, name);
|
|
242
|
+
if (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))
|
|
243
|
+
throw new Error("Unknown local GitHub issue or PR");
|
|
244
|
+
const value = this.newComment(body);
|
|
245
|
+
r.comments[number] ??= [];
|
|
246
|
+
r.comments[number].push(value);
|
|
247
|
+
this.save();
|
|
248
|
+
this.lostResponse("comment");
|
|
249
|
+
return structuredClone(value);
|
|
250
|
+
},
|
|
251
|
+
createPullRequest: async (owner, name, input) => {
|
|
252
|
+
const r = repo(owner, name);
|
|
253
|
+
const pr = this.newPullRequest(r, input);
|
|
254
|
+
r.pulls.push(pr);
|
|
255
|
+
const fail = this.state.failAfterPullRequestWrite;
|
|
256
|
+
this.state.failAfterPullRequestWrite = false;
|
|
257
|
+
this.save();
|
|
258
|
+
if (fail) throw new Error("Local GitHub: response lost after PR creation");
|
|
259
|
+
return this.refresh(r, pr);
|
|
260
|
+
},
|
|
261
|
+
...this.pullRequestClient(repo, "Unknown local GitHub pull request"),
|
|
262
|
+
listPullRequestFeedback: async (owner, name, number) => structuredClone([
|
|
263
|
+
...(repo(owner, name).feedback[number] ?? []).filter((item) => {
|
|
264
|
+
if (!profile.allowedOrganization) return true;
|
|
265
|
+
const editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];
|
|
266
|
+
return editor === void 0 || editor !== null && this.state.members.some((m) => m.toLowerCase() === editor.toLowerCase());
|
|
267
|
+
}),
|
|
268
|
+
...(repo(owner, name).comments[number] ?? []).map((c) => ({
|
|
269
|
+
kind: "conversation",
|
|
270
|
+
id: c.id,
|
|
271
|
+
body: c.body,
|
|
272
|
+
author: c.user.login,
|
|
273
|
+
createdAt: c.created_at
|
|
274
|
+
}))
|
|
275
|
+
]),
|
|
276
|
+
getCheckSummary: async (owner, name, sha) => structuredClone(
|
|
277
|
+
repo(owner, name).checks[sha] ?? {
|
|
278
|
+
headSha: sha,
|
|
279
|
+
status: "pending",
|
|
280
|
+
total: 0,
|
|
281
|
+
failed: []
|
|
282
|
+
}
|
|
283
|
+
),
|
|
284
|
+
listReleases: async (owner, name) => structuredClone(repo(owner, name).releases),
|
|
285
|
+
downloadReleaseAsset: async (asset) => {
|
|
286
|
+
for (const r of this.state.repositories)
|
|
287
|
+
if (r.assets[asset.url] !== void 0) return r.assets[asset.url];
|
|
288
|
+
throw new Error("Unknown local GitHub release asset");
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
return client;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
export {
|
|
295
|
+
LocalGitHubAdapter
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=testing.js.map
|