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 { PositiveInt, SDK_RELEASE_REPOSITORY, Sha, runUrl } from './github'; |
| 3 | import type { Channel } from './channel'; |
| 4 | import { PYTHON_RELEASE_MARKER, REGISTRY_VERSION } from './lanes'; |
| 5 | import { issueUrl, type ReleaseBatch } from './source'; |
| 6 | |
| 7 | const RELEASE_BRANCH = /^sdk-release\/batch-\d+$/; |
| 8 | |
| 9 | export const releaseBranch = (id: string) => `sdk-release/batch-${id}`; |
| 10 | |
| 11 | /** A pull request as list endpoints return it. They never say whether it merged. */ |
| 12 | export const PullListItem = Schema.Struct({ |
| 13 | number: PositiveInt, |
| 14 | html_url: Schema.String, |
| 15 | state: Schema.String, |
| 16 | /** `null` when the author's account was deleted. */ |
| 17 | user: Schema.NullOr(Schema.Struct({ login: Schema.String })), |
| 18 | head: Schema.Struct({ |
| 19 | sha: Sha, |
| 20 | ref: Schema.String, |
| 21 | repo: Schema.NullOr(Schema.Struct({ full_name: Schema.String })), |
| 22 | }), |
| 23 | base: Schema.Struct({ ref: Schema.String }), |
| 24 | }); |
| 25 | export type PullListItem = typeof PullListItem.Type; |
| 26 | |
| 27 | /** |
| 28 | * A single pull request. The gate decides on `merged`, so a response without it is a contract |
| 29 | * failure rather than an unmerged PR. |
| 30 | */ |
| 31 | export const PullDetail = Schema.Struct({ ...PullListItem.fields, merged: Schema.Boolean }); |
| 32 | export type PullDetail = typeof PullDetail.Type; |
| 33 | |
| 34 | export const isReleasePull = (pull: PullListItem) => |
| 35 | pull.head.repo?.full_name === SDK_RELEASE_REPOSITORY && RELEASE_BRANCH.test(pull.head.ref); |
| 36 | |
| 37 | const NOTE_EXEMPT = |
| 38 | '<!-- sdk-release-note-exempt: This release PR applies previously reviewed SDK changes and only updates release metadata and generated documentation. -->'; |
| 39 | const SUMMARY_LIMIT = 200; |
| 40 | |
| 41 | type Plan = ReleaseBatch['plan']; |
| 42 | type Changeset = Plan['changesets'][number]; |
| 43 | |
| 44 | const repositoryUrl = `https://github.com/${SDK_RELEASE_REPOSITORY}`; |
| 45 | const fileUrl = (branch: string, path: string) => |
| 46 | `${repositoryUrl}/${path.endsWith('/') ? 'tree' : 'blob'}/${branch}/${path}`; |
| 47 | |
| 48 | /** Shows contributor text literally, so it cannot hide or add content in the reviewed body. */ |
| 49 | const escapeMarkdown = (text: string) => |
| 50 | text |
| 51 | .replaceAll('&', '&') |
| 52 | .replaceAll('<', '<') |
| 53 | .replaceAll('>', '>') |
| 54 | .replace(/[\\`*_[\]()|#!]/g, '\\$&'); |
| 55 | |
| 56 | /** npm-valid names render as code; anything else renders as escaped text. */ |
| 57 | const SAFE_PACKAGE_NAME = /^@composio\/[a-z0-9][a-z0-9._-]*$/; |
| 58 | export const packageLabel = (name: string) => |
| 59 | name === PYTHON_RELEASE_MARKER |
| 60 | ? 'Python SDK (`composio` and every provider)' |
| 61 | : SAFE_PACKAGE_NAME.test(name) |
| 62 | ? `\`${name}\`` |
| 63 | : escapeMarkdown(name); |
| 64 | |
| 65 | /** First line of a changeset summary, short enough for one list item. */ |
| 66 | const headline = (summary: string) => { |
| 67 | const line = summary.trim().split('\n')[0]?.trim() || '(no summary)'; |
| 68 | return escapeMarkdown( |
| 69 | line.length > SUMMARY_LIMIT ? `${line.slice(0, SUMMARY_LIMIT - 1)}…` : line |
| 70 | ); |
| 71 | }; |
| 72 | |
| 73 | const changesetLine = (note: Changeset) => { |
| 74 | const bumps = note.releases |
| 75 | .filter(release => release.type !== 'none') |
| 76 | .map(release => `${packageLabel(release.name)} ${release.type}`) |
| 77 | .join(', '); |
| 78 | return `- \`.changeset/${note.id}.md\` (${bumps || 'no version bump'}): ${headline(note.summary)}`; |
| 79 | }; |
| 80 | |
| 81 | /** How a release PR explains its channel to the reviewer. */ |
| 82 | const CHANNEL_COPY: Record< |
| 83 | Channel, |
| 84 | { |
| 85 | readonly title: string; |
| 86 | readonly summary: string; |
| 87 | readonly notes: string; |
| 88 | readonly afterPublish: string; |
| 89 | } |
| 90 | > = { |
| 91 | stable: { |
| 92 | title: 'chore(release): publish SDK packages', |
| 93 | summary: 'A stable release: npm moves `latest` to these versions.', |
| 94 | notes: '## Changesets consumed', |
| 95 | afterPublish: |
| 96 | '5. After publishing, the bot opens a docs PR that pins the released npm versions, so twoslash checks the docs against them.', |
| 97 | }, |
| 98 | beta: { |
| 99 | title: 'chore(release): publish SDK beta packages', |
| 100 | summary: |
| 101 | 'A beta release: npm moves `next` to these versions and never touches `latest`, and pip installs them only with `--pre` or an exact pin. This PR commits only the release plan. The candidate checks apply its versions, so `next` keeps its stable versions and every changeset below stays pending for the stable release.', |
| 102 | notes: '## Changesets previewed', |
| 103 | afterPublish: |
| 104 | '5. A beta opens no docs PR: the docs keep following stable releases. The request issue lists the published versions.', |
| 105 | }, |
| 106 | }; |
| 107 | |
| 108 | export const releasePullTitle = (batch: ReleaseBatch) => |
| 109 | CHANNEL_COPY[batch.plan.choices.channel].title; |
| 110 | |
| 111 | const packageRows = (plan: Plan) => |
| 112 | plan.releases.map(release => { |
| 113 | const recommended = plan.recommended.find(candidate => candidate.name === release.name); |
| 114 | const override = |
| 115 | recommended?.newVersion === release.newVersion |
| 116 | ? '' |
| 117 | : ` (recommended ${recommended?.newVersion ?? 'none'})`; |
| 118 | const notes = release.changesets.map(id => `\`${id}\``).join(', ') || 'maintenance release'; |
| 119 | return `| ${packageLabel(release.name)} | ${release.oldVersion} → **${REGISTRY_VERSION[release.language](release.newVersion)}**${override} | ${release.type} | ${notes} |`; |
| 120 | }); |
| 121 | |
| 122 | /** Lists what ships, which changesets it consumes, and which changelogs and docs it edits. */ |
| 123 | export const releasePullBody = ( |
| 124 | batch: ReleaseBatch, |
| 125 | branch: string, |
| 126 | outputs: ReadonlyArray<string> |
| 127 | ) => { |
| 128 | const { plan } = batch; |
| 129 | const copy = CHANNEL_COPY[plan.choices.channel]; |
| 130 | const changelogs = outputs.filter(path => path.endsWith('/CHANGELOG.md')); |
| 131 | const docsChangelog = outputs.filter(path => path.startsWith('docs/content/changelog/')); |
| 132 | const references = outputs.filter(path => |
| 133 | path.startsWith('docs/content/reference/sdk-reference/') |
| 134 | ); |
| 135 | const link = (path: string) => `[\`${path}\`](${fileUrl(branch, path)})`; |
| 136 | const sections = [ |
| 137 | NOTE_EXEMPT, |
| 138 | copy.summary, |
| 139 | '## What gets released', |
| 140 | [ |
| 141 | '| Package | Version | Bump | Changesets |', |
| 142 | '| --- | --- | --- | --- |', |
| 143 | ...packageRows(plan), |
| 144 | ].join('\n'), |
| 145 | copy.notes, |
| 146 | plan.changesets.map(changesetLine).join('\n') || 'None: this is a maintenance release.', |
| 147 | ...(plan.retainedChangesets.length |
| 148 | ? [ |
| 149 | '## Changesets left for a later release', |
| 150 | 'These entries target a language this release skips. Their files stay in `.changeset/` with only these entries.', |
| 151 | plan.retainedChangesets.map(changesetLine).join('\n'), |
| 152 | ] |
| 153 | : []), |
| 154 | '## Changelog and docs edits', |
| 155 | [ |
| 156 | `- Docs changelog entry: ${docsChangelog.map(link).join(', ') || 'none'}.`, |
| 157 | `- Package changelogs: ${changelogs.map(link).join(', ') || 'none'}.`, |
| 158 | `- Regenerated API references: ${references.map(link).join(', ') || 'none'}.`, |
| 159 | ].join('\n'), |
| 160 | '## How this ships', |
| 161 | [ |
| 162 | `1. Release source is frozen at ${batch.inputBase}. Later \`next\` commits and their changesets wait for the next release.`, |
| 163 | `2. Review the diff and approve this head. Approval must come from a repository writer; the requester (@${batch.requestedBy}) may approve only with repository admin permission at release time. Do not push to this branch: the tag step only accepts the release bot's commit. To change the notes, fix the changesets on \`next\`, close this PR and request a new release.`, |
| 164 | `3. After approval and green checks, merge this PR. The release workflow rechecks the approval and tags this exact head \`sdk-release/${batch.id}\`; if the check fails, it creates no tag and asks you to revert this PR and request the release again.`, |
| 165 | '4. The tag run publishes the exact files the `SDK candidate` checks built and the `SDK candidate smoke` checks installed on this PR. If a publish job fails, use "Re-run failed jobs" on that run.', |
| 166 | copy.afterPublish, |
| 167 | ].join('\n'), |
| 168 | `Request: ${issueUrl(batch)}\nPlanning run: ${runUrl(batch.id)}`, |
| 169 | ]; |
| 170 | return sections.join('\n\n'); |
| 171 | }; |