Coverage

Coverage docs

The words

A percent is covered divided by total, and 100 when the total is 0. It is red below 80, yellow below 95 and green from 95.

POST /api/v1/upload

Send the header Authorization: Bearer <token> (the token names the repo) and Content-Type: application/json. The body may be gzip, with Content-Encoding: gzip.

Upload with curl
gzip -c report.json | curl --fail-with-body \
  -X POST https://coverage.utilarium.app/api/v1/upload \
  -H "Authorization: Bearer $COVERAGE_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Content-Encoding: gzip" \
  --data-binary @-
Upload with Node
import { gzipSync } from "node:zlib";

const report = {
  commit: process.env.GITHUB_SHA,
  branch: process.env.GITHUB_REF_NAME,
  flag: "apps/coro",
  message: "Fix the login page",
  files: [
    {
      path: "client/lib/x.ts",
      lines: [12, 14], // [covered, total]
      statements: [13, 15],
      functions: [3, 3],
      branches: [4, 6],
      missed: "3-5,9", // the uncovered lines, as sorted ranges
    },
  ],
};

const response = await fetch("https://coverage.utilarium.app/api/v1/upload", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.COVERAGE_TOKEN}`,
    "Content-Type": "application/json",
    "Content-Encoding": "gzip",
  },
  body: gzipSync(JSON.stringify(report)),
});
console.log(response.status, await response.json());
GitHub Actions step
- name: Upload coverage
  run: node upload-coverage.mjs
  env:
    COVERAGE_TOKEN: ${{ secrets.COVERAGE_TOKEN }}

The body

Body
{
  "commit": "0123456789abcdef0123456789abcdef01234567",
  "branch": "main",
  "flag": "apps/coro",
  "message": "Fix the login page",
  "files": [
    {
      "path": "client/lib/x.ts",
      "lines": [12, 14],
      "statements": [13, 15],
      "functions": [3, 3],
      "branches": [4, 6],
      "missed": "3-5,9"
    }
  ]
}

Any other field is refused, so a typo does not go unnoticed. Two files cannot have the same path.

Limits

Answers

201
{
  "ok": true,
  "upload": "42",
  "url": "https://coverage.utilarium.app/r/kamadorueda/apps/commit/0123456789abcdef0123456789abcdef01234567"
}

One upload for each repo, commit and flag: a second upload replaces the first (its files too), so you can send again after a retry.

Badge

A badge shows the line coverage of the default branch. It is off until you turn on "Public badge" in the repo's settings; until then the address answers 404. Add ?flag=apps/coro for one flag.

Markdown
![coverage](https://coverage.utilarium.app/api/v1/badge/<owner>/<name>.svg)