|
| 1 | +Design of Pull Request Builder |
| 2 | +============================== |
| 3 | + |
| 4 | +Background |
| 5 | +---------- |
| 6 | + |
| 7 | +This will focus on automatically building documentation for Pull Requests on Read the Docs projects. |
| 8 | +This is one of the most requested feature of Read the Docs. |
| 9 | +This document will serve as a design document for discussing how to implement this features. |
| 10 | + |
| 11 | +Scope |
| 12 | +----- |
| 13 | + |
| 14 | +- Making Pull Requests work like temporary ``Version`` |
| 15 | +- Excluding PR Versions from Elasticsearch Indexing |
| 16 | +- Adding a ``PR Builds`` Tab in the Project Dashboard |
| 17 | +- Updating the Footer API |
| 18 | +- Adding Warning Banner to Docs |
| 19 | +- Serving PR Docs |
| 20 | +- Excluding PR Versions from Search Engines |
| 21 | +- Receiving ``pull_request`` webhook event from Github |
| 22 | +- Fetching data from pull requests |
| 23 | +- Storing PR Version build Data |
| 24 | +- Creating PR Versions when a pull request is opened and Triggering a build |
| 25 | +- Triggering Builds on new commits on a PR |
| 26 | +- Status reporting to Github |
| 27 | + |
| 28 | +Fetching Data from Pull Requests |
| 29 | +-------------------------------- |
| 30 | + |
| 31 | +We already get Pull request events from Github webhooks. |
| 32 | +We can utilize that to fetch data from pull requests. |
| 33 | +when a ``pull_request`` event is triggered we can fetch the data of that pull request. |
| 34 | +We can fetch the pull request by doing something similar to travis-ci. |
| 35 | +ie: ``git fetch origin +refs/pull/<pr_number>/merge:`` |
| 36 | + |
| 37 | +Modeling Pull Requests as a Type of Version |
| 38 | +------------------------------------------- |
| 39 | + |
| 40 | +Pull requests can be Treated as a Type of Temporary ``Version``. |
| 41 | +We might consider adding a ``VERSION_TYPES`` to the ``Version`` model. |
| 42 | + |
| 43 | +- If we go with ``VERSION_TYPES`` we can add something like ``pull_request`` alongside Tag and Branch. |
| 44 | + |
| 45 | +We should add ``Version`` and ``Build`` Model Managers for PR and Regular Versions and Builds. |
| 46 | +The proposed names for PR and Regular Version and Build Mangers are ``external`` and ``internal``. |
| 47 | + |
| 48 | +We can then use ``Version.internal.all()`` to get all regular versions, |
| 49 | +``Version.external.all()`` to get all PR versions. |
| 50 | + |
| 51 | +We can then use ``Build.internal.all()`` to get all regular version builds, |
| 52 | +``Build.external.all()`` to get all PR version builds. |
| 53 | + |
| 54 | + |
| 55 | +Excluding PR Versions from Elasticsearch Indexing |
| 56 | +------------------------------------------------- |
| 57 | + |
| 58 | +We should exclude to PR Versions from being Indexed to Elasticsearch. |
| 59 | +We need to update the queryset to exclude PR Versions. |
| 60 | + |
| 61 | +Adding a PR Builds Tab in the Project Dashboard |
| 62 | +----------------------------------------------- |
| 63 | + |
| 64 | +We can add a Tab in the project dashboard that will listout the PR Builds of that project. |
| 65 | +We can name it ``PR Builds``. |
| 66 | + |
| 67 | +Creating Versions for Pull Requests |
| 68 | +----------------------------------- |
| 69 | + |
| 70 | +If the Github webhook event is ``pull_request`` and action is ``opened``, |
| 71 | +this means a pull request was opened in the projects repository. |
| 72 | +We can create a ``Version`` from the Payload data and trigger a initial build for the version. |
| 73 | +A version will be created whenever RTD receives an event like this. |
| 74 | + |
| 75 | +Triggering Build for New Commits in a Pull Request |
| 76 | +-------------------------------------------------- |
| 77 | + |
| 78 | +We might want to trigger a new build for the PR version if there is a new commit on the PR. |
| 79 | +If the Github webhook event is ``pull_request`` and action is ``synchronize``, |
| 80 | +this means a new commit was added to the pull request. |
| 81 | + |
| 82 | +Status Reporting to Github |
| 83 | +-------------------------- |
| 84 | + |
| 85 | +We could send build status reports to Github. We could send if the build was Successful or Failed. |
| 86 | +We can also send the build URL. By this we could show if the build passed or failed on Github something like travis-ci does. |
| 87 | + |
| 88 | +As we already have the ``repo:status`` scope on our OAuth App, |
| 89 | +we can send the status report to Github using the Github Status API. |
| 90 | + |
| 91 | +Sending the status report would be something like this: |
| 92 | + |
| 93 | +.. http:post:: /repos/:owner/:repo/statuses/:sha |
| 94 | +
|
| 95 | +.. code:: json |
| 96 | +
|
| 97 | + { |
| 98 | + "state": "success", |
| 99 | + "target_url": "<pr_build_url>", |
| 100 | + "description": "The build succeeded!", |
| 101 | + "context": "continuous-documentation/read-the-docs" |
| 102 | + } |
| 103 | +
|
| 104 | +Storing Pull Request Docs |
| 105 | +------------------------- |
| 106 | + |
| 107 | +We need to think about how and where to store data after a PR Version build is finished. |
| 108 | +We can store the data in a blob storage. |
| 109 | + |
| 110 | +Excluding PR Versions from Search Engines |
| 111 | +----------------------------------------- |
| 112 | + |
| 113 | +We should Exclude the PR Versions from Search Engines, |
| 114 | +because it might cause problems for RTD users. |
| 115 | +As users might land to a pull request doc but not the original Project Docs. |
| 116 | +This will cause confusion for the users. |
| 117 | + |
| 118 | +Serving PR Docs |
| 119 | +--------------- |
| 120 | + |
| 121 | +We need to think about how we want to serve the PR Docs. |
| 122 | + |
| 123 | +- We could serve the PR Docs from another Domain. |
| 124 | +- We could serve the PR Docs using ``<pr_number>`` namespace on the same Domain. |
| 125 | + |
| 126 | + - Using ``pr-<pr_number>`` as the version slug ``https://<project_slug>.readthedocs.io/<language_code>/pr-<pr_number>/`` |
| 127 | + - Using ``pr`` subdomain ``https://pr.<project_slug>.readthedocs.io/<pr_number>/`` |
| 128 | + |
| 129 | + |
| 130 | +Updating the Footer API |
| 131 | +----------------------- |
| 132 | + |
| 133 | +We need to update the Footer API to reflect the changes. |
| 134 | +We might want to have a way to show that if this is a PR Build on the Footer. |
| 135 | + |
| 136 | +- For regular project docs we should remove the PR Versions from the version list of the Footer. |
| 137 | +- We might want to send ``is_pr`` data with the Footer API response. |
| 138 | + |
| 139 | +Adding Warning Banner to Docs |
| 140 | +----------------------------- |
| 141 | + |
| 142 | +We need to add a warning banner to the PR Version Docs to let the users know that this is a Draft/PR version. |
| 143 | +We can use a sphinx extension that we will force to install on the PR Versions to add the warning banner. |
| 144 | + |
| 145 | +Related Issues |
| 146 | +-------------- |
| 147 | + |
| 148 | +- `Autobuild Docs for Pull Requests`_ |
| 149 | +- `Add travis-ci style pull request builder`_ |
| 150 | + |
| 151 | + |
| 152 | +.. _Autobuild Docs for Pull Requests: https://github.com/rtfd/readthedocs.org/issues/5684 |
| 153 | +.. _Add travis-ci style pull request builder: https://github.com/rtfd/readthedocs.org/issues/1340 |
0 commit comments