(msg: Api.Message, args: string[])
| 270 | private async handleMerge(msg: Api.Message, args: string[]) { |
| 271 | if (args.length < 2) { |
| 272 | throw new Error("参数不足,需要提供仓库名和PR编号"); |
| 273 | } |
| 274 | const [repoName, prNumberStr] = args; |
| 275 | const prNumber = parseInt(prNumberStr, 10); |
| 276 | if (isNaN(prNumber)) { |
| 277 | throw new Error("PR编号必须是数字"); |
| 278 | } |
| 279 | |
| 280 | await msg.edit({ text: `🔄 正在合并 <code>${htmlEscape(repoName)}</code> 中的 PR #${prNumber}...`, parseMode: "html" }); |
| 281 | |
| 282 | const parts = repoName.split("/"); |
| 283 | if (parts.length !== 2) { |
| 284 | throw new Error("仓库名格式应为 owner/repo,例如 octocat/Hello-World"); |
| 285 | } |
| 286 | const [owner, repo] = parts; |
| 287 | |
| 288 | const api = await getApi(); |
| 289 | try { |
| 290 | await api.put(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${prNumber}/merge`); |
| 291 | await msg.edit({ text: `✅ 成功合并 PR #${prNumber}`, parseMode: "html" }); |
| 292 | } catch (error: any) { |
| 293 | const errorMsg = error.response?.data?.message || error.message; |
| 294 | throw new Error(`合并失败: ${errorMsg}`); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | private async handleMergeAll(msg: Api.Message, args: string[]) { |
| 299 | if (args.length < 1) { |
| 300 | throw new Error("参数不足,需要提供仓库名"); |
| 301 | } |
no test coverage detected