Source: https://seerepo.com/docs/api-files
Markdown source: https://seerepo.com/docs/api-files.md
Description: What's in the repo and how much it weighs: every folder and file with its size and class, and for code what a test reaches and what's unused.

# The repo's files

`GET https://seerepo.com/api/v1/repos/:repo/files`

Says what's in the repo, code or not, and how much it weighs: one folder with its folders and its files, or the whole repo by size or by a column of its code. It comes from the tree GitHub gives of the commit SeeRepo read, and SeeRepo keeps it with each read: no call of yours goes to GitHub.

Each file has its class: `code`, `test`, `config`, `docs`, `image`, `data`, `binary` or `other`. What was generated, copied in from someone else, served as it is or kept in Git LFS is a mark on top of the class, so a generated image is still an image. For code, it adds what SeeRepo knows of the file: its lines, its module, whether a test reaches it, whether it's unused, its days with changes in the last 30 and its open health tasks.

What's in the repo's ignored paths is never listed: only how many there are. Sizes are in bytes.

## Request

| Parameter | Where | Description |
|---|---|---|
| `repo` | path | The repo's id, or owner/name with %2F. |
| `path` | query | Optional. A folder, from the repo's root, like `src/app`. The root by default. |
| `whole` | query | Optional. `1` for the whole repo instead of one folder. |
| `sort` | query | Optional. `size` (the default), `lines`, `changes`, `untested` or `unused`. |
| `class` | query | Optional. Only files of that class. |
| `limit` | query | Optional. How many files: 50 by default, 200 at most. |

```sh
curl "https://seerepo.com/api/v1/repos/6ad79fd8e89233277ded17c9/files?whole=1&sort=size" \
  -H "Authorization: Bearer $SEEREPO_KEY"
```

## Response

| Field | Type | Description |
|---|---|---|
| `data.read.sha` | string | The commit whose tree this is. |
| `data.read.partial` | boolean | GitHub sent only part of the tree: every file is listed, some without their size. |
| `data.read.ignored` | number | How many paths the repo's ignored paths leave out. |
| `data.path` | string | Only for a folder: the folder, `/` at the root. |
| `data.totals` | object | Only for a folder: `files`, `folders`, `size` and `unknownSize` of everything under it, and `byClass` with `files` and `size` by class. |
| `data.folders[]` | object | Only for a folder: its folders, the heaviest first, each with its `path` and the same sums. |
| `data.total` | number | How many files match, before `limit`. |
| `data.files[]` | object | `path`, `size` (null when unknown), `class`, `flags[]` (`generated`, `vendored`, `static`, `lfs`, `submodule`) and `code`. |
| `data.files[].code` | object\|null | For code SeeRepo read: `lines`, `kind`, `module` (`path` and `name`), `tested`, `unused`, `kit`, `changedDays` and `tasks`. Null otherwise. |

### Example

```json
{
  "status": "success",
  "data": {
    "read": { "sha": "0afb68a8c…", "partial": false, "ignored": 0 },
    "whole": true,
    "sort": "size",
    "total": 3,
    "files": [
      { "path": "public/hero.png", "size": 4210000, "class": "image", "flags": ["static"], "code": null },
      { "path": "src/app/page.tsx", "size": 18200, "class": "code", "flags": [], "code": { "lines": 412, "kind": "screen", "module": { "path": "/home", "name": "Home" }, "tested": false, "unused": false, "kit": null, "changedDays": 6, "tasks": 1 } }
    ]
  }
}
```

## Errors

| Status | Code | When |
|---|---|---|
| 400 | `bad_sort` | `sort` isn't one of the five. |
| 400 | `bad_class` | `class` isn't one of the eight. |
| 404 | `unknown_folder` | That folder isn't in the repo, or it's in its ignored paths. |
| 404 | `not_read_yet` | SeeRepo keeps this at the repo's next read. |
