( params: PiCloudRunParams, branch: string, detectedBase: string | undefined, totals: PiRunTotals )
| 145 | } |
| 146 | |
| 147 | async function openPullRequest( |
| 148 | params: PiCloudRunParams, |
| 149 | branch: string, |
| 150 | detectedBase: string | undefined, |
| 151 | totals: PiRunTotals |
| 152 | ): Promise<string | undefined> { |
| 153 | const base = params.baseBranch?.trim() || detectedBase |
| 154 | if (!base) { |
| 155 | throw new Error( |
| 156 | `Branch ${branch} pushed, but the base branch could not be determined — set "Base Branch" on the block and re-run.` |
| 157 | ) |
| 158 | } |
| 159 | const title = defaultTitle(params) |
| 160 | const body = params.prBody?.trim() || buildPrBody(params.task, totals.finalText) |
| 161 | |
| 162 | const result = await executeTool('github_create_pr', { |
| 163 | owner: params.owner, |
| 164 | repo: params.repo, |
| 165 | title, |
| 166 | head: branch, |
| 167 | base, |
| 168 | body, |
| 169 | draft: params.draft, |
| 170 | apiKey: params.githubToken, |
| 171 | }) |
| 172 | |
| 173 | if (!result.success) { |
| 174 | throw new Error( |
| 175 | `Branch ${branch} pushed but PR creation failed: ${result.error ?? 'unknown error'}` |
| 176 | ) |
| 177 | } |
| 178 | |
| 179 | const output = result.output as { metadata?: { html_url?: string } } | undefined |
| 180 | return output?.metadata?.html_url |
| 181 | } |
| 182 | |
| 183 | export const runCloudPi: PiBackendRun<PiCloudRunParams> = async (params, context) => { |
| 184 | if (!params.isBYOK) { |
no test coverage detected