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']; }