Badge API
The Badge API evaluates various project metrics fetched from a git provider (currently only gitlab is supported) and assigns corresponding badges to the project. Each badge can be tied to specific conditions, such as project maintenance, reuse, compliance, or open-source status.
Checkout the releases for details on the latest version and changes.
Configuration
The badge api is configured using a yaml configuration file with the name .badge-api.yaml. The program looks for this file in the current working directory and inside /etc/badge-api/.
In order to allow a flexible configuration of the API the actual configuration is available here. The config will automatically be reloaded every few minutes from the remote location/server.
The documentation for the configuration can be found here.
Development
- Launch Backend
- Optional: Launch Database:
docker compose up -d postgresql
cp .env.example .env
- Go through defined platforms in
.badge-api.yaml -> gitClients
cp secrets/glpat.secret.example secrets/glpat.secret
- Generate token: Docs
- For GitHub generate a token here: tokens (classic token). A token with no extra scopes covers the public read checks.
read:packages (packages check), push access (code review member matching) and admin access (branch protection) unlock the rest, which otherwise reports missing data.
make run
- Optional: Run checks via CLI
go run main.go check --help Show help for all available commands
go run main.go check --repository "https://gitlab.opencode.de/open-code/badgebackend/badge-api" Run check for a given repository
go run main.go check --all-repositories https://gitlab.opencode.de Run checks for all repositories for a given GitLab Instance
REMOTE_CONFIG_URL="https://gitlab.opencode.de/open-code/badgebackend/badge-config/-/raw/my-fancy-branch-name/" go run main.go check --repository "https://gitlab.opencode.de/open-code/badgebackend/badge-api" override the REMOTE_CONFIG_URL
- Run Demo Frontend
- Speedup testing by running local nginx cache:
docker compose up cache
- Run using
NGINX_OPENCODE_PROXY=true go run main.go check --all-repositories https://gitlab.opencode.de
- Clear cache:
sudo rm -R ./dev/nginx-cache/*
- Or in short:
sudo rm -R ./dev/nginx-cache/* ; docker compose up cache
- Generate mocks if necessary
- Tests
- Run tests using VSCode Testing Suite
- Linting (Optional)
- Performance Profiling
- Set Env Variable
ENABLE_PROFILING=true
- Run program
- Open results in browser:
go tool pprof -http=:6060 cpu.prof
Deployment (currently, to be changed in future)
- Clone Repository:
git clone git@gitlab.opencode.de:open-code/badgebackend/badge-api.git && cd badge-api
- Create pull secret for private docker registry:
kubectl create secret docker-registry regcred --docker-server=registry.opencode.de --docker-username='<name>' --docker-password='<key>' -n <your-namespace>
- Modify the values file in the helm-chart folder. Pay special attention to the
config and secretMounts sections.
- The secretFileMounts section is used to mount any tokens needed for git providers into the pod.
- The secretFileMounts and the config section must match in file paths!
- Install with helm:
helm install badge-api ./helm-chart