From f239442a1b18b461f6b631b7a9a74b3d7bb52095 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Mon, 18 May 2020 11:46:01 -0700 Subject: [PATCH 1/7] Add a project-level configuration for PR builds This allows users with the feature flag to enable/disable this feature. --- .../autobuild-docs-for-pull-requests.rst | 7 +++++-- readthedocs/projects/forms.py | 5 +++++ .../0049_add_external_build_enabled.py | 18 ++++++++++++++++++ readthedocs/projects/models.py | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 readthedocs/projects/migrations/0049_add_external_build_enabled.py diff --git a/docs/guides/autobuild-docs-for-pull-requests.rst b/docs/guides/autobuild-docs-for-pull-requests.rst index 0fa7fd3c900..2d82200619c 100644 --- a/docs/guides/autobuild-docs-for-pull-requests.rst +++ b/docs/guides/autobuild-docs-for-pull-requests.rst @@ -2,8 +2,11 @@ Autobuild Documentation for Pull Requests ========================================= Read the Docs allows autobuilding documentation for pull/merge requests for GitHub or GitLab projects. -This feature is currently available under a :doc:`Feature Flag `. -So, you can enable this feature by sending us an `email `__ including your project URL. +This feature is currently enabled for a subset of our projects while being rolled out. +You can check to see if your project has it enabled by looking at the :guilabel:`Admin > Advanced settings` and look for :guilabel:`Build pull requests for this project`. +We are rolling this feature out based on the projects age on Read the Docs, +so older projects will get it first. +You can also ask for this feature by sending us an `email `__ including your project URL. Features -------- diff --git a/readthedocs/projects/forms.py b/readthedocs/projects/forms.py index 138a40c2450..fcc271ce8f4 100644 --- a/readthedocs/projects/forms.py +++ b/readthedocs/projects/forms.py @@ -203,6 +203,7 @@ class Meta: 'analytics_code', 'show_version_warning', 'single_version', + 'external_builds_enabled' ) # These that can be set per-version using a config file. per_version_settings = ( @@ -259,6 +260,10 @@ def __init__(self, *args, **kwargs): else: self.fields['default_version'].widget.attrs['readonly'] = True + # Enable PR builder option on projects w/ feature flag + if not self.instance.has_feature(Feature.EXTERNAL_VERSION_BUILD): + self.fields.pop('external_builds_enabled') + def clean_conf_py_file(self): filename = self.cleaned_data.get('conf_py_file', '').strip() if filename and 'conf.py' not in filename: diff --git a/readthedocs/projects/migrations/0049_add_external_build_enabled.py b/readthedocs/projects/migrations/0049_add_external_build_enabled.py new file mode 100644 index 00000000000..f9bb1f8e2e6 --- /dev/null +++ b/readthedocs/projects/migrations/0049_add_external_build_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-05-18 20:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0048_remove_version_privacy_field'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='external_builds_enabled', + field=models.BooleanField(default=False, help_text='More information in our docs', verbose_name='Build pull requests for this project'), + ), + ] diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index 0006ccdd914..4c28af40209 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -202,6 +202,12 @@ class Project(models.Model): ), ) + external_builds_enabled = models.BooleanField( + _('Build pull requests for this project'), + default=False, + help_text=_('More information in our docs') # noqa + ) + # Project features cdn_enabled = models.BooleanField(_('CDN Enabled'), default=False) analytics_code = models.CharField( From 04605857d9bd1ee5671ed148c779aa2abf76676c Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Tue, 19 May 2020 06:29:24 -0700 Subject: [PATCH 2/7] Migrate existing PR builder projects and enable it --- readthedocs/api/v2/views/integrations.py | 2 ++ .../0050_migrate_external_builds.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 readthedocs/projects/migrations/0050_migrate_external_builds.py diff --git a/readthedocs/api/v2/views/integrations.py b/readthedocs/api/v2/views/integrations.py index d4438e990ce..e08a01c2125 100644 --- a/readthedocs/api/v2/views/integrations.py +++ b/readthedocs/api/v2/views/integrations.py @@ -412,6 +412,7 @@ def handle_webhook(self): # Handle pull request events if all([ self.project.has_feature(Feature.EXTERNAL_VERSION_BUILD), + self.project.external_builds_enabled, event == GITHUB_PULL_REQUEST, action, ]): @@ -568,6 +569,7 @@ def handle_webhook(self): if ( self.project.has_feature(Feature.EXTERNAL_VERSION_BUILD) and + self.project.external_builds_enabled and event == GITLAB_MERGE_REQUEST and action ): if ( diff --git a/readthedocs/projects/migrations/0050_migrate_external_builds.py b/readthedocs/projects/migrations/0050_migrate_external_builds.py new file mode 100644 index 00000000000..c792aca5011 --- /dev/null +++ b/readthedocs/projects/migrations/0050_migrate_external_builds.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.10 on 2020-05-19 13:24 + +from django.db import migrations + + +def migrate_features(apps, schema_editor): + # Enable the PR builder for projects with the feature flag + Feature = apps.get_model('projects', 'Feature') + for project in Feature.objects.get(feature_id='external_version_build').projects.all(): + project.external_builds_enabled = True + project.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0049_add_external_build_enabled'), + ] + + operations = [ + migrations.RunPython(migrate_features), + ] From 6c42f64271c87c0c2d3a37d6e44d7c4b3040dc87 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Thu, 21 May 2020 15:17:44 -0700 Subject: [PATCH 3/7] Make external_build field nullable --- readthedocs/projects/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index 4c28af40209..55a4790152b 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -205,6 +205,8 @@ class Project(models.Model): external_builds_enabled = models.BooleanField( _('Build pull requests for this project'), default=False, + # TODO: Remove this after migrations + null=True, help_text=_('More information in our docs') # noqa ) From 8c13dc1e4e61a0229793ef6f76f05b1d7bd50b51 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Thu, 21 May 2020 15:19:14 -0700 Subject: [PATCH 4/7] Update nullable migration --- .../projects/migrations/0049_add_external_build_enabled.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readthedocs/projects/migrations/0049_add_external_build_enabled.py b/readthedocs/projects/migrations/0049_add_external_build_enabled.py index f9bb1f8e2e6..04c7f6dcb28 100644 --- a/readthedocs/projects/migrations/0049_add_external_build_enabled.py +++ b/readthedocs/projects/migrations/0049_add_external_build_enabled.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.10 on 2020-05-18 20:17 +# Generated by Django 2.2.10 on 2020-05-21 22:18 from django.db import migrations, models @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='project', name='external_builds_enabled', - field=models.BooleanField(default=False, help_text='More information in our docs', verbose_name='Build pull requests for this project'), + field=models.BooleanField(default=False, help_text='More information in our docs', null=True, verbose_name='Build pull requests for this project'), ), ] From 4e1d1f54d670ddf4371d1556908eed6b8ea88ba2 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 22 May 2020 08:11:14 -0700 Subject: [PATCH 5/7] Fix migration --- .../projects/migrations/0050_migrate_external_builds.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/readthedocs/projects/migrations/0050_migrate_external_builds.py b/readthedocs/projects/migrations/0050_migrate_external_builds.py index c792aca5011..21a45cd7400 100644 --- a/readthedocs/projects/migrations/0050_migrate_external_builds.py +++ b/readthedocs/projects/migrations/0050_migrate_external_builds.py @@ -6,9 +6,10 @@ def migrate_features(apps, schema_editor): # Enable the PR builder for projects with the feature flag Feature = apps.get_model('projects', 'Feature') - for project in Feature.objects.get(feature_id='external_version_build').projects.all(): - project.external_builds_enabled = True - project.save() + if Feature.objects.filter(feature_id='external_version_build').exists(): + for project in Feature.objects.get(feature_id='external_version_build').projects.all(): + project.external_builds_enabled = True + project.save() class Migration(migrations.Migration): From a274a05caf28301966842b797ca80d424652997c Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 22 May 2020 08:11:25 -0700 Subject: [PATCH 6/7] Upgrade pytest & pytest-django --- requirements/testing.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/testing.txt b/requirements/testing.txt index 97adde92c7c..2c93585dfa5 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -2,9 +2,9 @@ -r local-docs-build.txt django-dynamic-fixture==3.1.0 -pytest==5.2.2 +pytest==5.4.2 pytest-custom-exit-code==0.3.0 -pytest-django==3.6.0 +pytest-django==3.8.0 pytest-xdist==1.30.0 pytest-cov==2.8.1 apipkg==1.5 From 43c0bac0b5ef6734a20af3e8f7cec55bce9f28f4 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 22 May 2020 09:35:58 -0700 Subject: [PATCH 7/7] Set external_builds_enabled on project in tests --- readthedocs/rtd_tests/tests/test_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/readthedocs/rtd_tests/tests/test_api.py b/readthedocs/rtd_tests/tests/test_api.py index cb3106572ab..93a987acc8b 100644 --- a/readthedocs/rtd_tests/tests/test_api.py +++ b/readthedocs/rtd_tests/tests/test_api.py @@ -790,6 +790,7 @@ def setUp(self): self.project = get( Project, build_queue=None, + external_builds_enabled=True, ) self.feature_flag = get( Feature,