feat(chronicle): コミット自動読み込みボタン追加(VPS /chronicle/activity 経由)

This commit is contained in:
posimai 2026-04-24 06:53:18 +09:00
parent 7eb0938afc
commit 4a5e695fa8
2 changed files with 59 additions and 2 deletions

View File

@ -228,7 +228,14 @@
<div class="sec-label">入力</div>
<div class="input-card">
<div class="field">
<label class="field-label" for="activities">主な活動</label>
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:6px">
<label class="field-label" for="activities" style="margin-bottom:0">主な活動</label>
<button class="btn btn-ghost" id="loadCommitsBtn"
style="font-size:11px;padding:4px 10px;display:inline-flex;align-items:center;gap:5px">
<i data-lucide="git-commit-horizontal" style="width:12px;height:12px;stroke-width:1.5"></i>
コミットから読み込む
</button>
</div>
<textarea id="activities" rows="5"
placeholder="実装した機能、解決した問題、取り組んだ作業などを自由に書いてください。箇条書きでもOK。"></textarea>
</div>
@ -477,6 +484,56 @@ document.getElementById('copyBtn').addEventListener('click', async () => {
}
});
// ── コミット読み込み ──────────────────
document.getElementById('loadCommitsBtn').addEventListener('click', async () => {
const token = getToken();
if (!token) { showToast('ログインが必要です'); return; }
const btn = document.getElementById('loadCommitsBtn');
btn.disabled = true;
btn.innerHTML = '<span class="spinner" style="border-color:rgba(0,0,0,.15);border-top-color:var(--text2)"></span> 読み込み中';
try {
const resp = await fetch(`${API}/chronicle/activity?days=${activeDays}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
if (resp.status === 503) {
showToast('VPS に CHRONICLE_GITHUB_TOKEN が未設定です');
return;
}
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const data = await resp.json();
if (!data.commits?.length) {
showToast('この期間にコミットが見つかりませんでした');
return;
}
const byRepo = {};
for (const c of data.commits) {
if (!byRepo[c.repo]) byRepo[c.repo] = [];
byRepo[c.repo].push(c.message);
}
const lines = [];
for (const [repo, messages] of Object.entries(byRepo)) {
lines.push(`【${repo}】`);
for (const m of messages) lines.push(`- ${m}`);
}
const area = document.getElementById('activities');
area.value = lines.join('\n');
showToast(`${data.commits.length} 件のコミットを読み込みました`);
} catch (e) {
showToast(`読み込み失敗: ${e.message}`);
} finally {
btn.disabled = false;
btn.innerHTML = '<i data-lucide="git-commit-horizontal" style="width:12px;height:12px;stroke-width:1.5"></i> コミットから読み込む';
lucide.createIcons();
}
});
// ── Toast ─────────────────────────────
function showToast(msg) {
const el = document.getElementById('toast');

View File

@ -30,7 +30,7 @@
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'; script-src 'self' 'unsafe-inline' https://unpkg.com https://posimai-ui.vercel.app; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com https://posimai-ui.vercel.app; font-src 'self' data: https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https://api.soar-enrich.com; worker-src 'self'; frame-ancestors 'none';"
"value": "default-src 'self'; script-src 'self' 'unsafe-inline' https://unpkg.com https://posimai-ui.vercel.app; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com https://posimai-ui.vercel.app; font-src 'self' data: https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https://api.soar-enrich.com https://api.github.com; worker-src 'self'; frame-ancestors 'none';"
},
{
"key": "Strict-Transport-Security",