Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Schema } from 'effect'; |
| 2 | import { stableByDefault } from './channel'; |
| 3 | import { autoByDefault } from './plan'; |
| 4 | |
| 5 | /** The channel and per-language bump choices; `auto` follows the changesets. */ |
| 6 | export const ReleaseRequest = Schema.Struct({ |
| 7 | channel: stableByDefault, |
| 8 | typescript: autoByDefault, |
| 9 | python: autoByDefault, |
| 10 | }); |
| 11 | export type ReleaseRequest = typeof ReleaseRequest.Type; |
| 12 | |
| 13 | const Dispatch = Schema.Struct({ |
| 14 | inputs: Schema.Record(Schema.String, Schema.Unknown), |
| 15 | }); |
| 16 | const Issue = Schema.Struct({ issue: Schema.Struct({ body: Schema.String }) }); |
| 17 | |
| 18 | /** Issue-form headings and the request fields they fill. */ |
| 19 | const ISSUE_FIELDS = { Channel: 'channel', TypeScript: 'typescript', Python: 'python' } as const; |
| 20 | const ISSUE_FIELD_PATTERN = |
| 21 | /^### (Channel|TypeScript|Python)\r?\n\r?\n([\s\S]*?)(?=^### |$(?![\s\S]))/gm; |
| 22 | |
| 23 | const parseIssueBody = (body: string) => { |
| 24 | const fields = new Map<keyof typeof ISSUE_FIELDS, string>(); |
| 25 | for (const match of body.matchAll(ISSUE_FIELD_PATTERN)) { |
| 26 | const heading = match[1] as keyof typeof ISSUE_FIELDS; |
| 27 | if (fields.has(heading)) throw new Error(`Duplicate release field: ${heading}`); |
| 28 | fields.set(heading, match[2].trim()); |
| 29 | } |
| 30 | if (fields.size !== Object.keys(ISSUE_FIELDS).length) |
| 31 | throw new Error('Use the SDK release request issue form'); |
| 32 | return Object.fromEntries([...fields].map(([heading, value]) => [ISSUE_FIELDS[heading], value])); |
| 33 | }; |
| 34 | |
| 35 | /** Reads the same request from a workflow dispatch or from the issue form. */ |
| 36 | export function parseReleaseRequest(eventName: string, payload: unknown): ReleaseRequest { |
| 37 | const fields = |
| 38 | eventName === 'workflow_dispatch' |
| 39 | ? Schema.decodeUnknownSync(Dispatch)(payload).inputs |
| 40 | : eventName === 'issues' |
| 41 | ? parseIssueBody(Schema.decodeUnknownSync(Issue)(payload).issue.body) |
| 42 | : undefined; |
| 43 | if (!fields) throw new Error('Unsupported SDK release request event'); |
| 44 | return Schema.decodeUnknownSync(ReleaseRequest)(fields); |
| 45 | } |