// 1. CONFIGURATION const CONFIG = { token: "YOUR_ACCESS_TOKEN_HERE", owner: "USERNAME_OR_ORG", repo: "REPOSITORY_NAME" }; // 2. MAIN LOGIC async function startImport() { const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.onchange = (e) => { const file = e.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = async (event) => { try { const json = JSON.parse(event.target.result); console.log(`šŸ“‚ Loaded ${json.length} labels. Starting strict import...`); await importToGitHub(json); } catch (err) { console.error("āŒ Invalid JSON:", err.message); } }; reader.readAsText(file); }; input.click(); } async function importToGitHub(labels) { const headers = { "Authorization": `token ${CONFIG.token}`, "Accept": "application/vnd.github.v3+json", "Content-Type": "application/json" }; let created = 0, skipped = 0, errors = 0; for (const [i, item] of labels.entries()) { // --- STRICT LENGTH CHECK --- const desc = item.description || ""; if (desc.length > 99) { console.error(`āŒ SKIPPED [${i+1}] "${item.label}": Description too long (${desc.length} chars > 99)`); errors++; continue; // Skip to next iteration immediately } // Prepare Payload const payload = { name: item.label, description: desc, color: item.color.replace("#", "") }; try { const res = await fetch(`https://api.github.com/repos/${CONFIG.owner}/${CONFIG.repo}/labels`, { method: "POST", headers, body: JSON.stringify(payload) }); if (res.status === 201) { console.log(`āœ… [${i+1}] Created: "${payload.name}"`); created++; } else if (res.status === 422) { // We still check for duplicates here just in case const data = await res.json().catch(() => ({})); if (data.errors?.[0]?.code === 'already_exists') { console.warn(`āš ļø [${i+1}] Skipped (Exists): "${payload.name}"`); skipped++; } else { console.error(`āŒ [${i+1}] API Error: "${payload.name}"`, data); errors++; } } else { console.error(`āŒ [${i+1}] Failed: "${payload.name}" (${res.status})`); errors++; } } catch (err) { console.error(`āŒ Network Error on "${payload.name}"`, err); errors++; } // Safety Delay (500ms) await new Promise(r => setTimeout(r, 500)); } console.log(`\nšŸ IMPORT COMPLETE\nāœ… Created: ${created}\nāš ļø Skipped (Exists): ${skipped}\nāŒ Skipped (Errors/Long): ${errors}`); } // 3. RUN startImport();