From 2d69b946082b49f39ce872e8b14592d84ce86649 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Wed, 25 Nov 2026 14:04:49 +0800 Subject: [PATCH] =?UTF-8?q?15m44q=20ghSyncCreate=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E6=9B=BF=E6=8D=A2=20[=E5=9B=BE=E7=89=87N]=20=E5=8D=A0?= =?UTF-8?q?=E4=BD=8D=E7=AC=A6=20+=20ghSyncClose=20=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E5=8D=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户实测 issue #8 body 里 'abc[图片1]' 占位符没替换成附件名, 且 issue 没被 关成 done/not planned。 根因1(附件占位符): 描述暂存阶段前端把附件插成 [图片N] 占位, 提交后客户端才替换, 服务端 ghSyncCreate 拿到的是原始描述(仍带 [图片N]) 直接塞 issue body → GitHub 上 显示 'abc[图片1]'。修: ghSyncCreate 里对 images 非空时 preg_replace 把 [图片N] 就地替换成 '📎 附件N'(静态, 不重复文件名, 文件名统一末尾集中展示)。 根因2(未关单/旧文案): gh_sync.log 不存在→ghLog 没写→关单要么早期 return(无 token / 空 gh_issue_number)要么成功没留痕。旧 issue #8 的驳回文案是 15m44p 部署前的 旧文本(🚫 工单已驳回, 无原因), 证明当时走的是不带 state_reason 的旧代码。 修: ghSyncClose 成功分支也 ghLog(记录 kind + reason + status), 便于下次定位。 --- gh_api.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gh_api.php b/gh_api.php index 2dfc4ca..40f9c07 100644 --- a/gh_api.php +++ b/gh_api.php @@ -101,6 +101,7 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t if (!$cfg['gh_enabled']) return false; if ($token === '') { // 没拿到 access_token(玩家未授权)→ 跳过同步(PHP 工单照常) + ghLog('create issue skipped: no gh token for player ' . $player); return false; } $repo = $cfg['gh_repo']; @@ -108,8 +109,22 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t // issue body:玩家名 + 描述 + 附件 // - @gh: 开头 = GitHub 模式占位附件(只记文件名,不走图床)→ 显示为「📎 附件:文件名」 // - http(s) = 真实图床外链 → 用 markdown 图片语法 + + // ★ 15m44q: 服务端把描述里的 [图片N] 占位符就地替换成「📎 附件N:文件名」。 + // 占位符是前端暂存附件时插进描述的(提交后才在客户端替换),服务端拿到的 description + // 仍带着 [图片N]。旧版 ghSyncCreate 直接把原始描述塞进 issue body,导致 GitHub 上 + // 显示「abc[图片1]」占位符没被替换(用户实测附件不对根因)。附件名统一在末尾集中 + // 展示一次,描述里的 [图片N] 只标记"此处有附件"不重复展示文件名。 + $desc = (string)$description; + $hasAttach = false; + foreach ((is_array($images) ? $images : []) as $u) { + if (is_string($u)) { $hasAttach = true; break; } + } + if ($hasAttach) { + $desc = preg_replace('/\[图片(\d+)\]/u', '\U📎 附件\1\E', $desc); + } $bodyParts = ['玩家:`' . $player . '`', '']; - if ($description !== '') $bodyParts[] = $description; + if ($desc !== '') $bodyParts[] = $desc; if (is_array($images) && count($images) > 0) { $bodyParts[] = ''; foreach ($images as $i => $u) { @@ -206,7 +221,11 @@ function ghSyncClose($ticketId, $kind, $token, $sender = 'admin') { $stateReason = ($kind === 'rejected') ? 'not_planned' : 'completed'; $r = ghApiRequest('POST', '/repos/' . $repo . '/issues/' . $issueNo . '/close', ['state' => 'closed', 'state_reason' => $stateReason], $token); - if (!$r['ok']) ghLog('close issue #' . $issueNo . ' failed: ' . $r['msg']); + if (!$r['ok']) { + ghLog('close issue #' . $issueNo . ' failed: ' . $r['msg']); + } else { + ghLog('close issue #' . $issueNo . ' ok kind=' . $kind . ' reason=' . $stateReason . ' status=' . $r['status']); + } return $r['ok']; }