No description
  • JavaScript 100%
Find a file
Max Fiedler 6dd1a4f00d Add EXCLUDE_LANGUAGES option to drop noise languages from output
Comma-separated env var (case-insensitive exact match) lets the
operator suppress languages like "Rich Text Format", "GLSL", "HLSL"
that would otherwise inflate the totals. Documented in README and
.env.example.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 22:21:08 +02:00
.claude Initial commit: Forgejo language stats aggregator 2026-05-09 21:57:48 +02:00
.env.example Add EXCLUDE_LANGUAGES option to drop noise languages from output 2026-05-09 22:21:08 +02:00
.gitattributes Initial commit: Forgejo language stats aggregator 2026-05-09 21:57:48 +02:00
.gitignore Exclude data results 2026-05-09 22:06:55 +02:00
CLAUDE.md Initial commit: Forgejo language stats aggregator 2026-05-09 21:57:48 +02:00
README.md Add EXCLUDE_LANGUAGES option to drop noise languages from output 2026-05-09 22:21:08 +02:00
update-stats.js Add EXCLUDE_LANGUAGES option to drop noise languages from output 2026-05-09 22:21:08 +02:00

Git language stats

Check all Git repositories for a user on a Forgejo instance and collect the statistics about the used programming languages. Save the collected data in a JSON file.

The resulting JSON is suitable as a data source for a website that, for example, displays a percentage breakdown of the languages used across all of the user's repositories.

Requirements

  • Node.js 20.12 or later (the script uses the built-in global fetch and process.loadEnvFile() to read the .env file without any dependencies).

Setup

  1. Copy the example environment file and edit it with your own values:

    cp .env.example .env
    
  2. Open .env and set:

    • FORGEJO_URL — base URL of your Forgejo instance.
    • FORGEJO_USERNAME — the user whose repositories should be scanned.
    • FORGEJO_TOKEN — an API token. Generate one in Forgejo under Settings > Applications with repository and user read permissions.
    • OUTPUT_PATH (optional) — where the JSON file is written. Defaults to /var/www/html/languages.json.
    • INCLUDE_FORKS (optional) — set to false to skip forked repositories. Defaults to including them.
    • EXCLUDE_LANGUAGES (optional) — comma-separated list of language names to drop from the output (e.g. Rich Text Format, GLSL, HLSL). Matching is case-insensitive and exact; whitespace around entries is ignored. Defaults to excluding nothing.

    .env is listed in .gitignore, so your token will not be committed.

    If you prefer, you can also export the variables directly in your shell or cron environment instead of using a .env file.

Run

node update-stats.js

Scheduling with cron

To run the script automatically (e.g. nightly at midnight), add an entry to your crontab with crontab -e:

0 0 * * * /usr/bin/node /opt/scripts/update-stats.js >> /var/log/git-language-stats.log 2>&1

Notes:

  • Use the absolute path to both node and the script. Cron runs with a minimal PATH, so bare commands often fail. Find your Node binary with which node.
  • Cron does not load your shell profile, so environment variables exported in ~/.bashrc or ~/.profile will not be available. Keep your configuration in the .env file next to the script — it is loaded automatically regardless of how the script is invoked.
  • The >> … 2>&1 part is optional but recommended: it appends both stdout and stderr to a log file so you can debug failed runs.
  • Make sure the user running the cron job has write permission to OUTPUT_PATH.