(msg: Api.Message, args: string[])
| 221 | private async handlePRs(msg: Api.Message, args: string[]) { |
| 222 | if (args.length < 1) { |
| 223 | throw new Error("参数不足,需要提供仓库名"); |
| 224 | } |
| 225 | const repoName = args[0]; |
| 226 | await msg.edit({ text: `🔄 正在获取 <code>${htmlEscape(repoName)}</code> 的PR列表...`, parseMode: "html" }); |
| 227 | |
| 228 | const parts = repoName.split("/"); |
| 229 | if (parts.length !== 2) { |
| 230 | throw new Error("仓库名格式应为 owner/repo,例如 octocat/Hello-World"); |
| 231 | } |
| 232 | const [owner, repo] = parts; |
| 233 | |
| 234 | const api = await getApi(); |
| 235 | const response = await api.get(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls`, { |
| 236 | params: { state: "open", per_page: 50 } |
| 237 | }); |
| 238 | |
| 239 | const list: any[] = response.data || []; |
| 240 | if (!list.length) { |
| 241 | await msg.edit({ text: `ℹ️ 仓库 <code>${htmlEscape(repoName)}</code> 中没有待处理的PR。`, parseMode: "html" }); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | // 获取可合并状态(可能为 null),尽量标注 |
| 246 | const details = [] as { number: number; title: string; user: string; mergeable?: boolean; state?: string }[]; |
| 247 | for (const item of list) { |
| 248 | try { |
| 249 | const pr = await api.get(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${item.number}`); |
| 250 | details.push({ |
| 251 | number: item.number, |
| 252 | title: item.title || "", |
| 253 | user: item?.user?.login || "", |
| 254 | mergeable: pr.data?.mergeable, |
| 255 | state: pr.data?.mergeable_state |
| 256 | }); |
| 257 | } catch { |
| 258 | details.push({ number: item.number, title: item.title || "", user: item?.user?.login || "" }); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | const prList = details.map((pr) => { |
| 263 | const flag = pr.mergeable === true ? "✅ 可合并" : pr.mergeable === false ? `⛔ 不可合并(${pr.state || "unknown"})` : "❓ 未知"; |
| 264 | return `• <b>#${pr.number}</b>: ${htmlEscape(pr.title)}\n 作者: <code>${htmlEscape(pr.user)}</code> | 状态: ${flag}`; |
| 265 | }).join("\n\n"); |
| 266 | |
| 267 | await sendLongMessage(msg, `📬 <b>待处理的PR:</b>\n\n${prList}`); |
| 268 | } |
| 269 | |
| 270 | private async handleMerge(msg: Api.Message, args: string[]) { |
| 271 | if (args.length < 2) { |
| 272 | throw new Error("参数不足,需要提供仓库名和PR编号"); |
| 273 | } |
no test coverage detected