Created
February 4, 2026 05:30
-
-
Save phpwalter/786c54cbc391c930c4d10e5a205eef53 to your computer and use it in GitHub Desktop.
Completly deletes all LABLELS within a given project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. CONFIGURATION | |
| // Generate a token at: https://github.com/settings/tokens | |
| // Scope required: 'repo' (or 'public_repo' if public) | |
| const CONFIG = { | |
| token: "YOUR_ACCESS_TOKEN_HERE", | |
| owner: "USERNAME_OR_ORG", | |
| repo: "REPOSITORY_NAME" | |
| }; | |
| // 2. THE SCRIPT | |
| async function nukeLabels() { | |
| const headers = { | |
| "Authorization": `token ${CONFIG.token}`, | |
| "Accept": "application/vnd.github.v3+json" | |
| }; | |
| try { | |
| console.log("🔄 Fetching label list..."); | |
| let labels = []; | |
| let page = 1; | |
| // Step 1: Fetch ALL labels (handling pagination) | |
| while (true) { | |
| const url = `https://api.github.com/repos/${CONFIG.owner}/${CONFIG.repo}/labels?per_page=100&page=${page}`; | |
| const res = await fetch(url, { headers }); | |
| if (!res.ok) throw new Error(`Fetch failed: ${res.status} ${res.statusText}`); | |
| const data = await res.json(); | |
| if (data.length === 0) break; | |
| labels = labels.concat(data); | |
| page++; | |
| } | |
| console.log(`⚠️ Found ${labels.length} labels. Deleting...`); | |
| // Step 2: Delete one by one | |
| for (const label of labels) { | |
| console.log(`Deleting: ${label.name}`); | |
| // EncodeURIComponent is vital for labels with spaces or emojis | |
| const deleteUrl = `https://api.github.com/repos/${CONFIG.owner}/${CONFIG.repo}/labels/${encodeURIComponent(label.name)}`; | |
| const delRes = await fetch(deleteUrl, { | |
| method: "DELETE", | |
| headers | |
| }); | |
| if (!delRes.ok) console.error(`Failed to delete ${label.name}`); | |
| } | |
| console.log("✅ Operation Complete: All labels deleted."); | |
| } catch (err) { | |
| console.error("❌ Error:", err.message); | |
| console.log("Double-check your Token and Repo/Owner names."); | |
| } | |
| } | |
| // 3. RUN | |
| nukeLabels(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment