diff --git a/.agent/rules/issue_management.md b/.agent/rules/issue_management.md index 87bb11d..e46aaa3 100644 --- a/.agent/rules/issue_management.md +++ b/.agent/rules/issue_management.md @@ -11,6 +11,7 @@ - **同期方向**: 原則として上流の Issue トラッカーが正(Source of Truth)です。 - **自動同期**: `node tools/scripts/sync_issues.mjs` を実行して、リモートの最新状態を `docs/issues/` に反映、またはローカルの新規 Issue をリモートに作成します。 - **Git追跡除外**: `docs/issues/` は `.gitignore` により Git 追跡から除外されています。 +- **Issue 編集と 404**: GitBucket の多くのバージョンでは、Issue 本体の PATCH(編集)API が未実装で 404 になります。同期スクリプトは 404 時に **Create an issue comment** API で本文をコメントとして投稿するフォールバックを行うため、編集内容は Issue のコメントとしてリモートに残ります。 ### 2. 記述規約 diff --git a/tools/scripts/sync_issues.mjs b/tools/scripts/sync_issues.mjs index e447a39..a01c93f 100644 --- a/tools/scripts/sync_issues.mjs +++ b/tools/scripts/sync_issues.mjs @@ -87,6 +87,23 @@ return await apiCall(`${API_BASE}?state=all`); } +// GitBucket の多くのバージョンでは Issue の PATCH(編集)が未実装のため 404 になる。 +// 代替: Issue にコメントを投稿する API(Create an issue comment)は対応している。 +const COMMENTS_BASE = "https://gitbucket.tmworks.club/api/v3/repos/dtmoyaji/TelosDB/issues"; + +async function postIssueComment(issueNumber, commentBody) { + if (!TOKEN) { + console.warn("[Skip] Cannot post comment: GITBUCKET_TOKEN is missing."); + return null; + } + try { + return await apiCall(`${COMMENTS_BASE}/${issueNumber}/comments`, 'POST', { body: commentBody }); + } catch (err) { + console.warn(`[Skip] Failed to post comment on #${issueNumber}:`, err.message); + return null; + } +} + async function updateRemoteIssue(number, title, body, state) { console.log(`Pushing changes to remote issue #${number}...`); try { @@ -94,9 +111,14 @@ } catch (err) { if (err.message.includes('404')) { const htmlUrl = `https://gitbucket.tmworks.club/dtmoyaji/TelosDB/issues/${number}`; - console.warn(`\n[Manual Action Required]`); - console.warn(`GitBucket API (PATCH) returned 404. Your version might not support issue updates via API.`); - console.warn(`Please manually close issue #${number} at: ${htmlUrl}\n`); + console.warn(`\n[Info] GitBucket API (PATCH) returned 404. Issue edit may not be supported in your version.`); + console.warn(`Posting current body as a comment instead...`); + const posted = await postIssueComment(number, body); + if (posted) { + console.warn(`[Done] Comment posted on #${number}. View: ${htmlUrl}\n`); + return { _commentFallback: true, html_url: htmlUrl }; + } + console.warn(`Please edit manually: ${htmlUrl}\n`); return { _manual: true, html_url: htmlUrl }; } throw err; @@ -165,11 +187,13 @@ } const updated = await updateRemoteIssue(idStr, meta.title, body, meta.state || 'open'); - if (updated && !updated._manual) { + if (updated && !updated._manual && !updated._commentFallback) { // Update local metadata timestamp to match remote const newMeta = { ...meta, state: updated.state, updated_at: updated.updated_at }; fs.writeFileSync(filePath, stringifyMarkdown(newMeta, updated.body)); console.log(`[Pushed] Updated #${idStr} on remote.`); + } else if (updated && updated._commentFallback) { + console.log(`[Pushed] #${idStr}: body posted as comment (PATCH not supported).`); } else { console.log(`[Skip] Remote update for #${idStr} requires manual intervention or failed.`); }