Created
September 24, 2025 16:07
-
-
Save pi0/65a64c46807e0df8782259505dab3f34 to your computer and use it in GitHub Desktop.
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
| // list-notifications.js | |
| const API = "https://api.github.com/notifications"; | |
| const TOKEN = process.env.GITHUB_TOKEN; | |
| if (!TOKEN) { | |
| console.error("Set GITHUB_TOKEN (classic PAT with `notifications` scope)."); | |
| process.exit(1); | |
| } | |
| const args = process.argv.slice(2); | |
| const idIndex = args.indexOf("--id"); | |
| const threadId = idIndex !== -1 ? args[idIndex + 1] : null; | |
| if (threadId) { | |
| // Mark thread as read | |
| const res = await fetch(`${API}/threads/${threadId}`, { | |
| method: "DELETE", | |
| headers: { | |
| "Accept": "application/vnd.github+json", | |
| "Authorization": `Bearer ${TOKEN}`, | |
| }, | |
| }); | |
| if (res.ok) { | |
| console.log(`Thread ${threadId} marked as read ✅`); | |
| } else { | |
| console.error("Error:", res.status, res.statusText); | |
| } | |
| } | |
| const res = await fetch(API, { | |
| headers: { | |
| "Accept": "application/vnd.github+json", | |
| "Authorization": `Bearer ${TOKEN}`, | |
| }, | |
| }); | |
| if (!res.ok) { | |
| console.error("Error:", res.status, res.statusText); | |
| const txt = await res.text(); | |
| console.error(txt); | |
| process.exit(1); | |
| } | |
| const data = await res.json(); | |
| for (const n of data) { | |
| console.log( | |
| `[${n.repository.full_name}] ${n.subject.type}: ${n.subject.title} (id: ${n.id})` | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment