- Python 76.7%
- Shell 23.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| deploy | ||
| docs | ||
| tests | ||
| .gitignore | ||
| apply.py | ||
| check_mirror_health.py | ||
| check_upstream.py | ||
| forgejo.py | ||
| init_instance.py | ||
| instance.py | ||
| LICENSE | ||
| liveness.py | ||
| metrics.py | ||
| publiccode_checks.py | ||
| README.md | ||
| scan_models.py | ||
| scan_publiccode.py | ||
| seed_archived_repo.py | ||
| set_org_avatars.py | ||
| smoke.sh | ||
| sync.py | ||
forgejo-mirror-sync
Mirrors a curated list of public code repositories into a Forgejo instance and reports on them: whether each upstream still exists, its publiccode.yml, and the AI models the code uses. It runs git.opencode.swiss, the read-only mirror described in opencode-forges, and is meant to be reusable by other instances. Each instance keeps its own settings in a directory of its own; git.opencode.swiss's are in opencode-forges.
This code was written with the help of AI assistants (Claude). It is published under the MIT licence.
What a run does
sync.py is the entry point. A scheduled run:
- Regenerates the mirror sets from the catalogues the instance trusts, so a repository a catalogue adds is picked up without anyone editing a list.
- Creates the missing mirrors as native Forgejo pull mirrors, one organisation per upstream owner. Forgejo keeps them in sync on its own schedule.
- Holds what needs a person: a new organisation, or a repository over the size cap, waits until someone approves the ticket the run opens for it.
- Checks each upstream, pausing mirrors whose upstream is gone and keeping them readable.
- Tags every repository with topics such as its sector, a missing licence and whether it has a
publiccode.yml, so visitors can filter. - Lists the AI models the mirrored code uses, with a digest of every file of each revision.
- Publishes a report of what changed to a repository on the instance, and alerts when something needs attention.
Without --apply, a run only reports and changes nothing.
Scripts
| Script | What it does |
|---|---|
| sync.py | Runs the steps above in order, and writes the report |
| apply.py | Creates mirrors and organisations from a mirror set, and sets topics; safe to run again |
| scan_publiccode.py | Finds which mirrors carry a publiccode.yml |
| scan_models.py | Lists the Hugging Face models the code names or declares in a bill of materials, and keeps a record of each revision; a repository elsewhere counts as holding a model only when a bill of materials declares it |
| liveness.py | Asks GitHub which upstream repositories still exist |
| check_mirror_health.py | Checks that every mirror exists and is in sync with its upstream |
| check_upstream.py | Records the size of each upstream repository |
| metrics.py | Writes the instance's figures as a page of their own |
| init_instance.py | Creates what the run expects on a new instance: the report repository with its decision files, the labels and each organisation's team; safe to run again |
| set_org_avatars.py | Gives each organisation its upstream owner's avatar |
| seed_archived_repo.py | Imports an archived repository too large to mirror in one go |
| forgejo.py | The Forgejo API client the scripts share |
| instance.py | Where the instance's files are, and what its instance.json says |
Setting up an instance
Everything that belongs to one instance lives in a directory of its own, named by INSTANCE_DIR:
instance.json: the instance's name, the catalogue sources in order of precedence with the generator for each, and a few labels. instance.py lists every setting.sources/: the generators, one per source, each writing a mirror set todata/.data/: the mirror sets, caches and credentials. Never committed.deploy/: the instance's manifests (see deploy/README.md).
git.opencode.swiss is the worked example: its instance directory has three sources (the federal catalogue, the OSS benchmark and the Swiss index) and a Kubernetes deployment.
Running it
export INSTANCE_DIR=<the instance's directory>
source "$INSTANCE_DIR/data/forgejo.env" # FORGEJO_URL and the bot's credentials
python3 init_instance.py # what is missing on the instance; --apply creates it
python3 sync.py # report only
python3 sync.py --apply --report # the weekly run
deploy/README.md covers deploying it, and deploy/expected-env.txt lists the environment variables the code reads.
Tests
INSTANCE_DIR=… ./smoke.shchecks the tool together with an instance, and the deployment when you are logged in to the cluster.python3 -I tests/test_boms.pychecks how bills of materials are read, without network access.
Reference
The design reasons and operating details, in full:
| Document | Covers |
|---|---|
| docs/sign-off.md | Organisation rights, the import size gate, and approving or declining through tickets |
| docs/scheduled-refresh.md | The scheduled run: order of steps, health checks, exit codes, and how gone upstreams are paused |
| docs/link-outs.md | Sending visitors to the upstream issue tracker and wiki |