|
| 1 | +How to manually connect your Git repository |
| 2 | +=========================================== |
| 3 | + |
| 4 | +In this guide, you will find the simple steps to integrating your Read the Docs project with GitHub, Bitbucket, GitLab, Gitea or any other Git provider that supports our generic API. |
| 5 | + |
| 6 | +.. note:: |
| 7 | + |
| 8 | + If your account is connected to the provider, |
| 9 | + we'll try to setup the integration automatically. |
| 10 | + If something fails, you can still setup the integration manually. |
| 11 | + |
| 12 | + |
| 13 | +Provider-specific instructions |
| 14 | +------------------------------ |
| 15 | + |
| 16 | +.. tabs:: |
| 17 | + |
| 18 | + .. tab:: GitHub |
| 19 | + |
| 20 | + .. _webhook-integration-github: |
| 21 | + |
| 22 | + * Go to the :guilabel:`Settings` page for your **GitHub project** |
| 23 | + * Click :guilabel:`Webhooks` > :guilabel:`Add webhook` |
| 24 | + * For **Payload URL**, use the URL of the integration on your **Read the Docs project**, |
| 25 | + found on the project's :guilabel:`Admin` > :guilabel:`Integrations` page. |
| 26 | + You may need to prepend *https://* to the URL. |
| 27 | + * For **Content type**, both *application/json* and |
| 28 | + *application/x-www-form-urlencoded* work |
| 29 | + * Leave the **Secrets** field blank |
| 30 | + * Select **Let me select individual events**, |
| 31 | + and mark **Branch or tag creation**, **Branch or tag deletion**, **Pull requests** and **Pushes** events |
| 32 | + * Ensure **Active** is enabled; it is by default |
| 33 | + * Finish by clicking **Add webhook**. You may be prompted to enter your GitHub password to confirm your action. |
| 34 | + |
| 35 | + You can verify if the webhook is working at the bottom of the GitHub page under **Recent Deliveries**. |
| 36 | + If you see a Response 200, then the webhook is correctly configured. |
| 37 | + For a 403 error, it's likely that the Payload URL is incorrect. |
| 38 | + |
| 39 | + .. note:: The webhook token, intended for the GitHub **Secret** field, is not yet implemented. |
| 40 | + |
| 41 | + .. tab:: Bitbucket |
| 42 | + |
| 43 | + .. _webhook-integration-bitbucket: |
| 44 | + |
| 45 | + * Go to the :guilabel:`Settings` > :guilabel:`Webhooks` > :guilabel:`Add webhook` page for your project |
| 46 | + * For **URL**, use the URL of the integration on Read the Docs, |
| 47 | + found on the :guilabel:`Admin` > :guilabel:`Integrations` page |
| 48 | + * Under **Triggers**, **Repository push** should be selected |
| 49 | + * Finish by clicking **Save** |
| 50 | + |
| 51 | + .. tab:: GitLab |
| 52 | + |
| 53 | + .. _webhook-integration-gitlab: |
| 54 | + |
| 55 | + * Go to the :guilabel:`Settings` > :guilabel:`Webhooks` page for your GitLab project |
| 56 | + * For **URL**, use the URL of the integration on **Read the Docs project**, |
| 57 | + found on the :guilabel:`Admin` > :guilabel:`Integrations` page |
| 58 | + * Leave the default **Push events** selected, |
| 59 | + additionally mark **Tag push events** and **Merge request events**. |
| 60 | + * Finish by clicking **Add Webhook** |
| 61 | + |
| 62 | + .. tab:: Gitea |
| 63 | + |
| 64 | + These instructions apply to any Gitea instance. |
| 65 | + |
| 66 | + .. warning:: |
| 67 | + |
| 68 | + This isn't officially supported, but using the "GitHub webhook" is an effective workaround, |
| 69 | + because Gitea uses the same payload as GitHub. The generic webhook is not compatible with Gitea. |
| 70 | + See `issue #8364`_ for more details. Official support may be implemented in the future. |
| 71 | + |
| 72 | + On Read the Docs: |
| 73 | + |
| 74 | + * Manually create a "GitHub webhook" integration |
| 75 | + (this will show a warning about the webhook not being correctly set up, |
| 76 | + that will go away when the webhook is configured in Gitea) |
| 77 | + |
| 78 | + On your Gitea instance: |
| 79 | + |
| 80 | + * Go to the :guilabel:`Settings` > :guilabel:`Webhooks` page for your project on your Gitea instance |
| 81 | + * Create a new webhook of type "Gitea" |
| 82 | + * For **URL**, use the URL of the integration on Read the Docs, |
| 83 | + found on the :guilabel:`Admin` > :guilabel:`Integrations` page |
| 84 | + * Leave the default **HTTP Method** as POST |
| 85 | + * For **Content type**, both *application/json* and |
| 86 | + *application/x-www-form-urlencoded* work |
| 87 | + * Leave the **Secret** field blank |
| 88 | + * Select **Choose events**, |
| 89 | + and mark **Branch or tag creation**, **Branch or tag deletion** and **Push** events |
| 90 | + * Ensure **Active** is enabled; it is by default |
| 91 | + * Finish by clicking **Add Webhook** |
| 92 | + * Test the webhook with :guilabel:`Delivery test` |
| 93 | + |
| 94 | + Finally, on Read the Docs, check that the warnings have disappeared |
| 95 | + and the delivery test triggered a build. |
| 96 | + |
| 97 | + .. _issue #8364: https://github.com/readthedocs/readthedocs.org/issues/8364 |
| 98 | + |
| 99 | + |
| 100 | +Additional integration |
| 101 | +---------------------- |
| 102 | + |
| 103 | +You can configure multiple webhooks. |
| 104 | + |
| 105 | +To manually set up an integration, go to :guilabel:`Admin` > :guilabel:`Integrations` > :guilabel:`Add integration` |
| 106 | +dashboard page and select the integration type you'd like to add. |
| 107 | +After you have added the integration, you'll see a link to information about the integration. |
| 108 | + |
| 109 | +As an example, the URL pattern looks like this: ``https://readthedocs.org/api/v2/webhook/<project-name>/<id>/*``. |
| 110 | + |
| 111 | +Use this URL when setting up a new integration with your provider ^^ these steps vary depending on the provider. |
| 112 | + |
| 113 | + |
| 114 | +.. _webhook-integration-generic: |
| 115 | + |
| 116 | +Using the generic API integration |
| 117 | +--------------------------------- |
| 118 | + |
| 119 | +For repositories that are not hosted with a supported provider, we also offer a |
| 120 | +generic API endpoint for triggering project builds. Similar to webhook integrations, |
| 121 | +this integration has a specific URL, which can be found on the project's **Integrations** dashboard page |
| 122 | +(:guilabel:`Admin` > :guilabel:`Integrations`). |
| 123 | + |
| 124 | +Token authentication is required to use the generic endpoint, you will find this |
| 125 | +token on the integration details page. The token should be passed in as a |
| 126 | +request parameter, either as form data or as part of JSON data input. |
| 127 | + |
| 128 | +Parameters |
| 129 | +^^^^^^^^^^ |
| 130 | + |
| 131 | +This endpoint accepts the following arguments during an HTTP POST: |
| 132 | + |
| 133 | +branches |
| 134 | + The names of the branches to trigger builds for. This can either be an array |
| 135 | + of branch name strings, or just a single branch name string. |
| 136 | + |
| 137 | + Default: **latest** |
| 138 | + |
| 139 | +token |
| 140 | + The integration token found on the project's **Integrations** dashboard page |
| 141 | + (:guilabel:`Admin` > :guilabel:`Integrations`). |
| 142 | + |
| 143 | +For example, the cURL command to build the ``dev`` branch, using the token |
| 144 | +``1234``, would be:: |
| 145 | + |
| 146 | + curl -X POST -d "branches=dev" -d "token=1234" https://readthedocs.org/api/v2/webhook/example-project/1/ |
| 147 | + |
| 148 | +A command like the one above could be called from a cron job or from a hook |
| 149 | +inside Git_, Subversion_, Mercurial_, or Bazaar_. |
| 150 | + |
| 151 | +.. _Git: http://www.kernel.org/pub/software/scm/git/docs/githooks.html |
| 152 | +.. _Subversion: https://www.mikewest.org/2006/06/subversion-post-commit-hooks-101 |
| 153 | +.. _Mercurial: http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html |
| 154 | +.. _Bazaar: http://wiki.bazaar.canonical.com/BzrHooks |
| 155 | + |
| 156 | +Authentication |
| 157 | +^^^^^^^^^^^^^^ |
| 158 | + |
| 159 | +This endpoint requires authentication. If authenticating with an integration |
| 160 | +token, a check will determine if the token is valid and matches the given |
| 161 | +project. If instead an authenticated user is used to make this request, a check |
| 162 | +will be performed to ensure the authenticated user is an owner of the project. |
| 163 | + |
| 164 | +Payload validation |
| 165 | +------------------ |
| 166 | + |
| 167 | +If your project was imported through a connected account, |
| 168 | +we create a secret for every integration that offers a way to verify that a webhook request is legitimate. |
| 169 | +Currently, `GitHub <https://developer.github.com/webhooks/securing/>`__ and `GitLab <https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#validate-payloads-by-using-a-secret-token>`__ |
| 170 | +offer a way to check this. |
| 171 | + |
| 172 | +Troubleshooting |
| 173 | +--------------- |
| 174 | + |
| 175 | +Debugging webhooks |
| 176 | +^^^^^^^^^^^^^^^^^^ |
| 177 | + |
| 178 | +If you are experiencing problems with an existing webhook, you may be able to |
| 179 | +use the integration detail page to help debug the issue. Each project |
| 180 | +integration, such as a webhook or the generic API endpoint, stores the HTTP |
| 181 | +exchange that takes place between Read the Docs and the external source. You'll |
| 182 | +find a list of these exchanges in any of the integration detail pages. |
| 183 | + |
| 184 | + |
| 185 | +Webhook activation failed. Make sure you have the necessary permissions |
| 186 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 187 | + |
| 188 | +If you find this error, |
| 189 | +make sure your user has permissions over the repository. |
| 190 | +In case of GitHub, |
| 191 | +check that you have granted access to the Read the Docs `OAuth App`_ to your organization. |
| 192 | + |
| 193 | +.. _OAuth App: https://github.com/settings/applications |
| 194 | + |
| 195 | + |
| 196 | +My project isn't automatically building |
| 197 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 198 | + |
| 199 | +If your project isn't automatically building, you can check your integration on |
| 200 | +Read the Docs to see the payload sent to our servers. If there is no recent |
| 201 | +activity on your Read the Docs project webhook integration, then it's likely |
| 202 | +that your VCS provider is not configured correctly. If there is payload |
| 203 | +information on your Read the Docs project, you might need to verify that your |
| 204 | +versions are configured to build correctly. |
0 commit comments