@leitwerk-dev/woodpecker 0.0.0-bootstrap.0 → 0.2.1
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 +83 -1
- package/dist/LICENSE +13 -0
- package/dist/binding.d.ts +4 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/capability.d.ts +11 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/chunk-L6GKOYHO.js +13 -0
- package/dist/chunk-L6GKOYHO.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/external.d.ts +35 -0
- package/dist/external.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +359 -0
- package/dist/index.js.map +1 -0
- package/dist/logs.d.ts +3 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/testing.d.ts +96 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +117 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools.d.ts +4 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +53 -14
- package/src/binding.ts +6 -0
- package/src/capability.ts +14 -0
- package/src/client.ts +178 -0
- package/src/external.ts +45 -0
- package/src/index.ts +52 -0
- package/src/logs.ts +8 -0
- package/src/provider.ts +121 -0
- package/src/testing.ts +172 -0
- package/src/tools.ts +109 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/capability.ts","../src/client.ts","../src/provider.ts","../src/external.ts","../src/tools.ts","../src/binding.ts"],"sourcesContent":["import { coreHostCapabilities, type LeitwerkExtensionModule } from \"@leitwerk-dev/process-sdk\";\nimport { type WoodpeckerIntegration, woodpeckerIntegration } from \"./capability.js\";\nimport { parseWoodpeckerProfiles, WoodpeckerClient } from \"./client.js\";\nimport { createWoodpeckerProvider } from \"./provider.js\";\nimport { registerWoodpeckerTools } from \"./tools.js\";\n\n/** @internal */\nconst manifest = {\n\t/** @internal */\n\tid: \"woodpecker\",\n\t/** @internal */\n\tversion: \"0.1.9\",\n} as const;\n/** @public */\nconst extension: LeitwerkExtensionModule = {\n\tmanifest,\n\tsetupServer(api, config) {\n\t\tconst profiles = parseWoodpeckerProfiles(config);\n\t\tconst integration: WoodpeckerIntegration = {\n\t\t\tclient(profile) {\n\t\t\t\tconst value = profiles.get(profile);\n\t\t\t\tif (!value) throw new Error(`Unknown Woodpecker profile '${profile}'`);\n\t\t\t\treturn new WoodpeckerClient(value);\n\t\t\t},\n\t\t};\n\t\tsetupWoodpeckerIntegration(api, integration);\n\t},\n};\n\nexport type { WoodpeckerIntegration } from \"./capability.js\";\nexport { woodpeckerIntegration } from \"./capability.js\";\nexport type { WoodpeckerPipeline } from \"./client.js\";\nexport { WOODPECKER_PIPELINE_KIND, woodpeckerExternal } from \"./external.js\";\nexport default extension;\n\n/** Register shared tools and polling with an explicit integration. @public */\nexport function setupWoodpeckerIntegration(\n\tapi: Parameters<NonNullable<LeitwerkExtensionModule[\"setupServer\"]>>[0],\n\tintegration: WoodpeckerIntegration,\n\toptions: {\n\t\t/** @public */\n\t\tnow?: () => number;\n\t} = {},\n) {\n\tapi.provide(woodpeckerIntegration, integration);\n\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\tif (!deps || Array.isArray(deps)) return;\n\tregisterWoodpeckerTools(api, integration);\n\treturn createWoodpeckerProvider(deps, integration, options);\n}\n\nexport * from \"./binding.js\";\n","import { createCapabilityToken } from \"@leitwerk-dev/process-sdk\";\nimport type { WoodpeckerClient } from \"./client.js\";\n/** Public contract shared by HTTP and local adapters. @public */\nexport type WoodpeckerClientLike = Pick<WoodpeckerClient, keyof WoodpeckerClient>;\n\n/** @public */\nexport interface WoodpeckerIntegration {\n\t/** @public */\n\tclient(profile: string): WoodpeckerClientLike;\n}\n/** @internal */\nexport const woodpeckerIntegration = createCapabilityToken<WoodpeckerIntegration>(\n\t\"@leitwerk-private/woodpecker.integration\",\n);\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\nimport { IntegrationHttpClient } from \"@leitwerk-dev/process-sdk\";\nimport { boundedLogTail } from \"./logs.js\";\n\n/** @internal */\nexport interface WoodpeckerProfile {\n\t/** @internal */\n\tbaseUrl: string;\n\t/** @internal */\n\ttoken: string;\n}\n/** @public */\nexport interface WoodpeckerRepository {\n\t/** @public */\n\tid: number;\n\t/** @public */\n\tfull_name: string;\n}\n/** @public */\nexport interface WoodpeckerPipeline {\n\t/** @internal */\n\tid: number;\n\t/** @internal */\n\tnumber: number;\n\t/** @internal */\n\tstatus: string;\n\t/** @internal */\n\tevent: string;\n\t/** @internal */\n\tbranch: string;\n\t/** @internal */\n\tcommit: string;\n\t/** @internal */\n\tcreated_at?: number;\n\t/** @internal */\n\tworkflows?: unknown[];\n}\n\ninterface WoodpeckerLogEntry {\n\tdata?: number[] | string;\n}\n\nfunction decodeLogData(data: WoodpeckerLogEntry[\"data\"]): string {\n\tif (Array.isArray(data)) {\n\t\treturn new TextDecoder(\"utf-8\", { fatal: false }).decode(Uint8Array.from(data));\n\t}\n\tif (typeof data !== \"string\") return \"\";\n\tif (/^[A-Za-z0-9+/]*={0,2}$/.test(data) && data.length % 4 === 0) {\n\t\ttry {\n\t\t\tconst binary = atob(data);\n\t\t\treturn new TextDecoder(\"utf-8\", { fatal: false }).decode(\n\t\t\t\tUint8Array.from(binary, (character) => character.charCodeAt(0)),\n\t\t\t);\n\t\t} catch {\n\t\t\t// Preserve an unexpected plain-text representation instead of hiding logs.\n\t\t}\n\t}\n\treturn data;\n}\n\n/** @internal */\nexport function parseWoodpeckerProfiles(value: unknown): Map<string, WoodpeckerProfile> {\n\tconst profiles = new Map<string, WoodpeckerProfile>();\n\tfor (const [name, raw] of Object.entries(\n\t\tasUnknownRecord(asUnknownRecord(value)?.profiles) ?? {},\n\t)) {\n\t\tconst config = asUnknownRecord(raw) ?? {};\n\t\tconst baseUrl = typeof config.base_url === \"string\" ? config.base_url.replace(/\\/+$/, \"\") : \"\";\n\t\tconst token = typeof config.token === \"string\" ? config.token.trim() : \"\";\n\t\tif (!/^https:\\/\\//.test(baseUrl))\n\t\t\tthrow new Error(`Woodpecker profile '${name}' requires an HTTPS base_url`);\n\t\tif (!token) throw new Error(`Woodpecker profile '${name}' requires a token`);\n\t\tprofiles.set(name, { baseUrl, token });\n\t}\n\treturn profiles;\n}\n\n/** @public */\nexport class WoodpeckerClient extends IntegrationHttpClient {\n\t/** @internal */\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly profile: WoodpeckerProfile,\n\t) {\n\t\tsuper(\"Woodpecker\", `${profile.baseUrl}/api`, {\n\t\t\tAuthorization: `Bearer ${profile.token}`,\n\t\t\tAccept: \"application/json\",\n\t\t});\n\t}\n\n\t/** @internal */\n\tlookupRepository(fullName: string, signal?: AbortSignal): Promise<WoodpeckerRepository> {\n\t\treturn this.request(`/repos/lookup/${encodeURIComponent(fullName)}`, {\n\t\t\tsignal,\n\t\t});\n\t}\n\n\t/** @internal */\n\tlistPipelines(\n\t\trepoId: number,\n\t\tsignal?: AbortSignal,\n\t\tpagination: {\n\t\t\t/** @internal */\n\t\t\tpage: number;\n\t\t\t/** @internal */\n\t\t\tperPage?: number;\n\t\t} = { page: 1 },\n\t): Promise<WoodpeckerPipeline[]> {\n\t\tconst { page, perPage = 100 } = pagination;\n\t\tif (\n\t\t\t!Number.isSafeInteger(page) ||\n\t\t\tpage < 1 ||\n\t\t\t!Number.isSafeInteger(perPage) ||\n\t\t\tperPage < 1 ||\n\t\t\tperPage > 100\n\t\t)\n\t\t\tthrow new Error(\"Invalid Woodpecker pipeline pagination\");\n\t\treturn this.request(`/repos/${repoId}/pipelines?page=${page}&perPage=${perPage}`, {\n\t\t\tsignal,\n\t\t});\n\t}\n\n\t/** @internal */\n\tgetPipeline(repoId: number, number: number, signal?: AbortSignal): Promise<WoodpeckerPipeline> {\n\t\treturn this.request(`/repos/${repoId}/pipelines/${number}`, { signal });\n\t}\n\n\t/** @public */\n\tasync getStepLogs(\n\t\trepoId: number,\n\t\tnumber: number,\n\t\tstepId: number,\n\t\ttailLines = 400,\n\t\tmaxBytes = 262_144,\n\t\tsignal?: AbortSignal,\n\t) {\n\t\tconst body = await (\n\t\t\tawait this.response(`/repos/${repoId}/logs/${number}/${stepId}`, {\n\t\t\t\tsignal,\n\t\t\t})\n\t\t).text();\n\t\tlet text = body;\n\t\ttry {\n\t\t\tconst entries = JSON.parse(body) as unknown;\n\t\t\tif (Array.isArray(entries)) {\n\t\t\t\ttext = entries\n\t\t\t\t\t.map((entry) =>\n\t\t\t\t\t\tdecodeLogData(asUnknownRecord(entry)?.data as WoodpeckerLogEntry[\"data\"]).replace(\n\t\t\t\t\t\t\t/\\r?\\n$/,\n\t\t\t\t\t\t\t\"\",\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t}\n\t\t} catch {\n\t\t\t// Older adapters may return text directly; retain it as-is.\n\t\t}\n\t\tconst output = boundedLogTail(text.split(/\\r?\\n/), tailLines, maxBytes);\n\t\treturn {\n\t\t\t/** @public */\n\t\t\tlogs: output,\n\t\t\t/** @internal */\n\t\t\ttruncated: output.length < text.length,\n\t\t};\n\t}\n\n\t/** @internal */\n\trestartPipeline(\n\t\trepoId: number,\n\t\tnumber: number,\n\t\tsignal?: AbortSignal,\n\t): Promise<WoodpeckerPipeline> {\n\t\treturn this.request(`/repos/${repoId}/pipelines/${number}`, {\n\t\t\tmethod: \"POST\",\n\t\t\tsignal,\n\t\t});\n\t}\n}\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\nimport {\n\ttype CoreServerSetupDeps,\n\tcreateExternalSourcePollReporter,\n} from \"@leitwerk-dev/process-sdk\";\nimport { createPollSchedule, emptyPollResult } from \"@leitwerk-dev/watcher-utils\";\nimport type { WoodpeckerClientLike, WoodpeckerIntegration } from \"./capability.js\";\nimport { WOODPECKER_PIPELINE_KIND, type WoodpeckerPipelineSourceConfig } from \"./external.js\";\n\nfunction parse(value: unknown): WoodpeckerPipelineSourceConfig | null {\n\tconst config = asUnknownRecord(value) ?? {};\n\tif (\n\t\t[\"profile\", \"owner\", \"repo\", \"branch\", \"headSha\"].some(\n\t\t\t(key) => typeof config[key] !== \"string\" || !(config[key] as string).trim(),\n\t\t)\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\tbranch: config.branch as string,\n\t\theadSha: config.headSha as string,\n\t\tafterPipelineNumber:\n\t\t\ttypeof config.afterPipelineNumber === \"number\" ? config.afterPipelineNumber : 0,\n\t\tdisabled: config.disabled === true,\n\t\tpollInterval: typeof config.pollInterval === \"string\" ? config.pollInterval : \"30s\",\n\t\tstatuses: Array.isArray(config.statuses)\n\t\t\t? config.statuses.filter((value): value is string => typeof value === \"string\")\n\t\t\t: undefined,\n\t};\n}\nconst terminal = new Set([\n\t\"success\",\n\t\"failure\",\n\t\"error\",\n\t\"killed\",\n\t\"canceled\",\n\t\"cancelled\",\n\t\"declined\",\n\t\"blocked\",\n]);\nconst supportedEvents = new Set([\"push\", \"pull_request\", \"pull_request_closed\"]);\n\nfunction matchesBranch(event: string, pipelineBranch: string, sourceBranch: string): boolean {\n\t// Woodpecker reports the PR target branch in `branch`. The commit uniquely\n\t// identifies the watched source head, so branch filtering only applies to pushes.\n\treturn event !== \"push\" || pipelineBranch === sourceBranch;\n}\n\nexport function createWoodpeckerProvider(\n\tdeps: CoreServerSetupDeps,\n\tintegration: WoodpeckerIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tconst due = createPollSchedule(options.now);\n\treturn deps.polling.create({\n\t\tid: \"woodpecker\",\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 = createExternalSourcePollReporter(deps.externalSources, result);\n\t\t\tawait report.poll(WOODPECKER_PIPELINE_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}`;\n\t\t\t\tif (!due(key, config.pollInterval)) return;\n\t\t\t\tconst client = integration.client(config.profile);\n\t\t\t\tconst repo = await client.lookupRepository(`${config.owner}/${config.repo}`);\n\t\t\t\tconst pipeline = await findLatestPipeline(client, repo.id, config);\n\t\t\t\tif (\n\t\t\t\t\t!pipeline ||\n\t\t\t\t\t!terminal.has(pipeline.status) ||\n\t\t\t\t\t(config.statuses && !config.statuses.includes(pipeline.status))\n\t\t\t\t)\n\t\t\t\t\treturn;\n\t\t\t\tawait report.fire(\n\t\t\t\t\tarmed,\n\t\t\t\t\t{ repositoryId: repo.id, pipeline },\n\t\t\t\t\t`${pipeline.number}:${pipeline.status}`,\n\t\t\t\t);\n\t\t\t});\n\t\t\treturn result;\n\t\t},\n\t});\n}\n\n/** The bounded lookup reports incomplete history instead of waiting silently. */\nexport async function findLatestPipeline(\n\tclient: WoodpeckerClientLike,\n\trepoId: number,\n\tconfig: WoodpeckerPipelineSourceConfig,\n) {\n\tfor (let page = 1; page <= 10; page++) {\n\t\tconst pipelines = (await client.listPipelines(repoId, undefined, { page, perPage: 100 })).sort(\n\t\t\t(a, b) => b.number - a.number,\n\t\t);\n\t\tconst match = pipelines.find(\n\t\t\t(candidate) =>\n\t\t\t\tcandidate.number > (config.afterPipelineNumber ?? 0) &&\n\t\t\t\tcandidate.commit === config.headSha &&\n\t\t\t\tsupportedEvents.has(candidate.event) &&\n\t\t\t\tmatchesBranch(candidate.event, candidate.branch, config.branch),\n\t\t);\n\t\tif (match) return match;\n\t\tif (\n\t\t\tpipelines.length < 100 ||\n\t\t\tpipelines.some((candidate) => candidate.number <= (config.afterPipelineNumber ?? 0))\n\t\t)\n\t\t\treturn null;\n\t}\n\tthrow new Error(\n\t\t\"Woodpecker pipeline lookup window exhausted (1000 pipelines); inspect the repository and update the watched pipeline floor before retrying\",\n\t);\n}\n","import type { ExternalActionSource } from \"@leitwerk-dev/process-sdk\";\n/** @internal */\nexport const WOODPECKER_PIPELINE_KIND = \"@leitwerk-private/woodpecker.pipeline\";\n/** @internal */\nexport interface WoodpeckerPipelineSourceConfig {\n\t/** @internal */\n\tprofile: string;\n\t/** @internal */\n\towner: string;\n\t/** @internal */\n\trepo: string;\n\t/** @internal */\n\tbranch: string;\n\t/** @internal */\n\theadSha: string;\n\t/** @internal */\n\tafterPipelineNumber?: number;\n\t/** @internal */\n\tdisabled?: boolean;\n\t/** @internal */\n\tpollInterval?: string;\n\t/** @internal */\n\tstatuses?: string[];\n}\n/** @internal */\nexport const woodpeckerExternal = {\n\t/** @internal */\n\tpipeline<TParams, TState>(\n\t\tresolve: (ctx: {\n\t\t\t/** @internal */\n\t\t\tparams: TParams;\n\t\t\t/** @internal */\n\t\t\tstate: TState;\n\t\t}) => WoodpeckerPipelineSourceConfig,\n\t): ExternalActionSource<TParams, TState> {\n\t\treturn {\n\t\t\tkind: WOODPECKER_PIPELINE_KIND,\n\t\t\tlabel: \"Woodpecker pipeline completion\",\n\t\t\tdescription: \"Fires when a pipeline matching the current source head completes\",\n\t\t\tconfig: {},\n\t\t\tinputMode: \"none\",\n\t\t\tresolve,\n\t\t};\n\t},\n};\n","import {\n\ttype IntegrationToolExecutionContext,\n\tnumberArg,\n\tprojectParameters,\n\ttype ServerExtensionAPI,\n\tstringArg,\n} from \"@leitwerk-dev/process-sdk\";\nimport { resolveWoodpeckerProjectBinding } from \"./binding.js\";\nimport type { WoodpeckerIntegration } from \"./capability.js\";\n\nfunction target(ctx: IntegrationToolExecutionContext) {\n\tconst binding = resolveWoodpeckerProjectBinding(ctx);\n\treturn { fullName: `${binding.owner}/${binding.repo}`, profile: binding.profile };\n}\n\nexport function registerWoodpeckerTools(\n\tapi: ServerExtensionAPI,\n\tintegration: WoodpeckerIntegration,\n) {\n\tconst schema = projectParameters();\n\tapi.tool<Record<string, unknown>>({\n\t\tname: \"woodpecker_lookup_repository\",\n\t\tdescription: \"Resolve the current process repository in Woodpecker\",\n\t\tparameters: schema,\n\t\tasync execute(ctx) {\n\t\t\tconst t = target(ctx);\n\t\t\treturn integration.client(t.profile).lookupRepository(t.fullName, ctx.signal);\n\t\t},\n\t});\n\tapi.tool<Record<string, unknown>>({\n\t\tname: \"woodpecker_list_pipelines\",\n\t\tdescription: \"List recent Woodpecker pipelines for the current process repository\",\n\t\tparameters: schema,\n\t\tasync execute(ctx) {\n\t\t\tconst t = target(ctx);\n\t\t\tconst client = integration.client(t.profile);\n\t\t\tconst repo = await client.lookupRepository(t.fullName, ctx.signal);\n\t\t\treturn client.listPipelines(repo.id, ctx.signal);\n\t\t},\n\t});\n\tfor (const name of [\"woodpecker_get_pipeline\", \"woodpecker_restart_pipeline\"] as const) {\n\t\tapi.tool<Record<string, unknown>>({\n\t\t\tname,\n\t\t\tdescription: name.endsWith(\"restart_pipeline\")\n\t\t\t\t? \"Restart a diagnosed Woodpecker pipeline\"\n\t\t\t\t: \"Read a Woodpecker pipeline\",\n\t\t\tparameters: projectParameters({\n\t\t\t\tpipelineNumber: { type: \"integer\" },\n\t\t\t\t...(name === \"woodpecker_restart_pipeline\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tdiagnosis: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\"Why this is an infrastructure or flaky failure rather than a repository defect\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tlogEvidence: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\tdescription: \"Concrete bounded-log evidence supporting a restart\",\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}),\n\t\t\tasync execute(ctx, args) {\n\t\t\t\tconst t = target(ctx);\n\t\t\t\tconst client = integration.client(t.profile);\n\t\t\t\tconst repo = await client.lookupRepository(t.fullName, ctx.signal);\n\t\t\t\tconst number = numberArg(args, \"pipelineNumber\");\n\t\t\t\tif (name === \"woodpecker_get_pipeline\")\n\t\t\t\t\treturn client.getPipeline(repo.id, number, ctx.signal);\n\t\t\t\tconst diagnosis = stringArg(args, \"diagnosis\");\n\t\t\t\tconst logEvidence = stringArg(args, \"logEvidence\");\n\t\t\t\tawait ctx.externalWrites.logOnly(\n\t\t\t\t\t{ writeType: \"woodpecker.restart\", dedupKey: ctx.idempotencyKey },\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tawait client.restartPipeline(repo.id, number, ctx.signal);\n\t\t\t\t\t\treturn { repoId: repo.id, number, diagnosis, logEvidence };\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn { ok: true };\n\t\t\t},\n\t\t});\n\t}\n\tapi.tool<Record<string, unknown>>({\n\t\tname: \"woodpecker_get_step_logs\",\n\t\tdescription: \"Read bounded logs for a Woodpecker pipeline step\",\n\t\tparameters: projectParameters(\n\t\t\t{\n\t\t\t\tpipelineNumber: { type: \"integer\" },\n\t\t\t\tstepId: { type: \"integer\" },\n\t\t\t\ttailLines: { type: \"integer\" },\n\t\t\t\tmaxBytes: { type: \"integer\" },\n\t\t\t},\n\t\t\t[\"pipelineNumber\", \"stepId\"],\n\t\t),\n\t\tasync execute(ctx, args) {\n\t\t\tconst t = target(ctx);\n\t\t\tconst client = integration.client(t.profile);\n\t\t\tconst repo = await client.lookupRepository(t.fullName, ctx.signal);\n\t\t\treturn client.getStepLogs(\n\t\t\t\trepo.id,\n\t\t\t\tnumberArg(args, \"pipelineNumber\"),\n\t\t\t\tnumberArg(args, \"stepId\"),\n\t\t\t\ttypeof args.tailLines === \"number\" ? args.tailLines : 400,\n\t\t\t\ttypeof args.maxBytes === \"number\" ? args.maxBytes : 262_144,\n\t\t\t\tctx.signal,\n\t\t\t);\n\t\t},\n\t});\n}\n","import { resolveRepositoryProjectBinding } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport const resolveWoodpeckerProjectBinding = (\n\tctx: Parameters<typeof resolveRepositoryProjectBinding>[0],\n) => resolveRepositoryProjectBinding(ctx, \"woodpecker\", \"forgejo\");\n"],"mappings":";;;;;AAAA,SAAS,4BAA0D;;;ACAnE,SAAS,6BAA6B;AAW/B,IAAM,wBAAwB;AAAA,EACpC;AACD;;;ACbA,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAyCtC,SAAS,cAAc,MAA0C;AAChE,MAAI,MAAM,QAAQ,IAAI,GAAG;AACxB,WAAO,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,EAAE,OAAO,WAAW,KAAK,IAAI,CAAC;AAAA,EAC/E;AACA,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,MAAI,yBAAyB,KAAK,IAAI,KAAK,KAAK,SAAS,MAAM,GAAG;AACjE,QAAI;AACH,YAAM,SAAS,KAAK,IAAI;AACxB,aAAO,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,EAAE;AAAA,QACjD,WAAW,KAAK,QAAQ,CAAC,cAAc,UAAU,WAAW,CAAC,CAAC;AAAA,MAC/D;AAAA,IACD,QAAQ;AAAA,IAER;AAAA,EACD;AACA,SAAO;AACR;AAGO,SAAS,wBAAwB,OAAgD;AACvF,QAAM,WAAW,oBAAI,IAA+B;AACpD,aAAW,CAAC,MAAM,GAAG,KAAK,OAAO;AAAA,IAChC,gBAAgB,gBAAgB,KAAK,GAAG,QAAQ,KAAK,CAAC;AAAA,EACvD,GAAG;AACF,UAAM,SAAS,gBAAgB,GAAG,KAAK,CAAC;AACxC,UAAM,UAAU,OAAO,OAAO,aAAa,WAAW,OAAO,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAC5F,UAAM,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,MA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AAA,QACpD,IAAI;AAAA,MACL;AAAA,IACD;AAAA,EACD,CAAC;AACF;;;ALrGA,IAAM,WAAW;AAAA;AAAA,EAEhB,IAAI;AAAA;AAAA,EAEJ,SAAS;AACV;AAEA,IAAM,YAAqC;AAAA,EAC1C;AAAA,EACA,YAAY,KAAK,QAAQ;AACxB,UAAM,WAAW,wBAAwB,MAAM;AAC/C,UAAM,cAAqC;AAAA,MAC1C,OAAO,SAAS;AACf,cAAM,QAAQ,SAAS,IAAI,OAAO;AAClC,YAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B,OAAO,GAAG;AACrE,eAAO,IAAI,iBAAiB,KAAK;AAAA,MAClC;AAAA,IACD;AACA,+BAA2B,KAAK,WAAW;AAAA,EAC5C;AACD;AAMA,IAAO,gBAAQ;AAGR,SAAS,2BACf,KACA,aACA,UAGI,CAAC,GACJ;AACD,MAAI,QAAQ,uBAAuB,WAAW;AAC9C,QAAM,OAAO,IAAI,IAAI,qBAAqB,WAAW;AACrD,MAAI,CAAC,QAAQ,MAAM,QAAQ,IAAI,EAAG;AAClC,0BAAwB,KAAK,WAAW;AACxC,SAAO,yBAAyB,MAAM,aAAa,OAAO;AAC3D;","names":["asUnknownRecord","asUnknownRecord","value"]}
|
package/dist/logs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM3F"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CoreServerSetupDeps } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { WoodpeckerClientLike, WoodpeckerIntegration } from "./capability.js";
|
|
3
|
+
import { type WoodpeckerPipelineSourceConfig } from "./external.js";
|
|
4
|
+
export declare function createWoodpeckerProvider(deps: CoreServerSetupDeps, integration: WoodpeckerIntegration, options?: {
|
|
5
|
+
now?: () => number;
|
|
6
|
+
}): {
|
|
7
|
+
poll(): Promise<import("@leitwerk-dev/watcher-utils").PollResult>;
|
|
8
|
+
};
|
|
9
|
+
/** The bounded lookup reports incomplete history instead of waiting silently. */
|
|
10
|
+
export declare function findLatestPipeline(client: WoodpeckerClientLike, repoId: number, config: WoodpeckerPipelineSourceConfig): Promise<import("./client.js").WoodpeckerPipeline | null>;
|
|
11
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,mBAAmB,EAExB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAA4B,KAAK,8BAA8B,EAAE,MAAM,eAAe,CAAC;AA2C9F,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,mBAAmB,EACzB,WAAW,EAAE,qBAAqB,EAClC,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO;;EAsCpC;AAED,iFAAiF;AACjF,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,8BAA8B,4DAuBtC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { LocalProviderStore } from "@leitwerk-dev/test-support/local-git";
|
|
2
|
+
import type { WoodpeckerClientLike } from "./capability.js";
|
|
3
|
+
import type { WoodpeckerPipeline, WoodpeckerRepository } from "./client.js";
|
|
4
|
+
/** @public */
|
|
5
|
+
interface LocalWoodpeckerRepository {
|
|
6
|
+
/** @public */
|
|
7
|
+
repository: WoodpeckerRepository;
|
|
8
|
+
/** @public */
|
|
9
|
+
pipelines: Array<WoodpeckerPipeline & {
|
|
10
|
+
/** @internal */
|
|
11
|
+
logs: string;
|
|
12
|
+
/** @internal */
|
|
13
|
+
controlKey?: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/** @public */
|
|
17
|
+
export interface LocalWoodpeckerState {
|
|
18
|
+
/** @public */
|
|
19
|
+
version: 1;
|
|
20
|
+
/** @public */
|
|
21
|
+
sequence: number;
|
|
22
|
+
/** @public */
|
|
23
|
+
repositories: LocalWoodpeckerRepository[];
|
|
24
|
+
}
|
|
25
|
+
/** @public */
|
|
26
|
+
interface LocalWoodpeckerOptions {
|
|
27
|
+
/** @public */
|
|
28
|
+
root: string;
|
|
29
|
+
/** @public */
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
/** @public */
|
|
32
|
+
now?: () => number;
|
|
33
|
+
/** @public */
|
|
34
|
+
nextId?: () => number;
|
|
35
|
+
}
|
|
36
|
+
/** Local CI state is independent of the repository's Git host. @public */
|
|
37
|
+
export declare class LocalWoodpeckerAdapter extends LocalProviderStore<LocalWoodpeckerState, LocalWoodpeckerOptions> {
|
|
38
|
+
/** @public */
|
|
39
|
+
constructor(options: LocalWoodpeckerOptions);
|
|
40
|
+
/** @public */
|
|
41
|
+
seed(fullName: string, id?: number): LocalWoodpeckerRepository;
|
|
42
|
+
/** @public */
|
|
43
|
+
publish(repo: LocalWoodpeckerRepository, input: {
|
|
44
|
+
/** @public */
|
|
45
|
+
branch: string;
|
|
46
|
+
/** @public */
|
|
47
|
+
commit: string;
|
|
48
|
+
/** @public */
|
|
49
|
+
status: string;
|
|
50
|
+
/** @public */
|
|
51
|
+
logs: string;
|
|
52
|
+
/** @internal */
|
|
53
|
+
event?: string;
|
|
54
|
+
/** @internal */
|
|
55
|
+
controlKey?: string;
|
|
56
|
+
}): {
|
|
57
|
+
/** @internal */
|
|
58
|
+
id: number;
|
|
59
|
+
/** @public */
|
|
60
|
+
number: number;
|
|
61
|
+
/** @internal */
|
|
62
|
+
event: string;
|
|
63
|
+
/** @internal */
|
|
64
|
+
created_at: number;
|
|
65
|
+
/** @internal */
|
|
66
|
+
workflows: {
|
|
67
|
+
/** @internal */
|
|
68
|
+
id: number;
|
|
69
|
+
/** @internal */
|
|
70
|
+
name: string;
|
|
71
|
+
/** @internal */
|
|
72
|
+
steps: {
|
|
73
|
+
/** @internal */
|
|
74
|
+
id: number;
|
|
75
|
+
/** @internal */
|
|
76
|
+
name: string;
|
|
77
|
+
/** @internal */
|
|
78
|
+
state: string;
|
|
79
|
+
}[];
|
|
80
|
+
}[];
|
|
81
|
+
/** @public */
|
|
82
|
+
branch: string;
|
|
83
|
+
/** @public */
|
|
84
|
+
commit: string;
|
|
85
|
+
/** @public */
|
|
86
|
+
status: string;
|
|
87
|
+
/** @public */
|
|
88
|
+
logs: string;
|
|
89
|
+
/** @internal */
|
|
90
|
+
controlKey?: string;
|
|
91
|
+
};
|
|
92
|
+
/** @public */
|
|
93
|
+
client(): WoodpeckerClientLike;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
96
|
+
//# 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,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG5E,cAAc;AACd,UAAU,yBAAyB;IAClC,cAAc;IACd,UAAU,EAAE,oBAAoB,CAAC;IACjC,cAAc;IACd,SAAS,EAAE,KAAK,CACf,kBAAkB,GAAG;QACpB,gBAAgB;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,gBAAgB;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,CACD,CAAC;CACF;AACD,cAAc;AACd,MAAM,WAAW,oBA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AM,IAAI,oBAAoB;CAsC9B"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boundedLogTail
|
|
3
|
+
} from "./chunk-L6GKOYHO.js";
|
|
4
|
+
|
|
5
|
+
// src/testing.ts
|
|
6
|
+
import { LocalProviderStore } from "@leitwerk-dev/test-support/local-git";
|
|
7
|
+
var LocalWoodpeckerAdapter = class extends LocalProviderStore {
|
|
8
|
+
/** @public */
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options, "woodpecker.json", {
|
|
11
|
+
version: 1,
|
|
12
|
+
sequence: 0,
|
|
13
|
+
repositories: []
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** @public */
|
|
17
|
+
seed(fullName, id) {
|
|
18
|
+
const existing = this.state.repositories.find((r) => r.repository.full_name === fullName);
|
|
19
|
+
if (existing) return existing;
|
|
20
|
+
const repo = { repository: { id: id ?? this.id(), full_name: fullName }, pipelines: [] };
|
|
21
|
+
this.state.sequence = Math.max(this.state.sequence, repo.repository.id);
|
|
22
|
+
this.state.repositories.push(repo);
|
|
23
|
+
this.save();
|
|
24
|
+
return repo;
|
|
25
|
+
}
|
|
26
|
+
/** @public */
|
|
27
|
+
publish(repo, input) {
|
|
28
|
+
if (![
|
|
29
|
+
"pending",
|
|
30
|
+
"running",
|
|
31
|
+
"success",
|
|
32
|
+
"failure",
|
|
33
|
+
"error",
|
|
34
|
+
"killed",
|
|
35
|
+
"canceled",
|
|
36
|
+
"cancelled",
|
|
37
|
+
"declined",
|
|
38
|
+
"blocked"
|
|
39
|
+
].includes(input.status))
|
|
40
|
+
throw new Error("Invalid pipeline status");
|
|
41
|
+
const number = this.id();
|
|
42
|
+
const pipeline = {
|
|
43
|
+
...input,
|
|
44
|
+
/** @internal */
|
|
45
|
+
id: number,
|
|
46
|
+
/** @public */
|
|
47
|
+
number,
|
|
48
|
+
/** @internal */
|
|
49
|
+
event: input.event ?? "push",
|
|
50
|
+
/** @internal */
|
|
51
|
+
created_at: Math.floor((this.options.now?.() ?? Date.now()) / 1e3),
|
|
52
|
+
/** @internal */
|
|
53
|
+
workflows: [
|
|
54
|
+
{
|
|
55
|
+
/** @internal */
|
|
56
|
+
id: 1,
|
|
57
|
+
/** @internal */
|
|
58
|
+
name: "local",
|
|
59
|
+
/** @internal */
|
|
60
|
+
steps: [
|
|
61
|
+
{
|
|
62
|
+
/** @internal */
|
|
63
|
+
id: 1,
|
|
64
|
+
/** @internal */
|
|
65
|
+
name: "validation",
|
|
66
|
+
/** @internal */
|
|
67
|
+
state: input.status
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
repo.pipelines.push(pipeline);
|
|
74
|
+
this.save();
|
|
75
|
+
return pipeline;
|
|
76
|
+
}
|
|
77
|
+
/** @public */
|
|
78
|
+
client() {
|
|
79
|
+
const repo = (id) => {
|
|
80
|
+
const value = this.state.repositories.find((r) => r.repository.id === id);
|
|
81
|
+
if (!value) throw new Error("Unknown local CI repository");
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
const pipeline = (id, number) => {
|
|
85
|
+
const value = repo(id).pipelines.find((p) => p.number === number);
|
|
86
|
+
if (!value) throw new Error("Unknown local pipeline");
|
|
87
|
+
return value;
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
profile: { baseUrl: this.options.baseUrl, token: "" },
|
|
91
|
+
lookupRepository: async (name) => {
|
|
92
|
+
const value = this.state.repositories.find((r) => r.repository.full_name === name);
|
|
93
|
+
if (!value) throw new Error("Unknown local CI repository");
|
|
94
|
+
return structuredClone(value.repository);
|
|
95
|
+
},
|
|
96
|
+
listPipelines: async (id, _signal, { page = 1, perPage = 100 } = { page: 1 }) => structuredClone(
|
|
97
|
+
[...repo(id).pipelines].sort((a, b) => b.number - a.number).slice((page - 1) * perPage, page * perPage)
|
|
98
|
+
),
|
|
99
|
+
getPipeline: async (id, number) => structuredClone(pipeline(id, number)),
|
|
100
|
+
getStepLogs: async (id, number, _step, tail = 400, bytes = 262144) => {
|
|
101
|
+
const original = pipeline(id, number).logs;
|
|
102
|
+
const logs = boundedLogTail(original.split("\n"), tail, bytes);
|
|
103
|
+
return { logs, truncated: logs !== original };
|
|
104
|
+
},
|
|
105
|
+
restartPipeline: async (id, number) => {
|
|
106
|
+
const value = pipeline(id, number);
|
|
107
|
+
value.status = "pending";
|
|
108
|
+
this.save();
|
|
109
|
+
return structuredClone(value);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export {
|
|
115
|
+
LocalWoodpeckerAdapter
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { LocalProviderStore } from \"@leitwerk-dev/test-support/local-git\";\nimport type { WoodpeckerClientLike } from \"./capability.js\";\nimport type { WoodpeckerPipeline, WoodpeckerRepository } from \"./client.js\";\nimport { boundedLogTail } from \"./logs.js\";\n\n/** @public */\ninterface LocalWoodpeckerRepository {\n\t/** @public */\n\trepository: WoodpeckerRepository;\n\t/** @public */\n\tpipelines: Array<\n\t\tWoodpeckerPipeline & {\n\t\t\t/** @internal */\n\t\t\tlogs: string;\n\t\t\t/** @internal */\n\t\t\tcontrolKey?: string;\n\t\t}\n\t>;\n}\n/** @public */\nexport interface LocalWoodpeckerState {\n\t/** @public */\n\tversion: 1;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\trepositories: LocalWoodpeckerRepository[];\n}\n/** @public */\ninterface LocalWoodpeckerOptions {\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}\n\n/** Local CI state is independent of the repository's Git host. @public */\nexport class LocalWoodpeckerAdapter extends LocalProviderStore<\n\tLocalWoodpeckerState,\n\tLocalWoodpeckerOptions\n> {\n\t/** @public */\n\tconstructor(options: LocalWoodpeckerOptions) {\n\t\tsuper(options, \"woodpecker.json\", {\n\t\t\tversion: 1,\n\t\t\tsequence: 0,\n\t\t\trepositories: [],\n\t\t});\n\t}\n\t/** @public */\n\tseed(fullName: string, id?: number) {\n\t\tconst existing = this.state.repositories.find((r) => r.repository.full_name === fullName);\n\t\tif (existing) return existing;\n\t\tconst repo = { repository: { id: id ?? this.id(), full_name: fullName }, pipelines: [] };\n\t\tthis.state.sequence = Math.max(this.state.sequence, repo.repository.id);\n\t\tthis.state.repositories.push(repo);\n\t\tthis.save();\n\t\treturn repo;\n\t}\n\t/** @public */\n\tpublish(\n\t\trepo: LocalWoodpeckerRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\tbranch: string;\n\t\t\t/** @public */\n\t\t\tcommit: string;\n\t\t\t/** @public */\n\t\t\tstatus: string;\n\t\t\t/** @public */\n\t\t\tlogs: string;\n\t\t\t/** @internal */\n\t\t\tevent?: string;\n\t\t\t/** @internal */\n\t\t\tcontrolKey?: string;\n\t\t},\n\t) {\n\t\tif (\n\t\t\t![\n\t\t\t\t\"pending\",\n\t\t\t\t\"running\",\n\t\t\t\t\"success\",\n\t\t\t\t\"failure\",\n\t\t\t\t\"error\",\n\t\t\t\t\"killed\",\n\t\t\t\t\"canceled\",\n\t\t\t\t\"cancelled\",\n\t\t\t\t\"declined\",\n\t\t\t\t\"blocked\",\n\t\t\t].includes(input.status)\n\t\t)\n\t\t\tthrow new Error(\"Invalid pipeline status\");\n\t\tconst number = this.id();\n\t\tconst pipeline = {\n\t\t\t...input,\n\t\t\t/** @internal */\n\t\t\tid: number,\n\t\t\t/** @public */\n\t\t\tnumber,\n\t\t\t/** @internal */\n\t\t\tevent: input.event ?? \"push\",\n\t\t\t/** @internal */\n\t\t\tcreated_at: Math.floor((this.options.now?.() ?? Date.now()) / 1000),\n\t\t\t/** @internal */\n\t\t\tworkflows: [\n\t\t\t\t{\n\t\t\t\t\t/** @internal */\n\t\t\t\t\tid: 1,\n\t\t\t\t\t/** @internal */\n\t\t\t\t\tname: \"local\",\n\t\t\t\t\t/** @internal */\n\t\t\t\t\tsteps: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/** @internal */\n\t\t\t\t\t\t\tid: 1,\n\t\t\t\t\t\t\t/** @internal */\n\t\t\t\t\t\t\tname: \"validation\",\n\t\t\t\t\t\t\t/** @internal */\n\t\t\t\t\t\t\tstate: input.status,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t\trepo.pipelines.push(pipeline);\n\t\tthis.save();\n\t\treturn pipeline;\n\t}\n\t/** @public */\n\tclient(): WoodpeckerClientLike {\n\t\tconst repo = (id: number) => {\n\t\t\tconst value = this.state.repositories.find((r) => r.repository.id === id);\n\t\t\tif (!value) throw new Error(\"Unknown local CI repository\");\n\t\t\treturn value;\n\t\t};\n\t\tconst pipeline = (id: number, number: number) => {\n\t\t\tconst value = repo(id).pipelines.find((p) => p.number === number);\n\t\t\tif (!value) throw new Error(\"Unknown local pipeline\");\n\t\t\treturn value;\n\t\t};\n\t\treturn {\n\t\t\tprofile: { baseUrl: this.options.baseUrl, token: \"\" },\n\t\t\tlookupRepository: async (name) => {\n\t\t\t\tconst value = this.state.repositories.find((r) => r.repository.full_name === name);\n\t\t\t\tif (!value) throw new Error(\"Unknown local CI repository\");\n\t\t\t\treturn structuredClone(value.repository);\n\t\t\t},\n\t\t\tlistPipelines: async (id, _signal, { page = 1, perPage = 100 } = { page: 1 }) =>\n\t\t\t\tstructuredClone(\n\t\t\t\t\t[...repo(id).pipelines]\n\t\t\t\t\t\t.sort((a, b) => b.number - a.number)\n\t\t\t\t\t\t.slice((page - 1) * perPage, page * perPage),\n\t\t\t\t),\n\t\t\tgetPipeline: async (id, number) => structuredClone(pipeline(id, number)),\n\t\t\tgetStepLogs: async (id, number, _step, tail = 400, bytes = 262144) => {\n\t\t\t\tconst original = pipeline(id, number).logs;\n\t\t\t\tconst logs = boundedLogTail(original.split(\"\\n\"), tail, bytes);\n\t\t\t\treturn { logs, truncated: logs !== original };\n\t\t\t},\n\t\t\trestartPipeline: async (id, number) => {\n\t\t\t\tconst value = pipeline(id, number);\n\t\t\t\tvalue.status = \"pending\";\n\t\t\t\tthis.save();\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t};\n\t}\n}\n"],"mappings":";;;;;AAAA,SAAS,0BAA0B;AAyC5B,IAAM,yBAAN,cAAqC,mBAG1C;AAAA;AAAA,EAED,YAAY,SAAiC;AAC5C,UAAM,SAAS,mBAAmB;AAAA,MACjC,SAAS;AAAA,MACT,UAAU;AAAA,MACV,cAAc,CAAC;AAAA,IAChB,CAAC;AAAA,EACF;AAAA;AAAA,EAEA,KAAK,UAAkB,IAAa;AACnC,UAAM,WAAW,KAAK,MAAM,aAAa,KAAK,CAAC,MAAM,EAAE,WAAW,cAAc,QAAQ;AACxF,QAAI,SAAU,QAAO;AACrB,UAAM,OAAO,EAAE,YAAY,EAAE,IAAI,MAAM,KAAK,GAAG,GAAG,WAAW,SAAS,GAAG,WAAW,CAAC,EAAE;AACvF,SAAK,MAAM,WAAW,KAAK,IAAI,KAAK,MAAM,UAAU,KAAK,WAAW,EAAE;AACtE,SAAK,MAAM,aAAa,KAAK,IAAI;AACjC,SAAK,KAAK;AACV,WAAO;AAAA,EACR;AAAA;AAAA,EAEA,QACC,MACA,OAcC;AACD,QACC,CAAC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,EAAE,SAAS,MAAM,MAAM;AAEvB,YAAM,IAAI,MAAM,yBAAyB;AAC1C,UAAM,SAAS,KAAK,GAAG;AACvB,UAAM,WAAW;AAAA,MAChB,GAAG;AAAA;AAAA,MAEH,IAAI;AAAA;AAAA,MAEJ;AAAA;AAAA,MAEA,OA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E,EAAE,SAAS,EACpB,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,EAClC,OAAO,OAAO,KAAK,SAAS,OAAO,OAAO;AAAA,MAC7C;AAAA,MACD,aAAa,OAAO,IAAI,WAAW,gBAAgB,SAAS,IAAI,MAAM,CAAC;AAAA,MACvE,aAAa,OAAO,IAAI,QAAQ,OAAO,OAAO,KAAK,QAAQ,WAAW;AACrE,cAAM,WAAW,SAAS,IAAI,MAAM,EAAE;AACtC,cAAM,OAAO,eAAe,SAAS,MAAM,IAAI,GAAG,MAAM,KAAK;AAC7D,eAAO,EAAE,MAAM,WAAW,SAAS,SAAS;AAAA,MAC7C;AAAA,MACA,iBAAiB,OAAO,IAAI,WAAW;AACtC,cAAM,QAAQ,SAAS,IAAI,MAAM;AACjC,cAAM,SAAS;AACf,aAAK,KAAK;AACV,eAAO,gBAAgB,KAAK;AAAA,MAC7B;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ServerExtensionAPI } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { WoodpeckerIntegration } from "./capability.js";
|
|
3
|
+
export declare function registerWoodpeckerTools(api: ServerExtensionAPI, integration: WoodpeckerIntegration): void;
|
|
4
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,kBAAkB,EAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAO7D,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,kBAAkB,EACvB,WAAW,EAAE,qBAAqB,QA2FlC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@leitwerk-dev/woodpecker",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"leitwerk": {
|
|
6
|
+
"extension": {
|
|
7
|
+
"source": "./src/index.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"discover": false
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"source": "./src/testing.ts",
|
|
20
|
+
"import": "./dist/testing.js",
|
|
21
|
+
"types": "./dist/testing.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup && tsc -p tsconfig.tsup.json --emitDeclarationOnly"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@leitwerk-dev/domain": "0.2.1",
|
|
29
|
+
"@leitwerk-dev/process-sdk": "0.2.1",
|
|
30
|
+
"@leitwerk-dev/watcher-utils": "0.2.1",
|
|
31
|
+
"@leitwerk-dev/test-support": "0.2.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"@types/node": "^26.2.0"
|
|
36
|
+
},
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=26 <27"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/**",
|
|
46
|
+
"src/**",
|
|
47
|
+
"!dist/**/*.test.*",
|
|
48
|
+
"!src/**/*.test.ts"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
53
|
+
"directory": "extensions/woodpecker"
|
|
54
|
+
}
|
|
16
55
|
}
|
package/src/binding.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { resolveRepositoryProjectBinding } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const resolveWoodpeckerProjectBinding = (
|
|
5
|
+
ctx: Parameters<typeof resolveRepositoryProjectBinding>[0],
|
|
6
|
+
) => resolveRepositoryProjectBinding(ctx, "woodpecker", "forgejo");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCapabilityToken } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { WoodpeckerClient } from "./client.js";
|
|
3
|
+
/** Public contract shared by HTTP and local adapters. @public */
|
|
4
|
+
export type WoodpeckerClientLike = Pick<WoodpeckerClient, keyof WoodpeckerClient>;
|
|
5
|
+
|
|
6
|
+
/** @public */
|
|
7
|
+
export interface WoodpeckerIntegration {
|
|
8
|
+
/** @public */
|
|
9
|
+
client(profile: string): WoodpeckerClientLike;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const woodpeckerIntegration = createCapabilityToken<WoodpeckerIntegration>(
|
|
13
|
+
"@leitwerk-private/woodpecker.integration",
|
|
14
|
+
);
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
|
+
import { IntegrationHttpClient } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { boundedLogTail } from "./logs.js";
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
export interface WoodpeckerProfile {
|
|
7
|
+
/** @internal */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** @internal */
|
|
10
|
+
token: string;
|
|
11
|
+
}
|
|
12
|
+
/** @public */
|
|
13
|
+
export interface WoodpeckerRepository {
|
|
14
|
+
/** @public */
|
|
15
|
+
id: number;
|
|
16
|
+
/** @public */
|
|
17
|
+
full_name: string;
|
|
18
|
+
}
|
|
19
|
+
/** @public */
|
|
20
|
+
export interface WoodpeckerPipeline {
|
|
21
|
+
/** @internal */
|
|
22
|
+
id: number;
|
|
23
|
+
/** @internal */
|
|
24
|
+
number: number;
|
|
25
|
+
/** @internal */
|
|
26
|
+
status: string;
|
|
27
|
+
/** @internal */
|
|
28
|
+
event: string;
|
|
29
|
+
/** @internal */
|
|
30
|
+
branch: string;
|
|
31
|
+
/** @internal */
|
|
32
|
+
commit: string;
|
|
33
|
+
/** @internal */
|
|
34
|
+
created_at?: number;
|
|
35
|
+
/** @internal */
|
|
36
|
+
workflows?: unknown[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface WoodpeckerLogEntry {
|
|
40
|
+
data?: number[] | string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function decodeLogData(data: WoodpeckerLogEntry["data"]): string {
|
|
44
|
+
if (Array.isArray(data)) {
|
|
45
|
+
return new TextDecoder("utf-8", { fatal: false }).decode(Uint8Array.from(data));
|
|
46
|
+
}
|
|
47
|
+
if (typeof data !== "string") return "";
|
|
48
|
+
if (/^[A-Za-z0-9+/]*={0,2}$/.test(data) && data.length % 4 === 0) {
|
|
49
|
+
try {
|
|
50
|
+
const binary = atob(data);
|
|
51
|
+
return new TextDecoder("utf-8", { fatal: false }).decode(
|
|
52
|
+
Uint8Array.from(binary, (character) => character.charCodeAt(0)),
|
|
53
|
+
);
|
|
54
|
+
} catch {
|
|
55
|
+
// Preserve an unexpected plain-text representation instead of hiding logs.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @internal */
|
|
62
|
+
export function parseWoodpeckerProfiles(value: unknown): Map<string, WoodpeckerProfile> {
|
|
63
|
+
const profiles = new Map<string, WoodpeckerProfile>();
|
|
64
|
+
for (const [name, raw] of Object.entries(
|
|
65
|
+
asUnknownRecord(asUnknownRecord(value)?.profiles) ?? {},
|
|
66
|
+
)) {
|
|
67
|
+
const config = asUnknownRecord(raw) ?? {};
|
|
68
|
+
const baseUrl = typeof config.base_url === "string" ? config.base_url.replace(/\/+$/, "") : "";
|
|
69
|
+
const token = typeof config.token === "string" ? config.token.trim() : "";
|
|
70
|
+
if (!/^https:\/\//.test(baseUrl))
|
|
71
|
+
throw new Error(`Woodpecker profile '${name}' requires an HTTPS base_url`);
|
|
72
|
+
if (!token) throw new Error(`Woodpecker profile '${name}' requires a token`);
|
|
73
|
+
profiles.set(name, { baseUrl, token });
|
|
74
|
+
}
|
|
75
|
+
return profiles;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** @public */
|
|
79
|
+
export class WoodpeckerClient extends IntegrationHttpClient {
|
|
80
|
+
/** @internal */
|
|
81
|
+
constructor(
|
|
82
|
+
/** @internal */
|
|
83
|
+
readonly profile: WoodpeckerProfile,
|
|
84
|
+
) {
|
|
85
|
+
super("Woodpecker", `${profile.baseUrl}/api`, {
|
|
86
|
+
Authorization: `Bearer ${profile.token}`,
|
|
87
|
+
Accept: "application/json",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @internal */
|
|
92
|
+
lookupRepository(fullName: string, signal?: AbortSignal): Promise<WoodpeckerRepository> {
|
|
93
|
+
return this.request(`/repos/lookup/${encodeURIComponent(fullName)}`, {
|
|
94
|
+
signal,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @internal */
|
|
99
|
+
listPipelines(
|
|
100
|
+
repoId: number,
|
|
101
|
+
signal?: AbortSignal,
|
|
102
|
+
pagination: {
|
|
103
|
+
/** @internal */
|
|
104
|
+
page: number;
|
|
105
|
+
/** @internal */
|
|
106
|
+
perPage?: number;
|
|
107
|
+
} = { page: 1 },
|
|
108
|
+
): Promise<WoodpeckerPipeline[]> {
|
|
109
|
+
const { page, perPage = 100 } = pagination;
|
|
110
|
+
if (
|
|
111
|
+
!Number.isSafeInteger(page) ||
|
|
112
|
+
page < 1 ||
|
|
113
|
+
!Number.isSafeInteger(perPage) ||
|
|
114
|
+
perPage < 1 ||
|
|
115
|
+
perPage > 100
|
|
116
|
+
)
|
|
117
|
+
throw new Error("Invalid Woodpecker pipeline pagination");
|
|
118
|
+
return this.request(`/repos/${repoId}/pipelines?page=${page}&perPage=${perPage}`, {
|
|
119
|
+
signal,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @internal */
|
|
124
|
+
getPipeline(repoId: number, number: number, signal?: AbortSignal): Promise<WoodpeckerPipeline> {
|
|
125
|
+
return this.request(`/repos/${repoId}/pipelines/${number}`, { signal });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @public */
|
|
129
|
+
async getStepLogs(
|
|
130
|
+
repoId: number,
|
|
131
|
+
number: number,
|
|
132
|
+
stepId: number,
|
|
133
|
+
tailLines = 400,
|
|
134
|
+
maxBytes = 262_144,
|
|
135
|
+
signal?: AbortSignal,
|
|
136
|
+
) {
|
|
137
|
+
const body = await (
|
|
138
|
+
await this.response(`/repos/${repoId}/logs/${number}/${stepId}`, {
|
|
139
|
+
signal,
|
|
140
|
+
})
|
|
141
|
+
).text();
|
|
142
|
+
let text = body;
|
|
143
|
+
try {
|
|
144
|
+
const entries = JSON.parse(body) as unknown;
|
|
145
|
+
if (Array.isArray(entries)) {
|
|
146
|
+
text = entries
|
|
147
|
+
.map((entry) =>
|
|
148
|
+
decodeLogData(asUnknownRecord(entry)?.data as WoodpeckerLogEntry["data"]).replace(
|
|
149
|
+
/\r?\n$/,
|
|
150
|
+
"",
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
.join("\n");
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
// Older adapters may return text directly; retain it as-is.
|
|
157
|
+
}
|
|
158
|
+
const output = boundedLogTail(text.split(/\r?\n/), tailLines, maxBytes);
|
|
159
|
+
return {
|
|
160
|
+
/** @public */
|
|
161
|
+
logs: output,
|
|
162
|
+
/** @internal */
|
|
163
|
+
truncated: output.length < text.length,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** @internal */
|
|
168
|
+
restartPipeline(
|
|
169
|
+
repoId: number,
|
|
170
|
+
number: number,
|
|
171
|
+
signal?: AbortSignal,
|
|
172
|
+
): Promise<WoodpeckerPipeline> {
|
|
173
|
+
return this.request(`/repos/${repoId}/pipelines/${number}`, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
signal,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
package/src/external.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ExternalActionSource } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
/** @internal */
|
|
3
|
+
export const WOODPECKER_PIPELINE_KIND = "@leitwerk-private/woodpecker.pipeline";
|
|
4
|
+
/** @internal */
|
|
5
|
+
export interface WoodpeckerPipelineSourceConfig {
|
|
6
|
+
/** @internal */
|
|
7
|
+
profile: string;
|
|
8
|
+
/** @internal */
|
|
9
|
+
owner: string;
|
|
10
|
+
/** @internal */
|
|
11
|
+
repo: string;
|
|
12
|
+
/** @internal */
|
|
13
|
+
branch: string;
|
|
14
|
+
/** @internal */
|
|
15
|
+
headSha: string;
|
|
16
|
+
/** @internal */
|
|
17
|
+
afterPipelineNumber?: number;
|
|
18
|
+
/** @internal */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** @internal */
|
|
21
|
+
pollInterval?: string;
|
|
22
|
+
/** @internal */
|
|
23
|
+
statuses?: string[];
|
|
24
|
+
}
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const woodpeckerExternal = {
|
|
27
|
+
/** @internal */
|
|
28
|
+
pipeline<TParams, TState>(
|
|
29
|
+
resolve: (ctx: {
|
|
30
|
+
/** @internal */
|
|
31
|
+
params: TParams;
|
|
32
|
+
/** @internal */
|
|
33
|
+
state: TState;
|
|
34
|
+
}) => WoodpeckerPipelineSourceConfig,
|
|
35
|
+
): ExternalActionSource<TParams, TState> {
|
|
36
|
+
return {
|
|
37
|
+
kind: WOODPECKER_PIPELINE_KIND,
|
|
38
|
+
label: "Woodpecker pipeline completion",
|
|
39
|
+
description: "Fires when a pipeline matching the current source head completes",
|
|
40
|
+
config: {},
|
|
41
|
+
inputMode: "none",
|
|
42
|
+
resolve,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|