From fb541038d97955b38b0371af1329f4d28a7f613c Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Wed, 25 Nov 2026 18:54:55 +0800 Subject: [PATCH] =?UTF-8?q?15m44w=20=E7=BB=AD4:=20=E4=BF=AEgit=E5=89=8D?= =?UTF-8?q?=E7=BC=80bug(clone:command=20not=20found)+=E7=BB=88=E6=80=81?= =?UTF-8?q?=E6=91=98=E5=85=A8label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ① git push 报 'clone: command not found' 根因: runGit shell_exec 拼命令时 $args[0] 是 git 子命令(clone/add/commit/push), 漏了 git 可执行名前缀 → shell 直接跑 clone 找不到。 修: $cmd='git '.implode(...)。 ② 撤销/驳回/完结(终态)摘 label 改为【摘该 issue 当前全部 label 只留目标标】 (用户要'摘掉其它标', 比旧版只摘 stateLabels 白名单更彻底, 自定义标签也摘)。 中间态(回复/处理中)保留只摘互斥状态组。 --- gh_api.php | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/gh_api.php b/gh_api.php index 86f3436..d4baa31 100644 --- a/gh_api.php +++ b/gh_api.php @@ -316,9 +316,12 @@ function ghSyncLabel($ticketId, $action, $token) { $target = isset($defaultMap[$key]) ? $defaultMap[$key] : ''; } if ($target === '') return false; - // 互斥组:状态类 label(打某个时摘掉同组其它),非状态类(如 申诉状)保留 + // 状态类 label 白名单(中间态互斥组 + 终态兜底),非状态类(申诉状等)中间态保留 $stateLabels = ['待处理', '处理中', '已回复', '已完成', '已驳回', '已撤销']; - // 拉 repo 现有 label,确认目标 label 存在(不存在则跳过,避免 422) + // ★ 15m44w 续4:终态动作(撤销/驳回/完结)= 摘【该 issue 当前挂的全部 label】只留目标标 + // (用户定调"摘掉其它标"——比旧版只摘 stateLabels 白名单更彻底,自定义标签也摘掉); + // 中间态动作(回复/处理中)仍只摘互斥的状态组,保留申诉状等非状态类标签。 + $finalStates = array('withdraw', 'rejected', 'completed'); $lr = ghApiRequest('GET', '/repos/' . $repo . '/labels', null, $token); $existingNames = []; if (!empty($lr['ok']) && is_array($lr['data'])) { @@ -328,7 +331,38 @@ function ghSyncLabel($ticketId, $action, $token) { ghLog('label skipped: target "' . $target . '" not in repo labels action=' . $action); return false; } - // 1) 摘掉同组其它 label(先摘后加) + // 1) 摘 label(终态=摘该 issue 全部当前 label,中间态=摘互斥状态组) + $issueNow = ghApiRequest('GET', '/repos/' . $repo . '/issues/' . $issueNo, null, $token); + if (in_array($action, $finalStates, true)) { + // 终态:拉该 issue 当前挂的 label 全摘(除了即将贴的目标标,其它一律摘) + $curLabels = []; + if (!empty($issueNow['ok']) && is_array($issueNow['data']) && isset($issueNow['data']['labels'])) { + foreach ($issueNow['data']['labels'] as $cl) { + // label 可能是对象 {name:...} 或字符串(兼容) + $nm = (is_array($cl) && isset($cl['name'])) ? (string)$cl['name'] : (string)$cl; + if ($nm !== '' && $nm !== $target) $curLabels[] = $nm; + } + } + // 兜底:旧逻辑的 stateLabels 白名单也一并纳入(防该 issue 还挂着白名单内状态标) + foreach ($stateLabels as $sl) { + if ($sl === $target) continue; + if (in_array($sl, $curLabels, true) || in_array($sl, $existingNames, true)) { + if (!in_array($sl, $curLabels, true)) $curLabels[] = $sl; + } + } + foreach (array_values(array_unique($curLabels)) as $cl) { + ghApiRequest('DELETE', '/repos/' . $repo . '/issues/' . $issueNo . '/labels/' . rawurlencode($cl), null, $token); + } + // 2) 加目标 label + $r = ghApiRequest('POST', '/repos/' . $repo . '/issues/' . $issueNo . '/labels', ['labels' => [$target]], $token); + if (!$r['ok']) { + ghLog('label add failed action=' . $action . ' target=' . $target . ': ' . $r['msg']); + } else { + ghLog('label ok(final, cleared ' . count($curLabels) . ') action=' . $action . ' target=' . $target . ' issue=' . $issueNo); + } + return $r['ok']; + } + // 中间态:只摘互斥状态组(保留申诉状等非状态类) foreach ($stateLabels as $sl) { if ($sl === $target) continue; if (in_array($sl, $existingNames, true)) { @@ -535,7 +569,9 @@ function ghImgRepoPushViaGit($full, $owner, $branch, $relPath, $tmpPath, $token, return $a; }; $runGit = function($args, $cwd, $q, $timeout = 60) { - $cmd = implode(' ', array_map($q, $args)); + // ★ 15m44w 续4 修:$args[0] 是 git 子命令(clone/add/commit/push...), 必须加 `git` 可执行名前缀, + // 旧版漏了导致 shell 直接跑 `clone` → "sh: line 1: clone: command not found"。 + $cmd = 'git ' . implode(' ', array_map($q, $args)); // 2>&1 合流 stderr;GIT_TERMINAL_PROMPT=0 禁交互(避免卡死);echo 退出码 $fullCmd = 'cd ' . $q($cwd) . ' && GIT_TERMINAL_PROMPT=0 ' . $cmd . ' 2>&1; echo __EXIT__$?'; $out = @shell_exec($fullCmd);