Skip to content

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 toolingforge-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.mjs

Set 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 codeMeaning
0Every live issue deleted.
1The git remote URL could not be parsed, or at least one deletion failed after the run started.
2No GW_ADMIN_TOKEN, and no token found in the credential file.
3No archive file at the fixed path.
4Listing live issues from the Forge failed.
5At least one live issue is absent from the archive; nothing is deleted.
6The 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.mjs

Run 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.mjs

Notes

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:

  • forge in the path: +4
  • token, pat, or key: +3
  • admin or owner: +2
  • user, login, name, host, or url: -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