Appearance
forge-purge-issues.mjs
Deletes every live Forgejo issue in this repository, but only once each one is confirmed present in the local archive.
Agent tooling › forge-purge-issues.mjs
What it does
Resolves an admin-capable Forge token from GW_ADMIN_TOKEN or a JSON credential file, then lists every issue on the repository's Forge instance across every page. Compares that live set against a local archive at a fixed path and refuses to delete anything when a live issue is missing from it. Deletes every live issue once that check passes, then reports how many succeeded.
Usage
scripts/forge-purge-issues.mjs reads no command-line arguments — every option is an environment variable. The whole invocation:
bash
node scripts/forge-purge-issues.mjsSet GW_ADMIN_TOKEN to supply the credential directly, or GW_OWNER_CREDENTIALS to point at a credential file other than the default, C:/ProgramData/my-harness/owner-credentials.json.
Options
No options.
Inputs and outputs
Reads git remote get-url origin for the repository context, the credential file or GW_ADMIN_TOKEN, and the archive at D:/my-repos/.showroom/grafted-wars/forge-archive/issues.json. Writes nothing to disk itself; every deletion is a DELETE request against the Forge issues API.
On success, it prints one line per deleted issue and a final deleted X/Y. Remaining: Z. summary. On any failure, it prints one line to stderr naming the reason.
| Exit code | Meaning |
|---|---|
0 | Every live issue deleted. |
1 | The git remote URL could not be parsed, or at least one deletion failed after the run started. |
2 | No GW_ADMIN_TOKEN, and no token found in the credential file. |
3 | No archive file at the fixed path. |
4 | Listing live issues from the Forge failed. |
5 | At least one live issue is absent from the archive; nothing is deleted. |
6 | The credential file exists but cannot be read (EPERM/EACCES) — it is restricted to Administrators/SYSTEM. |
Examples
Run it with an explicit token, bypassing the credential file entirely:
bash
GW_ADMIN_TOKEN=<admin-token> node scripts/forge-purge-issues.mjsRun it from an elevated shell using the default credential file, once a fresh archive export already exists at the archive path:
bash
node scripts/forge-purge-issues.mjsNotes
This script deletes every issue in the tracker; nothing about it is reversible from inside the repository. The archive check is the only guard — there is no --dry-run and no confirmation prompt.
The credential file is not read by a fixed field name. The scan, findForgeToken, walks the whole JSON tree and scores every string of at least 8 characters by its key path:
forgein the path:+4token,pat, orkey:+3adminorowner:+2user,login,name,host, orurl:-5
It picks the highest-scoring string among those scoring 4 or above. A credential file shaped differently than expected can silently pick the wrong string instead of failing to find one.
parseRemote is imported directly from tools/forge.mjs rather than reimplemented, so the two tools agree on how a remote URL resolves to an owner and repo.
The archive itself is not produced by anything in this repository; the script only reads it, and refuses to run without one already at the fixed path.
Source
scripts/forge-purge-issues.mjs — part of Agent tooling