Skip to content

Git backend: make default_branch to point to VCS' default branch #9424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/user/integrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ token
The integration token found on the project's **Integrations** dashboard page
(:guilabel:`Admin` > :guilabel:`Integrations`).

default_branch
This is the default branch of the repository
(ie. the one checked out when cloning the repository without arguments)

For example, the cURL command to build the ``dev`` branch, using the token
``1234``, would be::

curl -X POST -d "branches=dev" -d "token=1234" https://readthedocs.org/api/v2/webhook/example-project/1/
curl -X POST -d "branches=dev" -d "token=1234" -d "default_branch=main"
https://readthedocs.org/api/v2/webhook/example-project/1/

A command like the one above could be called from a cron job or from a hook
inside Git_, Subversion_, Mercurial_, or Bazaar_.
Expand Down
8 changes: 7 additions & 1 deletion readthedocs/api/v2/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ class APIWebhookView(WebhookMixin, APIView):
Expects the following JSON::

{
"branches": ["master"]
"branches": ["master"],
"default_branch": "main"
}
"""

Expand Down Expand Up @@ -800,8 +801,13 @@ def handle_webhook(self):
'branches',
[self.project.get_default_branch()],
)
default_branch = self.request.data.get("default_branch", None)
if isinstance(branches, str):
branches = [branches]

if default_branch and isinstance(default_branch, str):
self.update_default_branch(default_branch)

return self.get_response_push(self.project, branches)
except TypeError:
raise ParseError('Invalid request')
Expand Down
1 change: 0 additions & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
)
self.versions.filter(slug=LATEST).update(identifier=self.default_branch)


def delete(self, *args, **kwargs): # pylint: disable=arguments-differ
from readthedocs.projects.tasks.utils import clean_project_resources

Expand Down
89 changes: 47 additions & 42 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ def setUp(self):
Project,
build_queue=None,
external_builds_enabled=True,
default_branch="master",
)
self.version = get(
Version, slug='master', verbose_name='master',
Expand Down Expand Up @@ -2346,8 +2347,12 @@ def test_webhook_build_latest_and_master(self, trigger_build):
self.project.slug,
integration.pk,
),
{'token': integration.token, 'branches': default_branch.slug},
format='json',
{
"token": integration.token,
"branches": default_branch.slug,
"default_branch": "master",
},
format="json",
)
self.assertEqual(resp.status_code, 200)
self.assertTrue(resp.data['build_triggered'])
Expand Down Expand Up @@ -2402,46 +2407,46 @@ def test_get_version_by_id(self):
self.assertEqual(resp.status_code, 200)

version_data = {
'type': 'tag',
'verbose_name': '0.8',
'built': False,
'id': 18,
'active': True,
'project': {
'analytics_code': None,
'analytics_disabled': False,
'canonical_url': 'http://readthedocs.org/docs/pip/en/latest/',
'cdn_enabled': False,
'conf_py_file': '',
'container_image': None,
'container_mem_limit': None,
'container_time_limit': None,
'default_branch': None,
'default_version': 'latest',
'description': '',
'documentation_type': 'sphinx',
'environment_variables': {},
'enable_epub_build': True,
'enable_pdf_build': True,
'features': ['allow_deprecated_webhooks'],
'has_valid_clone': False,
'has_valid_webhook': False,
'id': 6,
'install_project': False,
'language': 'en',
'max_concurrent_builds': None,
'name': 'Pip',
'programming_language': 'words',
'python_interpreter': 'python3',
'repo': 'https://github.com/pypa/pip',
'repo_type': 'git',
'requirements_file': None,
'show_advertising': True,
'skip': False,
'slug': 'pip',
'use_system_packages': False,
'users': [1],
'urlconf': None,
"type": "tag",
"verbose_name": "0.8",
"built": False,
"id": 18,
"active": True,
"project": {
"analytics_code": None,
"analytics_disabled": False,
"canonical_url": "http://readthedocs.org/docs/pip/en/latest/",
"cdn_enabled": False,
"conf_py_file": "",
"container_image": None,
"container_mem_limit": None,
"container_time_limit": None,
"default_branch": None,
"default_version": "latest",
"description": "",
"documentation_type": "sphinx",
"environment_variables": {},
"enable_epub_build": True,
"enable_pdf_build": True,
"features": [],
"has_valid_clone": False,
"has_valid_webhook": False,
"id": 6,
"install_project": False,
"language": "en",
"max_concurrent_builds": None,
"name": "Pip",
"programming_language": "words",
"python_interpreter": "python3",
"repo": "https://github.com/pypa/pip",
"repo_type": "git",
"requirements_file": None,
"show_advertising": True,
"skip": False,
"slug": "pip",
"use_system_packages": False,
"users": [1],
"urlconf": None,
},
'privacy_level': 'public',
'downloads': {},
Expand Down