|
1 | | -# REST |
| 1 | +# REST pipeline |
| 2 | + |
| 3 | +Our REST pipeline creates autogenerated REST API documentation for docs.github.com/rest from the OpenAPI stored in the open-source repository [`github/rest-api-description`](https://github.com/github/rest-api-description). |
| 4 | + |
| 5 | +The pipeline is used to generate data that is used by the docs.github.com site when deployed locally, in preview environments, or in production. |
| 6 | + |
| 7 | +## How does it work |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +A [workflow](.github/workflows/sync-openapi.yml) is used to trigger the automation of the REST documentation. The workflow runs automatically on a schedule. The workflow that triggers the REST pipeline also triggers other automation pipelines that use the OpenAPI as the source data: |
| 12 | +- GitHub Apps |
| 13 | +- REST |
| 14 | +- Webhooks |
| 15 | + |
| 16 | +The workflow automatically creates a pull request with the changes (for all three pipelines) and the label `github-openapi-bot`. The workflow runs the `src/rest/scripts/update-files.js` script, which creates, deletes, or updates Markdown files in the `content/rest` directory. |
| 17 | + |
| 18 | +### Triggering the workflow sooner than the scheduled time |
| 19 | + |
| 20 | +You can manually run the workflow leaving the source branch input parameter with the default value of `main`. Running the workflow creates a new pull request in the `github/docs-internal` repo with the changes. |
| 21 | + |
| 22 | +### Triggering the workflow with a different source branch |
| 23 | + |
| 24 | +If there is a pull request that is still unmerged in `github/rest-api-description` that needs to be propagated to the docs.github.com site, manually run the workflow and provide the branch name of the pull request in the `github/rest-api-description` repo that you would like to get the changes from. This will create a new pull request in the `github/docs-internal` repo with the changes. |
| 25 | + |
| 26 | +## Local development |
| 27 | + |
| 28 | +To run the REST pipeline locally: |
| 29 | + |
| 30 | +1. Clone the [`github/rest-api-description`](https://github.com/github/rest-api-description) repository inside your local `docs-internal` repository. |
| 31 | +1. Run `src/rest/scripts/update-files.js -s rest-api-description -o rest`. Note, by default `-o rest` is specified, so you can omit it. |
2 | 32 |
|
3 | 33 | ## About this directory |
4 | 34 |
|
5 | | -* `src/rest/lib/index.js` is human-editable. |
6 | | -* `src/rest/data/*.json` are generated by [scripts](../../src/rest/scripts/README.md). |
| 35 | +- `src/rest/api` - The source code for the api endpoint used in production that redirects specific anchor links on a page under `docs.github.com/rest`. |
| 36 | +- `src/rest/data` - The automatically generated data files created by running this pipeline. |
| 37 | +- `src/rest/lib` - The source code used in production for the automated documentation generated by the REST pipeline and configuration files edited by content and engineering team members. |
| 38 | + - `src/rest/lib/config.json` - A configuration file used to specify metadata about the REST pipeline. |
| 39 | +- `src/rest/scripts` - The scripts and source code used run the REST pipeline, which updates the `src/rest/data` directory. |
| 40 | + - `src/rest/scripts/update-files.js` - The entrypoint script that runs the REST pipeline. |
| 41 | +- `src/rest/tests` - The tests used to verify the REST pipeline. |
| 42 | + |
| 43 | +## Configuring the pipeline |
| 44 | + |
| 45 | +The `src/rest/lib/config.json` file contain metadata used by the content and engineering team to configure the REST pipeline. The file contains the following properties: |
7 | 46 |
|
8 | | -## Editable files |
| 47 | +- `api-versions` - A list of the calendar-date API versions that are available for each version. |
| 48 | +- `versionMapping` - A mapping of the API version name used in the OpenAPI schema in `github/rest-api-description` to the version short name used in the `github/docs-internal` repo. |
| 49 | +- `frontmatterDefaults` - A list of default frontmatter values to append to each Markdown file in `content/rest`. |
| 50 | +- `targetDirectory` - The directory in `content` where the Markdown files that correspond to this pipeline are located. |
| 51 | +- `indexOrder` - The order of the children in the `index.md` file in the `targetDirectory`. The `startsWith` keyword lists the directories under `targetDirectory` that should be listed first. All other automatically created directories are appended to this list. |
| 52 | +- `sha` - The SHA of the commit in `github/rest-api-description` that was used to generate the data in `src/rest/data` and Markdown files in `content/rest`. This value is automatically updated when the pipeline runs. |
9 | 53 |
|
10 | | -* `src/rest/lib/index.js` consumes the static decorated schema files and exports `categories`, `operations`, and `operationsEnabledForGitHubApps` used by the REST middleware contextualizer. |
| 54 | +## Content team |
11 | 55 |
|
12 | | -## Static files |
| 56 | +The content writers can manually update parts of the autogenerated Markdown files in `content/rest`. When new Markdown files are added they will get all of the frontmatter properties defined in the `defaultFrontmatter` property in `src/rest/lib/config.js`. |
13 | 57 |
|
14 | | -Generated by `src/rest/scripts/update-files.js`: |
| 58 | +When a new Markdown file is created, a writer can manually change any of the frontmatter except `versions`. The pipeline will overwrite the `versions` property on subsequent runs, but will not modify any other frontmatter properties. |
15 | 59 |
|
16 | | -* `src/rest/data` - files generated from the dereferenced OpenAPI schema with the Markdown descriptions rendered in HTML |
17 | | -* `src/rest/data/dereferenced` - **NOTE** These are only generated if you pass the --keep-dereferenced-files option and are not checked into the repository. This option is for debug only. |
| 60 | +Writers can also add an introduction paragraph _above_ the following Markdown comment: |
18 | 61 |
|
19 | | -## Rendering docs |
| 62 | +```markdown |
| 63 | +<!-- Content after this section is automatically generated --> |
| 64 | +``` |
20 | 65 |
|
21 | | -When the server starts, `middleware/contextualizers/rest.js` accesses the data exported from the static decorated JSON files, fetches the data for the current version and requested path, and adds it to the `context` object. The added property is: |
| 66 | +## How to get help |
22 | 67 |
|
23 | | -* `req.context.currentRestOperations` - all operations with a category matching the current path |
| 68 | +Slack: `#docs-engineering` |
| 69 | +Repo: `github/docs-engineering` |
24 | 70 |
|
25 | | -Markdown files in `content/rest/reference` use Liquid to loop over these context properties. The Liquid calls HTML files in the `includes` directory to do most of the rendering. Writers can add content to the Markdown files alongside the Liquid. |
| 71 | +If you have a question about the REST pipeline, you can ask in the `#docs-engineering` Slack channel. If you notice a problem with the REST pipeline, you can open an issue in the `github/docs-engineering` repository. |
0 commit comments