15m44w 续5: 横条根因(gh_auth_tokens建表TEXT PK改VARCHAR)+webhook撤销联动+诊断端点

① 横条: gh_auth_tokens 建表声明 TEXT PRIMARY KEY 在 MySQL 下不合法(TEXT 不能做 PK),
   改 VARCHAR(500) 对齐线上 caoyuanphp 实际 schema(gh_cfg.php+gh_oauth.php 两处)。
   gh_cfg.php 验活加 ghLog 日志(status/ok/token前缀)便于定位断点。
② webhook 撤销联动(用户定调): issue 关闭事件 state_reason=completed/done 且 label 含「已撤销」
   → PHP 工单撤销(withdrawn)。原只分 not_planned→rejected/其它→completed, 现加 已撤销+done→withdrawn。
③ 新增 api/gh_diag.php 临时诊断端点(验活全链路逐步输出, 定位横条断点)。
This commit is contained in:
ypsdf1
2026-11-25 19:47:23 +08:00
parent fb541038d9
commit 7acbcf6198
4 changed files with 93 additions and 12 deletions
+24 -5
View File
@@ -445,16 +445,35 @@ function ghHandleWebhook($payload, $event) {
return true;
}
// issue 关闭事件:GitHub 侧关闭 issue → 按 state_reason 联动 PHP 状态
// 15m44s 新功能:closed-done(completed) → PHP 已完结;closed-not planned(not_planned) → PHP 已驳回。
// issue 关闭事件:GitHub 侧关闭 issue → 按 state_reason + label 联动 PHP 状态
// 15m44s:done(completed)→已完结;not planned(not_planned)→已驳回;其它/无 reason 默认已完结
// ★ 15m44w 续4(用户定调):closed-done(state_reason=completed/done) 且 label 含「已撤销」
// → PHP 工单撤销(withdrawn)。撤销场景:PHP 撤销工单时关 issue 贴「已撤销」标,
// GitHub 侧该 issue 后续被关(done)且挂着已撤销标 → 回推 PHP 撤销工单,保持两边一致。
if ($event === 'issues' && isset($issue['state']) && $issue['state'] === 'closed') {
$reason = isset($issue['state_reason']) ? (string)$issue['state_reason'] : '';
// 用户定调:done(completed)=已完结;not planned(not_planned)=已驳回;其它/无 reason 默认已完结
$phpStatus = ($reason === 'not_planned') ? 'rejected' : 'completed';
// 15m44w 续4:done + 已撤销 label → withdrawn
$issueLabels = [];
if (isset($issue['labels']) && is_array($issue['labels'])) {
foreach ($issue['labels'] as $lb) {
// label 可能是对象 {name:...} 或字符串(webhook payload 通常是对象)
$nm = (is_array($lb) && isset($lb['name'])) ? (string)$lb['name'] : (string)$lb;
if ($nm !== '') $issueLabels[] = $nm;
}
}
$isWithdrawLabel = in_array('已撤销', $issueLabels, true);
if ($isWithdrawLabel && in_array($reason, ['completed', 'done', ''], true)) {
$phpStatus = 'withdrawn';
} else {
// 用户定调:done(completed)=已完结;not planned(not_planned)=已驳回;其它/无 reason 默认已完结
$phpStatus = ($reason === 'not_planned') ? 'rejected' : 'completed';
}
$now = time();
$closeMsg = ($phpStatus === 'rejected')
? '🔒 GitHub issue #' . $issueNo . ' 已关闭(not planned)→ 工单标记为已驳回'
: '🔒 GitHub issue #' . $issueNo . ' 已关闭(done)→ 工单标记为已完结';
: (($phpStatus === 'withdrawn')
? '↩️ GitHub issue #' . $issueNo . ' 已关闭(done)且标签「已撤销」→ 工单标记为已撤销'
: '🔒 GitHub issue #' . $issueNo . ' 已关闭(done)→ 工单标记为已完结');
try {
$ins = $db->prepare("INSERT INTO web_ticket_replies (ticket_id, sender, role, message, created_at) VALUES (:tid, 'gh:issue', 'admin', :msg, :now)");
$ins->bindValue(':tid', $ticketId, SQLITE3_INTEGER);