Skip to content

Add a project-level configuration for PR builds #7090

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 8 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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: 5 additions & 2 deletions docs/guides/autobuild-docs-for-pull-requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 </guides/feature-flags>`.
So, you can enable this feature by sending us an `email <mailto:[email protected]>`__ 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We are rolling this feature out based on the projects age on Read the Docs,
We are rolling this feature out based on the projects' age on Read the Docs,

I always confuse this, so maybe I'm wrong here :)

so older projects will get it first.
You can also ask for this feature by sending us an `email <mailto:[email protected]>`__ including your project URL.

Features
--------
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/api/v2/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]):
Expand Down Expand Up @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions readthedocs/projects/migrations/0049_add_external_build_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-05-21 22:18

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 <a href="https://docs.readthedocs.io/en/latest/guides/autobuild-docs-for-pull-requests.html">our docs</a>', null=True, verbose_name='Build pull requests for this project'),
),
]
22 changes: 22 additions & 0 deletions readthedocs/projects/migrations/0050_migrate_external_builds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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')
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):

dependencies = [
('projects', '0049_add_external_build_enabled'),
]

operations = [
migrations.RunPython(migrate_features),
]
8 changes: 8 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ class Project(models.Model):
),
)

external_builds_enabled = models.BooleanField(
_('Build pull requests for this project'),
default=False,
# TODO: Remove this after migrations
null=True,
Comment on lines +208 to +209
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed when using a default= value. I'd remove it in this PR instead of forcing us to create a new one later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only works on the new code though, when we run the migration and the old code is still running, it will blow up the DB.

help_text=_('More information in <a href="https://docs.readthedocs.io/en/latest/guides/autobuild-docs-for-pull-requests.html">our docs</a>') # noqa
)

# Project features
cdn_enabled = models.BooleanField(_('CDN Enabled'), default=False)
analytics_code = models.CharField(
Expand Down
4 changes: 2 additions & 2 deletions requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I upgraded these because then it gave me proper failures on the migrations instead of blowing up :)

pytest-xdist==1.30.0
pytest-cov==2.8.1
apipkg==1.5
Expand Down