No description
- JavaScript 100%
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> |
||
|---|---|---|
| .claude | ||
| .env.example | ||
| .gitattributes | ||
| .gitignore | ||
| CLAUDE.md | ||
| README.md | ||
| update-stats.js | ||
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
fetchandprocess.loadEnvFile()to read the.envfile without any dependencies).
Setup
-
Copy the example environment file and edit it with your own values:
cp .env.example .env -
Open
.envand 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 tofalseto 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.
.envis 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
.envfile.
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
nodeand the script. Cron runs with a minimalPATH, so bare commands often fail. Find your Node binary withwhich node. - Cron does not load your shell profile, so environment variables exported in
~/.bashrcor~/.profilewill not be available. Keep your configuration in the.envfile next to the script — it is loaded automatically regardless of how the script is invoked. - The
>> … 2>&1part 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.