| Wendy Wang | 859617c | 2025-02-04 16:09:16 +0100 | [diff] [blame^] | 1 | # Gitiles API Reference |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | ### Formatting |
| 6 | |
| 7 | `?format=`: `TEXT`, `HTML`, and `JSON` |
| 8 | |
| 9 | The `JSON` output has a `)]}'` line at the top to prevent cross-site scripting. |
| 10 | When parsing, strip that line and the rest can be parsed normally. |
| 11 | |
| 12 | #### URL Format |
| 13 | Depending on the servlet context path set up to serve gitiles, the URL used to access these end points may differ. |
| 14 | |
| 15 | On gerrit.googlesource.com one URL is: `https://gerrit.googlesource.com/a/gitiles/+refs?format=TEXT`, while for a standard localhost deployment, the equivalent URL would be `http://localhost:8080/a/plugins/gitiles/test+refs?format=TEXT`. The examples given in this document are of the former form, to allow testing against real refs. They require authentication described in [the REST API Developer's Notes](https://gerrit-review.googlesource.com/Documentation/dev-rest-api.html). |
| 16 | |
| 17 | ### Endpoints |
| 18 | |
| 19 | #### **`+refs`** |
| 20 | `https://gerrit.googlesource.com/a/gitiles/+refs?format=TEXT` |
| 21 | |
| 22 | Lists all refs (branches, tags, etc.) in the repository. |
| 23 | |
| 24 | #### **`+log`** |
| 25 | `https://gerrit.googlesource.com/a/gitiles/+log/refs/heads/master?n=10&format=JSON` |
| 26 | |
| 27 | Shows the commit log. |
| 28 | Use the parameter `n=<number>` to limit the number of commits returned. |
| 29 | For paging use the start parameter `s=<next_cursor>`. |
| 30 | The `next` key in the JSON provides a cursor for the next page. Use it with `s=<next_cursor>`. |
| 31 | The final page will have no `next` key. |
| 32 | Every page except for the first will have a `previous` cursor to page backwards. |
| 33 | |
| 34 | #### **`+show`** |
| 35 | `https://gerrit.googlesource.com/a/gitiles/+show/refs/heads/master/?format=JSON` |
| 36 | |
| 37 | View the metadata about a given target. If the target is a file, use `format=TEXT` to view base64-encoded content, e.g. |
| 38 | ```bash |
| 39 | curl "https://gerrit.googlesource.com/a/gitiles/+show/refs/heads/master/README.md?format=TEXT" | base64 -d |
| 40 | ``` |
| 41 | |
| 42 | #### **`+archive`** |
| 43 | `https://gerrit.googlesource.com/a/gitiles/+archive/refs/heads/master.tar.gz` |
| 44 | |
| 45 | Download a compressed archive of a repository at a specific commit or ref. |
| 46 | Supported formats: `.tar.gz` and `.zip` |
| 47 | ```bash |
| 48 | curl "https://gerrit.googlesource.com/a/gitiles/+archive/refs/heads/master.tar.gz" -o repo.tar.gz |
| 49 | ``` |
| 50 | |
| 51 | #### **`+doc`** |
| 52 | `https://gerrit.googlesource.com/a/gitiles/+doc/refs/heads/master/README.md` |
| 53 | |
| 54 | Renders Markdown files into HTML. |
| 55 | |
| 56 | #### **`+blame`** |
| 57 | `https://gerrit.googlesource.com/a/gitiles/+blame/refs/heads/master/README.md` |
| 58 | |
| 59 | Shows line-by-line author information for a specific file (`git blame`). |
| 60 | |
| 61 | #### **`+diff`** |
| 62 | `https://gerrit.googlesource.com/a/gitiles/+diff/refs/heads/master/?from=master~1&to=master` |
| 63 | |
| 64 | Compute the diff between two commits. |