@leitwerk-dev/github 0.3.1 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { LocalForgeStore, type LocalRepositorySeed } from \"@leitwerk-dev/test-support/local-git\";\nimport { actionableFeedback, authorizedTrigger } from \"./authorization.js\";\nimport type { GitHubClientLike } from \"./capability.js\";\nimport type {\n\tGitHubCheckSummary,\n\tGitHubFeedbackItem,\n\tGitHubIssue,\n\tGitHubLabelEvent,\n\tGitHubProfile,\n\tGitHubPullRequest,\n\tGitHubRelease,\n} from \"./client.js\";\nimport { assertGitHubRepository } from \"./client.js\";\n\n/** @public */\ninterface LocalGitHubRepository {\n\t/** @public */\n\trepository: ReturnType<LocalGitHubAdapter[\"newRepository\"]>;\n\t/** @public */\n\tissues: GitHubIssue[];\n\t/** @public */\n\tpulls: GitHubPullRequest[];\n\t/** @public */\n\tcomments: Record<string, Array<ReturnType<LocalGitHubAdapter[\"newComment\"]>>>;\n\t/** @public */\n\tfeedback: Record<string, GitHubFeedbackItem[]>;\n\t/** @public */\n\tchecks: Record<string, GitHubCheckSummary>;\n\t/** @public */\n\treleases: GitHubRelease[];\n\t/** @public */\n\tassets: Record<string, string>;\n\t/** @public */\n\tlabels: Array<{\n\t\t/** @internal */\n\t\tid: number;\n\t\t/** @internal */\n\t\tname: string;\n\t}>;\n\t/** @public */\n\tlabelEvents: Record<string, GitHubLabelEvent[]>;\n\t/** @public */\n\treactions: Record<\n\t\tstring,\n\t\tArray<{\n\t\t\t/** @internal */\n\t\t\tid: number;\n\t\t\t/** @internal */\n\t\t\tcontent: string;\n\t\t\t/** @internal */\n\t\t\tuser: {\n\t\t\t\t/** @internal */\n\t\t\t\tlogin: string;\n\t\t\t};\n\t\t}>\n\t>;\n\t/** @public */\n\tfeedbackEditors: Record<string, string | null>;\n}\n/** @public */\nexport interface LocalGitHubState {\n\t/** @public */\n\tversion: 1;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\trepositories: LocalGitHubRepository[];\n\t/** @public */\n\tfailAfterPullRequestWrite: boolean;\n\t/** @public */\n\tmembers: string[];\n\t/** @public */\n\tfailAfterWrite: string | null;\n}\n/** @public */\ninterface LocalGitHubOptions {\n\t/** @public */\n\troot: string;\n\t/** @public */\n\tbaseUrl: string;\n\t/** @public */\n\tnow?: () => number;\n\t/** @public */\n\tnextId?: () => number;\n\t/** @public */\n\tseeds?: LocalRepositorySeed[];\n\t/** @public */\n\tallowedOrganization?: string;\n}\n\n/** Persistent local GitHub with actual commit ancestry and configurable release assets. @public */\nexport class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {\n\t/** @public */\n\tconstructor(options: LocalGitHubOptions) {\n\t\tsuper(options, \"github.json\", {\n\t\t\tversion: 1,\n\t\t\tsequence: 0,\n\t\t\trepositories: [],\n\t\t\tfailAfterPullRequestWrite: false,\n\t\t\tmembers: [],\n\t\t\tfailAfterWrite: null,\n\t\t});\n\t\tthis.state.members ??= [];\n\t\tthis.state.failAfterWrite ??= null;\n\t\tfor (const r of this.state.repositories) {\n\t\t\tr.labels ??= [];\n\t\t\tr.labelEvents ??= {};\n\t\t\tr.reactions ??= {};\n\t\t\tr.feedbackEditors ??= {};\n\t\t}\n\t\tfor (const seed of options.seeds ?? []) this.seed(seed);\n\t}\n\t/** @public */\n\trepo(owner: string, name: string) {\n\t\tconst repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);\n\t\tif (!repo) throw new Error(\"Unknown local GitHub repository\");\n\t\treturn repo;\n\t}\n\t/** @public */\n\tseed(seed: LocalRepositorySeed) {\n\t\tconst existing = this.state.repositories.find(\n\t\t\t(r) => r.repository.full_name === `${seed.owner}/${seed.name}`,\n\t\t);\n\t\tif (existing) return existing;\n\t\tconst repo: LocalGitHubRepository = {\n\t\t\trepository: this.newRepository(seed),\n\t\t\tissues: [],\n\t\t\tpulls: [],\n\t\t\tcomments: {},\n\t\t\tfeedback: {},\n\t\t\tchecks: {},\n\t\t\treleases: [],\n\t\t\tassets: {},\n\t\t\tlabels: [],\n\t\t\tlabelEvents: {},\n\t\t\treactions: {},\n\t\t\tfeedbackEditors: {},\n\t\t};\n\t\tthis.state.repositories.push(repo);\n\t\tthis.save();\n\t\treturn repo;\n\t}\n\t/** @public */\n\tsetChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary) {\n\t\tthis.git.head(repo.repository.ssh_url, summary.headSha);\n\t\trepo.checks[summary.headSha] = structuredClone(summary);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tpublishRelease(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttag: string;\n\t\t\t/** @public */\n\t\t\tref: string;\n\t\t\t/** @public */\n\t\t\tassets: Record<string, string>;\n\t\t\t/** @internal */\n\t\t\tdraft?: boolean;\n\t\t\t/** @internal */\n\t\t\tprerelease?: boolean;\n\t\t},\n\t) {\n\t\tconst commit = this.git.head(repo.repository.ssh_url, input.ref);\n\t\tthis.git.run(repo.repository.ssh_url, [\"check-ref-format\", `refs/tags/${input.tag}`]);\n\t\tthis.git.run(repo.repository.ssh_url, [\"tag\", \"--\", input.tag, commit]);\n\t\tconst id = this.id();\n\t\tconst release: GitHubRelease = {\n\t\t\tid,\n\t\t\ttag_name: input.tag,\n\t\t\ttarget_commitish: commit,\n\t\t\tdraft: input.draft ?? false,\n\t\t\tprerelease: input.prerelease ?? false,\n\t\t\thtml_url: `${this.options.baseUrl}/__local`,\n\t\t\tassets: Object.entries(input.assets).map(([name, contents]) => {\n\t\t\t\tconst url = `${this.options.baseUrl}/__local/assets/${this.id()}`;\n\t\t\t\trepo.assets[url] = contents;\n\t\t\t\treturn { name, url, browser_download_url: url };\n\t\t\t}),\n\t\t};\n\t\trepo.releases.unshift(release);\n\t\tthis.save();\n\t\treturn release;\n\t}\n\t/** @public */\n\toverride newRepository(seed: LocalRepositorySeed) {\n\t\treturn {\n\t\t\t...super.newRepository(seed),\n\t\t\t/** @public */\n\t\t\tarchived: false,\n\t\t\t/** @public */\n\t\t\thas_issues: true,\n\t\t};\n\t}\n\t/** @public */\n\tsetMembership(login: string, member: boolean) {\n\t\tthis.state.members = this.state.members.filter(\n\t\t\t(value) => value.toLowerCase() !== login.toLowerCase(),\n\t\t);\n\t\tif (member) this.state.members.push(login);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tfailNextResponse(operation: \"comment\" | \"reply\" | \"reaction\" | \"issue\" | \"label\") {\n\t\tthis.state.failAfterWrite = operation;\n\t\tthis.save();\n\t}\n\tprivate lostResponse(operation: string) {\n\t\tif (this.state.failAfterWrite !== operation) return;\n\t\tthis.state.failAfterWrite = null;\n\t\tthis.save();\n\t\tthrow new Error(`Local GitHub: response lost after ${operation} write`);\n\t}\n\t/** @public */\n\tcreateIssue(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttitle: string;\n\t\t\t/** @public */\n\t\t\tbody?: string;\n\t\t\t/** @public */\n\t\t\tauthor?: string;\n\t\t},\n\t) {\n\t\tconst number = this.id();\n\t\tconst issue: GitHubIssue = {\n\t\t\tnumber,\n\t\t\ttitle: input.title,\n\t\t\tbody: input.body ?? \"\",\n\t\t\tstate: \"open\",\n\t\t\thtml_url: `${this.options.baseUrl}/__local#issue-${number}`,\n\t\t\tupdated_at: this.timestamp(),\n\t\t\tuser: { login: input.author ?? \"developer\" },\n\t\t\tlabels: [],\n\t\t};\n\t\trepo.issues.push(issue);\n\t\tthis.save();\n\t\treturn issue;\n\t}\n\t/** @public */\n\tsetIssueLabel(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tname: string,\n\t\tactor: string,\n\t\tpresent = true,\n\t) {\n\t\tconst issue = repo.issues.find((value) => value.number === number);\n\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\tissue.labels = issue.labels.filter((label) => label.name !== name);\n\t\tif (present) issue.labels.push({ id: this.id(), name });\n\t\tconst event: GitHubLabelEvent = {\n\t\t\tid: this.id(),\n\t\t\tevent: present ? \"labeled\" : \"unlabeled\",\n\t\t\tlabel: { name },\n\t\t\tactor: { login: actor },\n\t\t};\n\t\trepo.labelEvents[number] ??= [];\n\t\trepo.labelEvents[number].push(event);\n\t\tissue.updated_at = this.timestamp();\n\t\tthis.save();\n\t\treturn event;\n\t}\n\t/** @public */\n\teditFeedback(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tkind: GitHubFeedbackItem[\"kind\"],\n\t\tid: number,\n\t\tbody: string,\n\t\teditor: string | null,\n\t) {\n\t\tconst item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);\n\t\tif (!item) throw new Error(\"Unknown local GitHub feedback\");\n\t\titem.body = body;\n\t\titem.createdAt = this.timestamp();\n\t\trepo.feedbackEditors[`${kind}:${id}`] = editor;\n\t\tthis.save();\n\t}\n\n\t/** @public */\n\tclient(): GitHubClientLike {\n\t\tconst profile: GitHubProfile = {\n\t\t\tapiBaseUrl: this.options.baseUrl,\n\t\t\ttoken: \"\",\n\t\t\tbotLogin: \"leitwerk-bot\",\n\t\t\t...(this.options.allowedOrganization\n\t\t\t\t? { allowedOrganization: this.options.allowedOrganization }\n\t\t\t\t: {}),\n\t\t};\n\t\tconst repo = (owner: string, name: string) => {\n\t\t\tassertGitHubRepository(profile, owner, name);\n\t\t\treturn this.repo(owner, name);\n\t\t};\n\t\tconst client: GitHubClientLike = {\n\t\t\tprofile,\n\t\t\tlistRepositories: async () =>\n\t\t\t\tthis.state.repositories\n\t\t\t\t\t.map((r) => ({ ...r.repository, archived: false, has_issues: true }))\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(r) =>\n\t\t\t\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\t\t\t\tr.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase(),\n\t\t\t\t\t),\n\t\t\tlistOpenIssues: async (owner, name) =>\n\t\t\t\tstructuredClone(repo(owner, name).issues.filter((i) => i.state === \"open\")),\n\t\t\tlistIssueEvents: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).labelEvents[number] ?? []),\n\t\t\tisOrganizationMember: async (login) =>\n\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\tthis.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),\n\t\t\tauthorizedTrigger: async (owner, name, number, trigger, done) =>\n\t\t\t\tauthorizedTrigger(client, owner, name, number, trigger, done),\n\t\t\tresolveGitIdentity: async (name) => ({\n\t\t\t\tprovider: \"github\",\n\t\t\t\tprofile: name,\n\t\t\t\tlogin: profile.botLogin,\n\t\t\t\tname: \"Sandbox Developer\",\n\t\t\t\temail: \"developer@sandbox.invalid\",\n\t\t\t}),\n\t\t\tlistLabels: async (owner, name) => structuredClone(repo(owner, name).labels),\n\t\t\tcreateLabel: async (owner, name, labelName) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tlet label = r.labels.find((value) => value.name === labelName);\n\t\t\t\tif (!label) {\n\t\t\t\t\tlabel = { id: this.id(), name: labelName };\n\t\t\t\t\tr.labels.push(label);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"label\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(label);\n\t\t\t},\n\t\t\tensureLabel: async (owner, name, labelName) => {\n\t\t\t\tconst label = repo(owner, name).labels.find((value) => value.name === labelName);\n\t\t\t\treturn label ? structuredClone(label) : client.createLabel(owner, name, labelName);\n\t\t\t},\n\t\t\tupdateIssue: async (owner, name, number, patch) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\tfor (const key of [\"title\", \"body\", \"state\"] as const)\n\t\t\t\t\tif (typeof patch[key] === \"string\") issue[key] = patch[key];\n\t\t\t\tif (Array.isArray(patch.labels))\n\t\t\t\t\tissue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));\n\t\t\t\tissue.updated_at = this.timestamp();\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tlistFeedbackReactions: async (owner, name, kind, id) =>\n\t\t\t\tstructuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),\n\t\t\taddFeedbackReaction: async (owner, name, kind, id) => {\n\t\t\t\tif (![\"conversation\", \"inline\"].includes(kind))\n\t\t\t\t\tthrow new Error(\"Reviews do not support reactions\");\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tr.reactions[`${kind}:${id}`] ??= [];\n\t\t\t\tconst reactions = r.reactions[`${kind}:${id}`];\n\t\t\t\tlet reaction = reactions.find(\n\t\t\t\t\t(r) => r.content === \"eyes\" && r.user.login === profile.botLogin,\n\t\t\t\t);\n\t\t\t\tif (!reaction) {\n\t\t\t\t\treaction = { id: this.id(), content: \"eyes\", user: { login: profile.botLogin } };\n\t\t\t\t\treactions.push(reaction);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"reaction\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(reaction);\n\t\t\t},\n\t\t\tlistFeedbackReplies: async (owner, name, number, kind) =>\n\t\t\t\tkind === \"inline\"\n\t\t\t\t\t? structuredClone(\n\t\t\t\t\t\t\t(repo(owner, name).feedback[number] ?? [])\n\t\t\t\t\t\t\t\t.filter((f) => f.kind === \"inline\")\n\t\t\t\t\t\t\t\t.map((f) => ({ ...f })),\n\t\t\t\t\t\t)\n\t\t\t\t\t: client.listIssueComments(owner, name, number),\n\t\t\treplyFeedback: async (owner, name, number, kind, id, body) => {\n\t\t\t\tif (kind !== \"inline\") return client.addIssueComment(owner, name, number, body);\n\t\t\t\tconst value = this.addFeedback(repo(owner, name), number, {\n\t\t\t\t\tkind: \"inline\",\n\t\t\t\t\tbody,\n\t\t\t\t\tauthor: profile.botLogin,\n\t\t\t\t});\n\t\t\t\tObject.assign(value, { in_reply_to_id: id });\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"reply\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tlistActionablePullRequestFeedback: async (owner, name, number, signal) =>\n\t\t\t\tactionableFeedback(\n\t\t\t\t\tclient,\n\t\t\t\t\tawait client.listPullRequestFeedback(owner, name, number, signal),\n\t\t\t\t),\n\t\t\tgetIssue: async (owner, name, number) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tgetCommit: async (owner, name, ref) => ({\n\t\t\t\tsha: this.git.head(repo(owner, name).repository.ssh_url, ref),\n\t\t\t}),\n\t\t\tisAncestor: async (owner, name, ancestor, descendant) =>\n\t\t\t\tthis.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),\n\t\t\tlistIssueComments: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).comments[number] ?? []),\n\t\t\taddIssueComment: async (owner, name, number, body) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tif (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))\n\t\t\t\t\tthrow new Error(\"Unknown local GitHub issue or PR\");\n\t\t\t\tconst value = this.newComment(body);\n\t\t\t\tr.comments[number] ??= [];\n\t\t\t\tr.comments[number].push(value);\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"comment\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tcreatePullRequest: async (owner, name, input) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tconst pr = this.newPullRequest(r, input);\n\t\t\t\tr.pulls.push(pr);\n\t\t\t\tconst fail = this.state.failAfterPullRequestWrite;\n\t\t\t\tthis.state.failAfterPullRequestWrite = false;\n\t\t\t\tthis.save();\n\t\t\t\tif (fail) throw new Error(\"Local GitHub: response lost after PR creation\");\n\t\t\t\treturn this.refresh(r, pr);\n\t\t\t},\n\t\t\t...this.pullRequestClient(repo, \"Unknown local GitHub pull request\"),\n\t\t\tlistPullRequestFeedback: async (owner, name, number) =>\n\t\t\t\tstructuredClone([\n\t\t\t\t\t...(repo(owner, name).feedback[number] ?? []).filter((item) => {\n\t\t\t\t\t\tif (!profile.allowedOrganization) return true;\n\t\t\t\t\t\tconst editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\teditor === undefined ||\n\t\t\t\t\t\t\t(editor !== null &&\n\t\t\t\t\t\t\t\tthis.state.members.some((m) => m.toLowerCase() === editor.toLowerCase()))\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t\t...(repo(owner, name).comments[number] ?? []).map((c) => ({\n\t\t\t\t\t\tkind: \"conversation\" as const,\n\t\t\t\t\t\tid: c.id,\n\t\t\t\t\t\tbody: c.body,\n\t\t\t\t\t\tauthor: c.user.login,\n\t\t\t\t\t\tcreatedAt: c.created_at,\n\t\t\t\t\t})),\n\t\t\t\t]),\n\t\t\tgetCiDiagnostics: async (owner, name, number, headSha) => {\n\t\t\t\tconst r = this.repo(owner, name);\n\t\t\t\tconst pr = r.pulls.find((p) => p.number === number);\n\t\t\t\tif (!pr || this.git.head(r.repository.ssh_url, pr.head.ref) !== headSha)\n\t\t\t\t\tthrow new Error(\"Stale CI diagnostics\");\n\t\t\t\treturn {\n\t\t\t\t\theadSha,\n\t\t\t\t\tchecks: (r.checks[headSha]?.failed ?? []).map((check, i) => ({\n\t\t\t\t\t\tid: i + 1,\n\t\t\t\t\t\tname: check.name,\n\t\t\t\t\t\toutput: { summary: check.name },\n\t\t\t\t\t\tannotations: [],\n\t\t\t\t\t})),\n\t\t\t\t\tjobs: [],\n\t\t\t\t\ttruncated: false,\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetCheckSummary: async (owner, name, sha) =>\n\t\t\t\tstructuredClone(\n\t\t\t\t\trepo(owner, name).checks[sha] ?? {\n\t\t\t\t\t\theadSha: sha,\n\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\tfailed: [],\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\tlistReleases: async (owner, name) => structuredClone(repo(owner, name).releases),\n\t\t\tdownloadReleaseAsset: async (asset) => {\n\t\t\t\tfor (const r of this.state.repositories)\n\t\t\t\t\tif (r.assets[asset.url] !== undefined) return r.assets[asset.url];\n\t\t\t\tthrow new Error(\"Unknown local GitHub release asset\");\n\t\t\t},\n\t\t};\n\t\treturn client;\n\t}\n}\n"],"mappings":";;;;;;;AAAA,SAAS,uBAAiD;AA2FnD,IAAM,qBAAN,cAAiC,gBAAsD;AAAA;AAAA,EAE7F,YAAY,SAA6B;AACxC,UAAM,SAAS,eAAe;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,cAAc,CAAC;AAAA,MACf,2BAA2B;AAAA,MAC3B,SAAS,CAAC;AAAA,MACV,gBAAgB;AAAA,IACjB,CAAC;AACD,SAAK,MAAM,YAAY,CAAC;AACxB,SAAK,MAAM,mBAAmB;AAC9B,eAAW,KAAK,KAAK,MAAM,cAAc;AACxC,QAAE,WAAW,CAAC;AACd,QAAE,gBAAgB,CAAC;AACnB,QAAE,cAAc,CAAC;AACjB,QAAE,oBAAoB,CAAC;AAAA,IACxB;AACA,eAAW,QAAQ,QAAQ,SAAS,CAAC,EAAG,MAAK,KAAK,IAAI;AAAA,EACvD;AAAA;AAAA,EAEA,KAAK,OAAe,MAAc;AACjC,UAAM,OAAO,KAAK,MAAM,aAAa,KAAK,CAAC,MAAM,EAAE,WAAW,cAAc,GAAG,KAAK,IAAI,IAAI,EAAE;AAC9F,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,iCAAiC;AAC5D,WAAO;AAAA,EACR;AAAA;AAAA,EAEA,KAAK,MAA2B;AAC/B,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AAU,CAAC,GAAG,IAAI,CAAC,OAAO,OAAO;AAAA,YAC5D,IAAI,IAAI;AAAA,YACR,MAAM,MAAM;AAAA,YACZ,QAAQ,EAAE,SAAS,MAAM,KAAK;AAAA,YAC9B,aAAa,CAAC;AAAA,UACf,EAAE;AAAA,UACF,MAAM,CAAC;AAAA,UACP,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,MACA,iBAAiB,OAAO,OAAO,MAAM,QACpC;AAAA,QACC,KAAK,OAAO,IAAI,EAAE,OAAO,GAAG,KAAK;AAAA,UAChC,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,OAAO;AAAA,UACP,QAAQ,CAAC;AAAA,QACV;AAAA,MACD;AAAA,MACD,cAAc,OAAO,OAAO,SAAS,gBAAgB,KAAK,OAAO,IAAI,EAAE,QAAQ;AAAA,MAC/E,sBAAsB,OAAO,UAAU;AACtC,mBAAW,KAAK,KAAK,MAAM;AAC1B,cAAI,EAAE,OAAO,MAAM,GAAG,MAAM,OAAW,QAAO,EAAE,OAAO,MAAM,GAAG;AACjE,cAAM,IAAI,MAAM,oCAAoC;AAAA,MACrD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;","names":["r"]}
1
+ {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { LocalForgeStore, type LocalRepositorySeed } from \"@leitwerk-dev/test-support/local-git\";\nimport { actionableFeedback, authorizedTrigger } from \"./authorization.js\";\nimport type { GitHubClientLike } from \"./capability.js\";\nimport type {\n\tGitHubCheckSummary,\n\tGitHubFeedbackItem,\n\tGitHubIssue,\n\tGitHubLabelEvent,\n\tGitHubProfile,\n\tGitHubPullRequest,\n\tGitHubRelease,\n} from \"./client.js\";\nimport { assertGitHubRepository } from \"./client.js\";\n\n/** @public */\ninterface LocalGitHubRepository {\n\t/** @public */\n\trepository: ReturnType<LocalGitHubAdapter[\"newRepository\"]>;\n\t/** @public */\n\tissues: GitHubIssue[];\n\t/** @public */\n\tpulls: GitHubPullRequest[];\n\t/** @public */\n\tcomments: Record<string, Array<ReturnType<LocalGitHubAdapter[\"newComment\"]>>>;\n\t/** @public */\n\tfeedback: Record<string, GitHubFeedbackItem[]>;\n\t/** @public */\n\tchecks: Record<string, GitHubCheckSummary>;\n\t/** @public */\n\treleases: GitHubRelease[];\n\t/** @public */\n\tassets: Record<string, string>;\n\t/** @public */\n\tlabels: Array<{\n\t\t/** @internal */\n\t\tid: number;\n\t\t/** @internal */\n\t\tname: string;\n\t}>;\n\t/** @public */\n\tlabelEvents: Record<string, GitHubLabelEvent[]>;\n\t/** @public */\n\treactions: Record<\n\t\tstring,\n\t\tArray<{\n\t\t\t/** @internal */\n\t\t\tid: number;\n\t\t\t/** @internal */\n\t\t\tcontent: string;\n\t\t\t/** @internal */\n\t\t\tuser: {\n\t\t\t\t/** @internal */\n\t\t\t\tlogin: string;\n\t\t\t};\n\t\t}>\n\t>;\n\t/** @public */\n\tfeedbackEditors: Record<string, string | null>;\n}\n/** @public */\nexport interface LocalGitHubState {\n\t/** @public */\n\tversion: 1;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\trepositories: LocalGitHubRepository[];\n\t/** @public */\n\tfailAfterPullRequestWrite: boolean;\n\t/** @public */\n\tmembers: string[];\n\t/** @public */\n\tfailAfterWrite: string | null;\n}\n/** @public */\ninterface LocalGitHubOptions {\n\t/** @public */\n\troot: string;\n\t/** @public */\n\tbaseUrl: string;\n\t/** @public */\n\tnow?: () => number;\n\t/** @public */\n\tnextId?: () => number;\n\t/** @public */\n\tseeds?: LocalRepositorySeed[];\n\t/** @public */\n\tallowedOrganization?: string;\n}\n\n/** Persistent local GitHub with actual commit ancestry and configurable release assets. @public */\nexport class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {\n\t/** @public */\n\tconstructor(options: LocalGitHubOptions) {\n\t\tsuper(options, \"github.json\", {\n\t\t\tversion: 1,\n\t\t\tsequence: 0,\n\t\t\trepositories: [],\n\t\t\tfailAfterPullRequestWrite: false,\n\t\t\tmembers: [],\n\t\t\tfailAfterWrite: null,\n\t\t});\n\t\tthis.state.members ??= [];\n\t\tthis.state.failAfterWrite ??= null;\n\t\tfor (const r of this.state.repositories) {\n\t\t\tr.labels ??= [];\n\t\t\tr.labelEvents ??= {};\n\t\t\tr.reactions ??= {};\n\t\t\tr.feedbackEditors ??= {};\n\t\t}\n\t\tfor (const seed of options.seeds ?? []) this.seed(seed);\n\t}\n\t/** @public */\n\trepo(owner: string, name: string) {\n\t\tconst repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);\n\t\tif (!repo) throw new Error(\"Unknown local GitHub repository\");\n\t\treturn repo;\n\t}\n\t/** @public */\n\tseed(seed: LocalRepositorySeed) {\n\t\tconst existing = this.state.repositories.find(\n\t\t\t(r) => r.repository.full_name === `${seed.owner}/${seed.name}`,\n\t\t);\n\t\tif (existing) return existing;\n\t\tconst repo: LocalGitHubRepository = {\n\t\t\trepository: this.newRepository(seed),\n\t\t\tissues: [],\n\t\t\tpulls: [],\n\t\t\tcomments: {},\n\t\t\tfeedback: {},\n\t\t\tchecks: {},\n\t\t\treleases: [],\n\t\t\tassets: {},\n\t\t\tlabels: [],\n\t\t\tlabelEvents: {},\n\t\t\treactions: {},\n\t\t\tfeedbackEditors: {},\n\t\t};\n\t\tthis.state.repositories.push(repo);\n\t\tthis.save();\n\t\treturn repo;\n\t}\n\t/** @public */\n\tsetChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary) {\n\t\tthis.git.head(repo.repository.ssh_url, summary.headSha);\n\t\trepo.checks[summary.headSha] = structuredClone(summary);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tpublishRelease(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttag: string;\n\t\t\t/** @public */\n\t\t\tref: string;\n\t\t\t/** @public */\n\t\t\tassets: Record<string, string>;\n\t\t\t/** @internal */\n\t\t\tdraft?: boolean;\n\t\t\t/** @internal */\n\t\t\tprerelease?: boolean;\n\t\t},\n\t) {\n\t\tconst commit = this.git.head(repo.repository.ssh_url, input.ref);\n\t\tthis.git.run(repo.repository.ssh_url, [\"check-ref-format\", `refs/tags/${input.tag}`]);\n\t\tthis.git.run(repo.repository.ssh_url, [\"tag\", \"--\", input.tag, commit]);\n\t\tconst id = this.id();\n\t\tconst release: GitHubRelease = {\n\t\t\tid,\n\t\t\ttag_name: input.tag,\n\t\t\ttarget_commitish: commit,\n\t\t\tdraft: input.draft ?? false,\n\t\t\tprerelease: input.prerelease ?? false,\n\t\t\thtml_url: `${this.options.baseUrl}/__local`,\n\t\t\tassets: Object.entries(input.assets).map(([name, contents]) => {\n\t\t\t\tconst url = `${this.options.baseUrl}/__local/assets/${this.id()}`;\n\t\t\t\trepo.assets[url] = contents;\n\t\t\t\treturn { name, url, browser_download_url: url };\n\t\t\t}),\n\t\t};\n\t\trepo.releases.unshift(release);\n\t\tthis.save();\n\t\treturn release;\n\t}\n\t/** @public */\n\toverride newRepository(seed: LocalRepositorySeed) {\n\t\treturn {\n\t\t\t...super.newRepository(seed),\n\t\t\t/** @public */\n\t\t\tarchived: false,\n\t\t\t/** @public */\n\t\t\thas_issues: true,\n\t\t};\n\t}\n\t/** @public */\n\tsetMembership(login: string, member: boolean) {\n\t\tthis.state.members = this.state.members.filter(\n\t\t\t(value) => value.toLowerCase() !== login.toLowerCase(),\n\t\t);\n\t\tif (member) this.state.members.push(login);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tfailNextResponse(\n\t\toperation: \"comment\" | \"reply\" | \"reaction\" | \"issue\" | \"label\" | \"create-issue\",\n\t) {\n\t\tthis.state.failAfterWrite = operation;\n\t\tthis.save();\n\t}\n\tprivate lostResponse(operation: string) {\n\t\tif (this.state.failAfterWrite !== operation) return;\n\t\tthis.state.failAfterWrite = null;\n\t\tthis.save();\n\t\tthrow new Error(`Local GitHub: response lost after ${operation} write`);\n\t}\n\t/** @public */\n\tcreateIssue(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttitle: string;\n\t\t\t/** @public */\n\t\t\tbody?: string;\n\t\t\t/** @public */\n\t\t\tauthor?: string;\n\t\t},\n\t) {\n\t\tconst number = this.id();\n\t\tconst issue: GitHubIssue = {\n\t\t\tnumber,\n\t\t\ttitle: input.title,\n\t\t\tbody: input.body ?? \"\",\n\t\t\tstate: \"open\",\n\t\t\thtml_url: `${this.options.baseUrl}/__local/github/receipts/${repo.repository.id}/${number}`,\n\t\t\tupdated_at: this.timestamp(),\n\t\t\tuser: { login: input.author ?? \"developer\" },\n\t\t\tlabels: [],\n\t\t};\n\t\trepo.issues.push(issue);\n\t\tthis.save();\n\t\treturn issue;\n\t}\n\t/** @public */\n\tsetIssueLabel(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tname: string,\n\t\tactor: string,\n\t\tpresent = true,\n\t) {\n\t\tconst issue = repo.issues.find((value) => value.number === number);\n\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\tissue.labels = issue.labels.filter((label) => label.name !== name);\n\t\tif (present) issue.labels.push({ id: this.id(), name });\n\t\tconst event: GitHubLabelEvent = {\n\t\t\tid: this.id(),\n\t\t\tevent: present ? \"labeled\" : \"unlabeled\",\n\t\t\tlabel: { name },\n\t\t\tactor: { login: actor },\n\t\t};\n\t\trepo.labelEvents[number] ??= [];\n\t\trepo.labelEvents[number].push(event);\n\t\tissue.updated_at = this.timestamp();\n\t\tthis.save();\n\t\treturn event;\n\t}\n\t/** @public */\n\teditFeedback(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tkind: GitHubFeedbackItem[\"kind\"],\n\t\tid: number,\n\t\tbody: string,\n\t\teditor: string | null,\n\t) {\n\t\tconst item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);\n\t\tif (!item) throw new Error(\"Unknown local GitHub feedback\");\n\t\titem.body = body;\n\t\titem.createdAt = this.timestamp();\n\t\trepo.feedbackEditors[`${kind}:${id}`] = editor;\n\t\tthis.save();\n\t}\n\n\t/** @public */\n\tclient(): GitHubClientLike {\n\t\tconst profile: GitHubProfile = {\n\t\t\tapiBaseUrl: this.options.baseUrl,\n\t\t\ttoken: \"\",\n\t\t\tbotLogin: \"leitwerk-bot\",\n\t\t\t...(this.options.allowedOrganization\n\t\t\t\t? { allowedOrganization: this.options.allowedOrganization }\n\t\t\t\t: {}),\n\t\t};\n\t\tconst repo = (owner: string, name: string) => {\n\t\t\tassertGitHubRepository(profile, owner, name);\n\t\t\treturn this.repo(owner, name);\n\t\t};\n\t\tconst client: GitHubClientLike = {\n\t\t\tprofile,\n\t\t\tgetRepositoryById: async (id) => {\n\t\t\t\tconst found = this.state.repositories.find((entry) => entry.repository.id === id);\n\t\t\t\tif (!found) throw new Error(\"Unknown local GitHub repository\");\n\t\t\t\treturn {\n\t\t\t\t\t...repo(found.repository.owner.login, found.repository.name).repository,\n\t\t\t\t\tarchived: false,\n\t\t\t\t\thas_issues: true,\n\t\t\t\t};\n\t\t\t},\n\t\t\tlistIssues: async (owner, name) => structuredClone(repo(owner, name).issues),\n\t\t\tcreateIssue: async (owner, name, input) => {\n\t\t\t\tconst issue = this.createIssue(repo(owner, name), input);\n\t\t\t\tissue.labels = input.labels.map((label) => ({ id: this.id(), name: label }));\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"create-issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tlistRepositories: async () =>\n\t\t\t\tthis.state.repositories\n\t\t\t\t\t.map((r) => ({ ...r.repository, archived: false, has_issues: true }))\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(r) =>\n\t\t\t\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\t\t\t\tr.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase(),\n\t\t\t\t\t),\n\t\t\tlistOpenIssues: async (owner, name) =>\n\t\t\t\tstructuredClone(repo(owner, name).issues.filter((i) => i.state === \"open\")),\n\t\t\tlistIssueEvents: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).labelEvents[number] ?? []),\n\t\t\tisOrganizationMember: async (login) =>\n\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\tthis.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),\n\t\t\tauthorizedTrigger: async (owner, name, number, trigger, done) =>\n\t\t\t\tauthorizedTrigger(client, owner, name, number, trigger, done),\n\t\t\tresolveGitIdentity: async (name) => ({\n\t\t\t\tprovider: \"github\",\n\t\t\t\tprofile: name,\n\t\t\t\tlogin: profile.botLogin,\n\t\t\t\tname: \"Sandbox Developer\",\n\t\t\t\temail: \"developer@sandbox.invalid\",\n\t\t\t}),\n\t\t\tlistLabels: async (owner, name) => structuredClone(repo(owner, name).labels),\n\t\t\tcreateLabel: async (owner, name, labelName) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tlet label = r.labels.find((value) => value.name === labelName);\n\t\t\t\tif (!label) {\n\t\t\t\t\tlabel = { id: this.id(), name: labelName };\n\t\t\t\t\tr.labels.push(label);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"label\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(label);\n\t\t\t},\n\t\t\tensureLabel: async (owner, name, labelName) => {\n\t\t\t\tconst label = repo(owner, name).labels.find((value) => value.name === labelName);\n\t\t\t\treturn label ? structuredClone(label) : client.createLabel(owner, name, labelName);\n\t\t\t},\n\t\t\tupdateIssue: async (owner, name, number, patch) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\tfor (const key of [\"title\", \"body\", \"state\"] as const)\n\t\t\t\t\tif (typeof patch[key] === \"string\") issue[key] = patch[key];\n\t\t\t\tif (Array.isArray(patch.labels))\n\t\t\t\t\tissue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));\n\t\t\t\tissue.updated_at = this.timestamp();\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tlistFeedbackReactions: async (owner, name, kind, id) =>\n\t\t\t\tstructuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),\n\t\t\taddFeedbackReaction: async (owner, name, kind, id) => {\n\t\t\t\tif (![\"conversation\", \"inline\"].includes(kind))\n\t\t\t\t\tthrow new Error(\"Reviews do not support reactions\");\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tr.reactions[`${kind}:${id}`] ??= [];\n\t\t\t\tconst reactions = r.reactions[`${kind}:${id}`];\n\t\t\t\tlet reaction = reactions.find(\n\t\t\t\t\t(r) => r.content === \"eyes\" && r.user.login === profile.botLogin,\n\t\t\t\t);\n\t\t\t\tif (!reaction) {\n\t\t\t\t\treaction = { id: this.id(), content: \"eyes\", user: { login: profile.botLogin } };\n\t\t\t\t\treactions.push(reaction);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"reaction\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(reaction);\n\t\t\t},\n\t\t\tlistFeedbackReplies: async (owner, name, number, kind) =>\n\t\t\t\tkind === \"inline\"\n\t\t\t\t\t? structuredClone(\n\t\t\t\t\t\t\t(repo(owner, name).feedback[number] ?? [])\n\t\t\t\t\t\t\t\t.filter((f) => f.kind === \"inline\")\n\t\t\t\t\t\t\t\t.map((f) => ({ ...f })),\n\t\t\t\t\t\t)\n\t\t\t\t\t: client.listIssueComments(owner, name, number),\n\t\t\treplyFeedback: async (owner, name, number, kind, id, body) => {\n\t\t\t\tif (kind !== \"inline\") return client.addIssueComment(owner, name, number, body);\n\t\t\t\tconst value = this.addFeedback(repo(owner, name), number, {\n\t\t\t\t\tkind: \"inline\",\n\t\t\t\t\tbody,\n\t\t\t\t\tauthor: profile.botLogin,\n\t\t\t\t});\n\t\t\t\tObject.assign(value, { in_reply_to_id: id });\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"reply\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tlistActionablePullRequestFeedback: async (owner, name, number, signal) =>\n\t\t\t\tactionableFeedback(\n\t\t\t\t\tclient,\n\t\t\t\t\tawait client.listPullRequestFeedback(owner, name, number, signal),\n\t\t\t\t),\n\t\t\tgetIssue: async (owner, name, number) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tgetCommit: async (owner, name, ref) => ({\n\t\t\t\tsha: this.git.head(repo(owner, name).repository.ssh_url, ref),\n\t\t\t}),\n\t\t\tisAncestor: async (owner, name, ancestor, descendant) =>\n\t\t\t\tthis.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),\n\t\t\tlistIssueComments: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).comments[number] ?? []),\n\t\t\taddIssueComment: async (owner, name, number, body) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tif (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))\n\t\t\t\t\tthrow new Error(\"Unknown local GitHub issue or PR\");\n\t\t\t\tconst value = this.newComment(body);\n\t\t\t\tr.comments[number] ??= [];\n\t\t\t\tr.comments[number].push(value);\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"comment\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tcreatePullRequest: async (owner, name, input) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tconst pr = this.newPullRequest(r, input);\n\t\t\t\tr.pulls.push(pr);\n\t\t\t\tconst fail = this.state.failAfterPullRequestWrite;\n\t\t\t\tthis.state.failAfterPullRequestWrite = false;\n\t\t\t\tthis.save();\n\t\t\t\tif (fail) throw new Error(\"Local GitHub: response lost after PR creation\");\n\t\t\t\treturn this.refresh(r, pr);\n\t\t\t},\n\t\t\t...this.pullRequestClient(repo, \"Unknown local GitHub pull request\"),\n\t\t\tlistPullRequestFeedback: async (owner, name, number) =>\n\t\t\t\tstructuredClone([\n\t\t\t\t\t...(repo(owner, name).feedback[number] ?? []).filter((item) => {\n\t\t\t\t\t\tif (!profile.allowedOrganization) return true;\n\t\t\t\t\t\tconst editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\teditor === undefined ||\n\t\t\t\t\t\t\t(editor !== null &&\n\t\t\t\t\t\t\t\tthis.state.members.some((m) => m.toLowerCase() === editor.toLowerCase()))\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t\t...(repo(owner, name).comments[number] ?? []).map((c) => ({\n\t\t\t\t\t\tkind: \"conversation\" as const,\n\t\t\t\t\t\tid: c.id,\n\t\t\t\t\t\tbody: c.body,\n\t\t\t\t\t\tauthor: c.user.login,\n\t\t\t\t\t\tcreatedAt: c.created_at,\n\t\t\t\t\t})),\n\t\t\t\t]),\n\t\t\tgetCiDiagnostics: async (owner, name, number, headSha) => {\n\t\t\t\tconst r = this.repo(owner, name);\n\t\t\t\tconst pr = r.pulls.find((p) => p.number === number);\n\t\t\t\tif (!pr || this.git.head(r.repository.ssh_url, pr.head.ref) !== headSha)\n\t\t\t\t\tthrow new Error(\"Stale CI diagnostics\");\n\t\t\t\treturn {\n\t\t\t\t\theadSha,\n\t\t\t\t\tchecks: (r.checks[headSha]?.failed ?? []).map((check, i) => ({\n\t\t\t\t\t\tid: i + 1,\n\t\t\t\t\t\tname: check.name,\n\t\t\t\t\t\toutput: { summary: check.name },\n\t\t\t\t\t\tannotations: [],\n\t\t\t\t\t})),\n\t\t\t\t\tjobs: [],\n\t\t\t\t\ttruncated: false,\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetCheckSummary: async (owner, name, sha) =>\n\t\t\t\tstructuredClone(\n\t\t\t\t\trepo(owner, name).checks[sha] ?? {\n\t\t\t\t\t\theadSha: sha,\n\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\tfailed: [],\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\tlistReleases: async (owner, name) => structuredClone(repo(owner, name).releases),\n\t\t\tdownloadReleaseAsset: async (asset) => {\n\t\t\t\tfor (const r of this.state.repositories)\n\t\t\t\t\tif (r.assets[asset.url] !== undefined) return r.assets[asset.url];\n\t\t\t\tthrow new Error(\"Unknown local GitHub release asset\");\n\t\t\t},\n\t\t};\n\t\treturn client;\n\t}\n}\n"],"mappings":";;;;;;;AAAA,SAAS,uBAAiD;AA2FnD,IAAM,qBAAN,cAAiC,gBAAsD;AAAA;AAAA,EAE7F,YAAY,SAA6B;AACxC,UAAM,SAAS,eAAe;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,cAAc,CAAC;AAAA,MACf,2BAA2B;AAAA,MAC3B,SAAS,CAAC;AAAA,MACV,gBAAgB;AAAA,IACjB,CAAC;AACD,SAAK,MAAM,YAAY,CAAC;AACxB,SAAK,MAAM,mBAAmB;AAC9B,eAAW,KAAK,KAAK,MAAM,cAAc;AACxC,QAAE,WAAW,CAAC;AACd,QAAE,gBAAgB,CAAC;AACnB,QAAE,cAAc,CAAC;AACjB,QAAE,oBAAoB,CAAC;AAAA,IACxB;AACA,eAAW,QAAQ,QAAQ,SAAS,CAAC,EAAG,MAAK,KAAK,IAAI;AAAA,EACvD;AAAA;AAAA,EAEA,KAAK,OAAe,MAAc;AACjC,UAAM,OAAO,KAAK,MAAM,aAAa,KAAK,CAAC,MAAM,EAAE,WAAW,cAAc,GAAG,KAAK,IAAI,IAAI,EAAE;AAC9F,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,iCAAiC;AAC5D,WAAO;AAAA,EACR;AAAA;AAAA,EAEA,KAAK,MAA2B;AAC/B,UAAM,WAAW,KAAK,MAAM,aAAa;AAAA,MACxC,CAAC,MAAM,EAAE,WAAW,cAAc,GAAG,K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OAAO,MAAM,GAAG;AACjE,cAAM,IAAI,MAAM,oCAAoC;AAAA,MACrD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;","names":["r"]}
@@ -0,0 +1,5 @@
1
+ import { type ServerExtensionAPI, type TicketCreationConfig } from "@leitwerk-dev/process-sdk";
2
+ import type { GitHubIntegration } from "./capability.js";
3
+ /** @internal */
4
+ export declare function registerGitHubTicketCreation(api: ServerExtensionAPI, integration: GitHubIntegration, config: TicketCreationConfig): void;
5
+ //# sourceMappingURL=ticket-creation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ticket-creation.d.ts","sourceRoot":"","sources":["../src/ticket-creation.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,kBAAkB,EAEvB,KAAK,oBAAoB,EAKzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAmBzD,gBAAgB;AAChB,wBAAgB,4BAA4B,CAC3C,GAAG,EAAE,kBAAkB,EACvB,WAAW,EAAE,iBAAiB,EAC9B,MAAM,EAAE,oBAAoB,GAC1B,IAAI,CA6HN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/github",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "leitwerk": {
6
6
  "extension": {
@@ -25,11 +25,11 @@
25
25
  "build": "tsup && tsc -p tsconfig.tsup.json --emitDeclarationOnly"
26
26
  },
27
27
  "dependencies": {
28
- "@leitwerk-dev/domain": "0.3.1",
29
- "@leitwerk-dev/process-sdk": "0.3.1",
30
- "@leitwerk-dev/watcher-utils": "0.3.1",
31
- "@leitwerk-dev/test-support": "0.3.1",
32
- "@leitwerk-dev/coding": "0.3.1"
28
+ "@leitwerk-dev/domain": "0.4.0",
29
+ "@leitwerk-dev/process-sdk": "0.4.0",
30
+ "@leitwerk-dev/watcher-utils": "0.4.0",
31
+ "@leitwerk-dev/test-support": "0.4.0",
32
+ "@leitwerk-dev/coding": "0.4.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.5.1",
package/src/client.ts CHANGED
@@ -22,6 +22,10 @@ interface GitHubLabel {
22
22
 
23
23
  /** @public */
24
24
  export interface GitHubRepository {
25
+ /** @internal */
26
+ clone_url?: string;
27
+ /** @internal */
28
+ id?: number;
25
29
  /** @public */
26
30
  name: string;
27
31
  /** @internal */
@@ -226,15 +230,40 @@ export class GitHubClient extends RepositoryHttpClient {
226
230
  );
227
231
  }
228
232
  /** @internal */
229
- async listOpenIssues(owner: string, repo: string) {
230
- return (
231
- await this.pages<
232
- GitHubIssue & {
233
- /** @internal */
234
- pull_request?: unknown;
235
- }
236
- >(`${this.repositoryPath(owner, repo)}/issues?state=open`)
237
- ).filter((issue) => !issue.pull_request);
233
+ listOpenIssues(owner: string, repo: string) {
234
+ return this.listIssues(owner, repo, undefined, "open");
235
+ }
236
+ /** @internal */
237
+ async getRepositoryById(id: number, signal?: AbortSignal): Promise<GitHubRepository> {
238
+ const repository = await this.request<GitHubRepository>(`/repositories/${id}`, { signal });
239
+ assertGitHubRepository(this.profile, repository.owner.login, repository.name);
240
+ return repository;
241
+ }
242
+ /** @internal */
243
+ async listIssues(
244
+ owner: string,
245
+ repo: string,
246
+ signal?: AbortSignal,
247
+ state: "open" | "all" = "all",
248
+ ): Promise<GitHubIssue[]> {
249
+ const issues = await this.pages<GitHubIssue & { pull_request?: unknown }>(
250
+ `${this.repositoryPath(owner, repo)}/issues?state=${state}`,
251
+ signal,
252
+ );
253
+ return issues.filter((issue) => !issue.pull_request);
254
+ }
255
+ /** @internal */
256
+ createIssue(
257
+ owner: string,
258
+ repo: string,
259
+ input: {
260
+ /** @internal */ title: string;
261
+ /** @internal */ body: string;
262
+ /** @internal */ labels: string[];
263
+ },
264
+ signal?: AbortSignal,
265
+ ): Promise<GitHubIssue> {
266
+ return this.writeJson(`${this.repositoryPath(owner, repo)}/issues`, "POST", input, signal);
238
267
  }
239
268
  /** @internal */
240
269
  listIssueEvents(owner: string, repo: string, number: number) {
@@ -290,14 +319,15 @@ export class GitHubClient extends RepositoryHttpClient {
290
319
  });
291
320
  }
292
321
  /** @internal */
293
- listLabels(owner: string, repo: string) {
294
- return this.pages<GitHubLabel>(`${this.repositoryPath(owner, repo)}/labels`);
322
+ listLabels(owner: string, repo: string, signal?: AbortSignal) {
323
+ return this.pages<GitHubLabel>(`${this.repositoryPath(owner, repo)}/labels`, signal);
295
324
  }
296
325
  /** @internal */
297
- createLabel(owner: string, repo: string, name: string) {
326
+ createLabel(owner: string, repo: string, name: string, signal?: AbortSignal) {
298
327
  return this.request<GitHubLabel>(`${this.repositoryPath(owner, repo)}/labels`, {
299
328
  method: "POST",
300
329
  body: JSON.stringify({ name, color: "238636" }),
330
+ signal,
301
331
  });
302
332
  }
303
333
  /** @internal */
package/src/external.ts CHANGED
@@ -2,29 +2,23 @@ import { describeConflict } from "@leitwerk-dev/coding/repository-rebase";
2
2
  import {
3
3
  defineExternalActionSource,
4
4
  type ExternalEventDescription,
5
+ type RepositoryFeedbackSourceConfig,
6
+ type RepositoryIssueCancelledSourceConfig,
7
+ type RepositoryPullRequestSourceConfig,
5
8
  } from "@leitwerk-dev/process-sdk";
6
9
 
7
10
  /** @internal */
8
11
  export const GITHUB_PR_STATE_KIND = "@leitwerk-private/github.pr_state";
9
12
 
10
13
  /** @public */
11
- export interface GitHubPullRequestSourceConfig {
12
- /** @public */
13
- profile: string;
14
- /** @public */
15
- owner: string;
16
- /** @public */
17
- repo: string;
18
- /** @public */
19
- prNumber: number;
14
+ export interface GitHubPullRequestSourceConfig
15
+ extends Omit<GitHubPullRequestTerminalSourceConfig, "terminalOutcome" | "disabled"> {
20
16
  /** @public */
21
17
  headSha: string;
22
18
  /** @public */
23
19
  feedbackCursor: number;
24
20
  /** @public */
25
21
  lastConflictKey?: string | null;
26
- /** @public */
27
- pollInterval?: string;
28
22
  /** @internal */
29
23
  disabled?: boolean;
30
24
  /** @public */
@@ -93,50 +87,21 @@ export const GITHUB_PR_FEEDBACK_KIND = "@leitwerk-public/github.pr_feedback";
93
87
  export const GITHUB_ISSUE_CANCELLED_KIND = "@leitwerk-public/github.issue_cancelled";
94
88
 
95
89
  /** @public */
96
- export interface GitHubPullRequestTerminalSourceConfig {
97
- /** @public */
98
- profile: string;
99
- /** @public */
100
- owner: string;
101
- /** @public */
102
- repo: string;
103
- /** @public */
104
- prNumber: number;
105
- /** @public */
106
- pollInterval?: string;
107
- /** @public */
108
- terminalOutcome?: "merged" | "closed";
109
- /** @internal */
110
- disabled?: boolean;
111
- }
90
+ export interface GitHubPullRequestTerminalSourceConfig
91
+ extends Pick<RepositoryPullRequestSourceConfig, "profile" | "owner" | "repo" | "prNumber">,
92
+ Partial<
93
+ Pick<RepositoryPullRequestSourceConfig, "pollInterval" | "terminalOutcome" | "disabled">
94
+ > {}
112
95
 
113
96
  /** @public */
114
- export interface GitHubFeedbackSourceConfig extends GitHubPullRequestTerminalSourceConfig {
115
- /** @public */
116
- conversationCursor: number;
117
- /** @public */
118
- reviewCursor: number;
119
- /** @public */
120
- inlineCursor: number;
121
- /** @public */
122
- quietPeriodMs: number;
123
- }
97
+ export interface GitHubFeedbackSourceConfig
98
+ extends GitHubPullRequestTerminalSourceConfig,
99
+ Omit<RepositoryFeedbackSourceConfig, keyof RepositoryPullRequestSourceConfig> {}
124
100
 
125
101
  /** @public */
126
- export interface GitHubIssueCancelledSourceConfig {
127
- /** @public */
128
- profile: string;
129
- /** @public */
130
- owner: string;
131
- /** @public */
132
- repo: string;
133
- /** @public */
134
- issueNumber: number;
135
- /** @public */
136
- triggerLabel: string;
137
- /** @public */
138
- pollInterval?: string;
139
- }
102
+ export interface GitHubIssueCancelledSourceConfig
103
+ extends Omit<RepositoryIssueCancelledSourceConfig, "pollInterval">,
104
+ Partial<Pick<RepositoryIssueCancelledSourceConfig, "pollInterval">> {}
140
105
 
141
106
  /** @public */
142
107
  export const GITHUB_CHECKS_KIND = "@leitwerk-public/github.checks";
package/src/index.ts CHANGED
@@ -1,7 +1,15 @@
1
- import { coreHostCapabilities, type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
1
+ import {
2
+ coreHostCapabilities,
3
+ type LeitwerkExtensionModule,
4
+ parseTicketCreationConfig,
5
+ repositorySettingsIdentity,
6
+ scopedSettingsCapability,
7
+ type TicketCreationConfig,
8
+ } from "@leitwerk-dev/process-sdk";
2
9
  import { type GitHubIntegration, githubIntegration } from "./capability.js";
3
10
  import { GitHubClient, parseGitHubProfiles } from "./client.js";
4
11
  import { createGitHubProvider } from "./provider.js";
12
+ import { registerGitHubTicketCreation } from "./ticket-creation.js";
5
13
  import { registerGitHubTools } from "./tools.js";
6
14
 
7
15
  /** @internal */
@@ -16,6 +24,23 @@ const extension: LeitwerkExtensionModule = {
16
24
  manifest,
17
25
  setupServer(api, config) {
18
26
  const profiles = parseGitHubProfiles(config);
27
+ const settings = api.get(scopedSettingsCapability);
28
+ if (settings && !Array.isArray(settings))
29
+ settings.registerDiscovery("repository", async () => {
30
+ const subjects = [];
31
+ for (const profile of profiles.values()) {
32
+ for (const repo of await new GitHubClient(profile).listRepositories()) {
33
+ if (repo.id === undefined) continue;
34
+ subjects.push({
35
+ scopeType: "repository",
36
+ identity: repositorySettingsIdentity(repo.html_url, repo.id),
37
+ label: repo.full_name,
38
+ aliases: [repo.ssh_url, ...(repo.clone_url ? [repo.clone_url] : [])],
39
+ });
40
+ }
41
+ }
42
+ return subjects;
43
+ });
19
44
  const integration: GitHubIntegration = {
20
45
  profiles: () => [...profiles.keys()],
21
46
  client(profile) {
@@ -24,7 +49,9 @@ const extension: LeitwerkExtensionModule = {
24
49
  return new GitHubClient(value);
25
50
  },
26
51
  };
27
- setupGitHubIntegration(api, integration);
52
+ setupGitHubIntegration(api, integration, {
53
+ ticketCreation: parseTicketCreationConfig(config, "GitHub"),
54
+ });
28
55
  },
29
56
  };
30
57
 
@@ -37,12 +64,19 @@ export function setupGitHubIntegration(
37
64
  options: {
38
65
  /** @public */
39
66
  now?: () => number;
67
+ /** @internal */
68
+ ticketCreation?: TicketCreationConfig;
40
69
  } = {},
41
70
  ) {
42
71
  api.provide(githubIntegration, integration);
43
72
  const deps = api.get(coreHostCapabilities.serverSetup);
44
73
  if (!deps || Array.isArray(deps)) return;
45
74
  registerGitHubTools(api, integration);
75
+ registerGitHubTicketCreation(
76
+ api,
77
+ integration,
78
+ options.ticketCreation ?? { enabled: false, defaultLabels: [] },
79
+ );
46
80
  return createGitHubProvider(deps, integration, options);
47
81
  }
48
82
 
package/src/testing.ts CHANGED
@@ -202,7 +202,9 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
202
202
  this.save();
203
203
  }
204
204
  /** @public */
205
- failNextResponse(operation: "comment" | "reply" | "reaction" | "issue" | "label") {
205
+ failNextResponse(
206
+ operation: "comment" | "reply" | "reaction" | "issue" | "label" | "create-issue",
207
+ ) {
206
208
  this.state.failAfterWrite = operation;
207
209
  this.save();
208
210
  }
@@ -230,7 +232,7 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
230
232
  title: input.title,
231
233
  body: input.body ?? "",
232
234
  state: "open",
233
- html_url: `${this.options.baseUrl}/__local#issue-${number}`,
235
+ html_url: `${this.options.baseUrl}/__local/github/receipts/${repo.repository.id}/${number}`,
234
236
  updated_at: this.timestamp(),
235
237
  user: { login: input.author ?? "developer" },
236
238
  labels: [],
@@ -296,6 +298,23 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
296
298
  };
297
299
  const client: GitHubClientLike = {
298
300
  profile,
301
+ getRepositoryById: async (id) => {
302
+ const found = this.state.repositories.find((entry) => entry.repository.id === id);
303
+ if (!found) throw new Error("Unknown local GitHub repository");
304
+ return {
305
+ ...repo(found.repository.owner.login, found.repository.name).repository,
306
+ archived: false,
307
+ has_issues: true,
308
+ };
309
+ },
310
+ listIssues: async (owner, name) => structuredClone(repo(owner, name).issues),
311
+ createIssue: async (owner, name, input) => {
312
+ const issue = this.createIssue(repo(owner, name), input);
313
+ issue.labels = input.labels.map((label) => ({ id: this.id(), name: label }));
314
+ this.save();
315
+ this.lostResponse("create-issue");
316
+ return structuredClone(issue);
317
+ },
299
318
  listRepositories: async () =>
300
319
  this.state.repositories
301
320
  .map((r) => ({ ...r.repository, archived: false, has_issues: true }))
@@ -0,0 +1,164 @@
1
+ import {
2
+ listTicketDestinations,
3
+ markdownTicketCreationDefinition,
4
+ numberArg,
5
+ objectArg,
6
+ parseTicketDestinationId,
7
+ type ServerExtensionAPI,
8
+ stringArg,
9
+ type TicketCreationConfig,
10
+ type TicketCreationDestinationProvider,
11
+ type TicketCreationDestinationSnapshot,
12
+ ticketDestinationId,
13
+ ticketLabelNames,
14
+ } from "@leitwerk-dev/process-sdk";
15
+ import type { GitHubIntegration } from "./capability.js";
16
+ import { assertGitHubRepository, type GitHubRepository } from "./client.js";
17
+
18
+ function destinationData(snapshot: TicketCreationDestinationSnapshot) {
19
+ const data = objectArg(snapshot.data);
20
+ return {
21
+ profile: stringArg(data, "profile"),
22
+ baseUrl: stringArg(data, "baseUrl"),
23
+ repositoryId: numberArg(data, "repositoryId"),
24
+ owner: stringArg(data, "owner"),
25
+ repo: stringArg(data, "repo"),
26
+ defaultLabels: ticketLabelNames(data.defaultLabels),
27
+ };
28
+ }
29
+
30
+ function available(repository: GitHubRepository): boolean {
31
+ return !!repository.id && !repository.archived && repository.has_issues;
32
+ }
33
+
34
+ /** @internal */
35
+ export function registerGitHubTicketCreation(
36
+ api: ServerExtensionAPI,
37
+ integration: GitHubIntegration,
38
+ config: TicketCreationConfig,
39
+ ): void {
40
+ if (!config.enabled) return;
41
+ const summary = (profile: string, repository: GitHubRepository) => ({
42
+ id: ticketDestinationId(profile, repository.id ?? 0),
43
+ displayName: repository.full_name,
44
+ group: `${profile} · ${new URL(integration.client(profile).profile.apiBaseUrl).hostname}`,
45
+ description: config.defaultLabels.length
46
+ ? `Default labels: ${config.defaultLabels.join(", ")}`
47
+ : "No default labels",
48
+ });
49
+ const validateDestination = async (
50
+ snapshot: TicketCreationDestinationSnapshot,
51
+ signal?: AbortSignal,
52
+ ) => {
53
+ const data = destinationData(snapshot);
54
+ const client = integration.client(data.profile);
55
+ if (client.profile.apiBaseUrl !== data.baseUrl)
56
+ throw new Error("GitHub profile installation changed");
57
+ assertGitHubRepository(client.profile, data.owner, data.repo);
58
+ const repository = await client.getRepositoryById(data.repositoryId, signal);
59
+ if (
60
+ !available(repository) ||
61
+ repository.owner.login !== data.owner ||
62
+ repository.name !== data.repo
63
+ )
64
+ throw new Error("The selected GitHub repository changed; choose the destination again");
65
+ };
66
+ const destinations: TicketCreationDestinationProvider = {
67
+ list() {
68
+ return listTicketDestinations("GitHub", integration.profiles?.() ?? [], async (profile) =>
69
+ (await integration.client(profile).listRepositories())
70
+ .filter(available)
71
+ .map((repository) => summary(profile, repository)),
72
+ );
73
+ },
74
+ async resolve({ destinationId }) {
75
+ const { profile, resourceId } = parseTicketDestinationId(destinationId);
76
+ const client = integration.client(profile);
77
+ const repository = await client.getRepositoryById(Number(resourceId));
78
+ if (!available(repository))
79
+ throw new Error("The selected GitHub repository cannot accept issues");
80
+ const labels = await client.listLabels(repository.owner.login, repository.name);
81
+ return {
82
+ summary: summary(profile, repository),
83
+ data: {
84
+ profile,
85
+ baseUrl: client.profile.apiBaseUrl,
86
+ repositoryId: repository.id,
87
+ owner: repository.owner.login,
88
+ repo: repository.name,
89
+ defaultLabels: config.defaultLabels,
90
+ },
91
+ agentContext: `Create an issue in ${repository.full_name}. Existing optional labels: ${labels.map((label) => label.name).join(", ") || "none"}.`,
92
+ };
93
+ },
94
+ validate: validateDestination,
95
+ };
96
+ api.tool<Record<string, unknown>>({
97
+ name: "github_create_issue",
98
+ description: "Create one issue in the selected GitHub repository",
99
+ ...markdownTicketCreationDefinition("GitHub", destinations),
100
+ async execute(ctx, args) {
101
+ if (!ctx.ticketDestination) throw new Error("A GitHub ticket destination is required");
102
+ ctx.signal.throwIfAborted();
103
+ await validateDestination(ctx.ticketDestination, ctx.signal);
104
+ ctx.signal.throwIfAborted();
105
+ const target = destinationData(ctx.ticketDestination);
106
+ const client = integration.client(target.profile);
107
+ const title = stringArg(args, "title");
108
+ const body = stringArg(args, "body");
109
+ const requestedLabels = ticketLabelNames(args.labels);
110
+ const labels = await client.listLabels(target.owner, target.repo, ctx.signal);
111
+ const unknown = requestedLabels.filter(
112
+ (name) =>
113
+ !target.defaultLabels.includes(name) && !labels.some((label) => label.name === name),
114
+ );
115
+ if (unknown.length) throw new Error(`Unknown GitHub labels: ${unknown.join(", ")}`);
116
+ for (const name of target.defaultLabels) {
117
+ ctx.signal.throwIfAborted();
118
+ await ctx.externalWrites.ensure(
119
+ { writeType: "github.ensure_label", dedupKey: `${ctx.idempotencyKey}:label:${name}` },
120
+ {
121
+ reconcile: async () =>
122
+ (await client.listLabels(target.owner, target.repo, ctx.signal)).find(
123
+ (label) => label.name === name,
124
+ ) ?? null,
125
+ execute: () => {
126
+ ctx.signal.throwIfAborted();
127
+ return client.createLabel(target.owner, target.repo, name, ctx.signal);
128
+ },
129
+ toMetadata: (label) => ({ id: label.id, name: label.name }),
130
+ },
131
+ );
132
+ }
133
+ const marker = `<!-- leitwerk-ticket-write:${ctx.idempotencyKey} -->`;
134
+ const issue = await ctx.externalWrites.ensure(
135
+ { writeType: "github.create_issue", dedupKey: ctx.idempotencyKey },
136
+ {
137
+ reconcile: async () =>
138
+ (await client.listIssues(target.owner, target.repo, ctx.signal)).find((issue) =>
139
+ issue.body?.includes(marker),
140
+ ) ?? null,
141
+ execute: () => {
142
+ ctx.signal.throwIfAborted();
143
+ return client.createIssue(
144
+ target.owner,
145
+ target.repo,
146
+ {
147
+ title,
148
+ body: `${body}\n\n${marker}`,
149
+ labels: [...new Set([...target.defaultLabels, ...requestedLabels])],
150
+ },
151
+ ctx.signal,
152
+ );
153
+ },
154
+ toMetadata: (issue) => ({ number: issue.number, url: issue.html_url }),
155
+ },
156
+ );
157
+ return {
158
+ externalId: `${target.owner}/${target.repo}#${issue.number}`,
159
+ url: issue.html_url,
160
+ result: issue,
161
+ };
162
+ },
163
+ });
164
+ }