Skip to content
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

Merge initial work from Pull Request Builder GSOC #5823

Merged
merged 201 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
31b9bf2
Version Type Added
saadmk11 May 30, 2019
bd11994
Version Model Methods Updated
saadmk11 May 30, 2019
8f3e64b
Internal and External Version Manager added
saadmk11 Jun 4, 2019
66200a0
lint fix
saadmk11 Jun 4, 2019
34e4134
All Version Querysets Updated with InternalVersionManager
saadmk11 Jun 4, 2019
3a3cfdf
Manager names moved to Constants
saadmk11 Jun 5, 2019
3d3de29
Tests added
saadmk11 Jun 6, 2019
b55983f
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 Jun 6, 2019
6187272
Updated migrations
saadmk11 Jun 6, 2019
386ca07
footer API updated
saadmk11 Jun 8, 2019
29348ef
manager tests updated
saadmk11 Jun 11, 2019
11a0583
_override_setting removed from new managers
saadmk11 Jun 13, 2019
c100c81
BuildTriggerMixin updated
saadmk11 Jun 13, 2019
c1c03bb
More Update
saadmk11 Jun 13, 2019
5ea5f67
lint fix
saadmk11 Jun 13, 2019
73a46a5
Merge branch 'master' into version-update
saadmk11 Jun 13, 2019
56493fa
removed unused import
saadmk11 Jun 14, 2019
d8cff7e
Merge branch 'master' into version-update
saadmk11 Jun 17, 2019
84a6975
External version name added everywhere
saadmk11 Jun 17, 2019
05951cf
Migration name changed
saadmk11 Jun 17, 2019
e192300
Sitemap sort order priorities updated
saadmk11 May 23, 2019
d5ec837
ordering fix
saadmk11 May 25, 2019
1f13be1
doc string fix
saadmk11 May 25, 2019
e0232b3
sort_by_priority function added to sitemap
saadmk11 May 29, 2019
fdcfcf6
lint fix
saadmk11 May 29, 2019
ef13214
Sorting by swapping positions
saadmk11 Jun 11, 2019
736a337
index out of range issue fix
saadmk11 Jun 12, 2019
c18f381
Use a real SessionBase object on FooterNoSessionMiddleware
humitos Jun 12, 2019
908860a
Version Type Added
saadmk11 May 30, 2019
f81bcf0
Version Model Methods Updated
saadmk11 May 30, 2019
66377c2
Internal and External Version Manager added
saadmk11 Jun 4, 2019
8bdf75c
lint fix
saadmk11 Jun 4, 2019
21f96de
All Version Querysets Updated with InternalVersionManager
saadmk11 Jun 4, 2019
014477d
Manager names moved to Constants
saadmk11 Jun 5, 2019
d3f5254
Tests added
saadmk11 Jun 6, 2019
6bca1e4
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 Jun 6, 2019
8830a18
Updated migrations
saadmk11 Jun 6, 2019
5ed38c4
footer API updated
saadmk11 Jun 8, 2019
2d8b072
manager tests updated
saadmk11 Jun 11, 2019
89f3c8a
_override_setting removed from new managers
saadmk11 Jun 13, 2019
7b63973
BuildTriggerMixin updated
saadmk11 Jun 13, 2019
3a2fc6d
More Update
saadmk11 Jun 13, 2019
bca152a
lint fix
saadmk11 Jun 13, 2019
5f90052
Move search functions
stsewd Jun 13, 2019
120eb5d
removed unused import
saadmk11 Jun 14, 2019
ef3d061
External version name added everywhere
saadmk11 Jun 17, 2019
5b33bbd
Migration name changed
saadmk11 Jun 17, 2019
5180743
Build Managers added
saadmk11 Jun 8, 2019
8301679
Managers used in all the places
saadmk11 Jun 13, 2019
7b75ee8
build manager tests added
saadmk11 Jun 13, 2019
8c7b02b
More Tests added
saadmk11 Jun 13, 2019
5d6c750
External version name added
saadmk11 Jun 17, 2019
c5d1c09
Merge branch 'gsoc-19-pr-builder' into build-manager-update
saadmk11 Jun 17, 2019
5329036
Sitemap sort order priorities updated
saadmk11 May 23, 2019
d64e2d0
ordering fix
saadmk11 May 25, 2019
51ad395
doc string fix
saadmk11 May 25, 2019
884857b
sort_by_priority function added to sitemap
saadmk11 May 29, 2019
43b24d7
lint fix
saadmk11 May 29, 2019
3e278a2
Sorting by swapping positions
saadmk11 Jun 11, 2019
7d3f934
index out of range issue fix
saadmk11 Jun 12, 2019
4194a42
Use a real SessionBase object on FooterNoSessionMiddleware
humitos Jun 12, 2019
5572dee
Version Type Added
saadmk11 May 30, 2019
7f90a88
Version Model Methods Updated
saadmk11 May 30, 2019
19e7fa1
Internal and External Version Manager added
saadmk11 Jun 4, 2019
bd256fd
lint fix
saadmk11 Jun 4, 2019
fef7191
All Version Querysets Updated with InternalVersionManager
saadmk11 Jun 4, 2019
0dd9eb2
Manager names moved to Constants
saadmk11 Jun 5, 2019
f267881
Tests added
saadmk11 Jun 6, 2019
cc1297f
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 Jun 6, 2019
20ca139
Updated migrations
saadmk11 Jun 6, 2019
cb17a79
footer API updated
saadmk11 Jun 8, 2019
f687302
manager tests updated
saadmk11 Jun 11, 2019
bf9bd5e
_override_setting removed from new managers
saadmk11 Jun 13, 2019
12cd686
BuildTriggerMixin updated
saadmk11 Jun 13, 2019
d7330c1
More Update
saadmk11 Jun 13, 2019
eed1a9c
lint fix
saadmk11 Jun 13, 2019
f3f86dc
Move search functions
stsewd Jun 13, 2019
3d62248
removed unused import
saadmk11 Jun 14, 2019
09a09a2
External version name added everywhere
saadmk11 Jun 17, 2019
119a3ae
Migration name changed
saadmk11 Jun 17, 2019
df4705a
Removed PR Versions from Elasticsearch Indexing
saadmk11 Jun 14, 2019
9140a57
HTMLFile manager added
saadmk11 Jun 14, 2019
f902d65
typo fix
saadmk11 Jun 14, 2019
afd5e47
lint fix
saadmk11 Jun 17, 2019
f03db54
External naming updated
saadmk11 Jun 18, 2019
1173718
Merge branch 'master' into version-update
saadmk11 Jun 18, 2019
5a05b6c
naming update
saadmk11 Jun 18, 2019
7607268
Merge branch 'gsoc-19-pr-builder' into build-manager-update
saadmk11 Jun 18, 2019
560cfef
Merge branch 'gsoc-19-pr-builder' into remove-pr-from-es
saadmk11 Jun 18, 2019
75efef8
naming updated
saadmk11 Jun 18, 2019
3c13c38
naming update for External
saadmk11 Jun 18, 2019
51188e7
fix
saadmk11 Jun 18, 2019
3bdf03c
fix
saadmk11 Jun 18, 2019
9b99538
vcs_url() update
saadmk11 Jun 18, 2019
cfd085c
tests updated
saadmk11 Jun 18, 2019
0beaad6
Merge pull request #5779 from saadmk11/build-manager-update
ericholscher Jun 18, 2019
13c5330
Merge branch 'gsoc-19-pr-builder' into remove-pr-from-es
saadmk11 Jun 19, 2019
6fd5f68
lint fix
saadmk11 Jun 19, 2019
be8f4de
Sync External versions to our database
ericholscher Jun 18, 2019
30ac6ba
Remove unused patterns
ericholscher Jun 18, 2019
df122da
Small whitespace cleanup
ericholscher Jun 18, 2019
da4f71d
Clean up fetch logic a bit
ericholscher Jun 18, 2019
1207afb
Add Comment
ericholscher Jun 18, 2019
c74d294
Initial changes for PR Builder
saadmk11 Jun 19, 2019
e7c7417
removed _default_class for BuildManager
saadmk11 Jun 20, 2019
5fb2e4e
Only build external version from webhook payload
saadmk11 Jun 21, 2019
a859eac
fix
saadmk11 Jun 21, 2019
5b883df
need to pass verbose_name as a list for get_response_push
saadmk11 Jun 21, 2019
12f6658
Merge pull request #5828 from saadmk11/pr-builder
ericholscher Jun 21, 2019
7bcb3e1
Merge pull request #5805 from saadmk11/remove-pr-from-es
ericholscher Jun 21, 2019
a166563
Merge branch 'master' of github.com:rtfd/readthedocs.org into gsoc-19…
ericholscher Jun 21, 2019
31041a3
add all versions and builds to version and build listing
saadmk11 Jun 21, 2019
9cf8ec3
fix tests
saadmk11 Jun 21, 2019
711ed9a
fix tests
saadmk11 Jun 21, 2019
65697cb
refine webhook handling
saadmk11 Jun 22, 2019
7fa5a01
lint fix
saadmk11 Jun 22, 2019
5718ea7
Doc string updated
saadmk11 Jun 22, 2019
5663dc3
Doc string updated
saadmk11 Jun 22, 2019
e5d9725
Updated Action
saadmk11 Jun 24, 2019
7c6abc7
Merge pull request #5837 from saadmk11/remove-internal-filtering
ericholscher Jun 24, 2019
3427564
Pull Request Closed webhook handled
saadmk11 Jun 25, 2019
2f739f0
More refining
saadmk11 Jun 26, 2019
9fbb839
tests added
saadmk11 Jun 27, 2019
cdd38a1
vcs_repo updated
saadmk11 Jun 27, 2019
7ef5175
vcs_repo more update
saadmk11 Jun 27, 2019
30390fe
updated event handling
saadmk11 Jun 27, 2019
694a27b
vcs_repo method updated
saadmk11 Jun 27, 2019
d721fc0
fix
saadmk11 Jun 27, 2019
1692dfb
use named args
saadmk11 Jun 27, 2019
7b2bc6c
Docstring added and some changes added
saadmk11 Jun 27, 2019
d38e44a
Merge pull request #5838 from saadmk11/refine-pr-building
ericholscher Jun 27, 2019
70be132
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 Jul 4, 2019
6400305
migrations updated
saadmk11 Jul 4, 2019
04d4dca
fix typo
saadmk11 Jul 4, 2019
40fb6ee
Send Build Status using Github Status API
saadmk11 Jun 28, 2019
c561486
docstring update
saadmk11 Jun 28, 2019
3cf07f2
Updated Constants and notification sending
saadmk11 Jun 29, 2019
d9a867b
cleanup
saadmk11 Jun 29, 2019
ef6707b
task update
saadmk11 Jul 2, 2019
66526be
send_build_status updated
saadmk11 Jul 2, 2019
8f2505a
updated get full url
saadmk11 Jul 2, 2019
ac67805
changed to PRODUCTION_DOMAIN
saadmk11 Jul 2, 2019
95264e0
tasks updated
saadmk11 Jul 2, 2019
1c0dda5
some tests added
saadmk11 Jul 3, 2019
9b10ea6
send_build_status tests added
saadmk11 Jul 4, 2019
e8098fb
tests for tasks added
saadmk11 Jul 4, 2019
e7a1641
try catch added to task
saadmk11 Jul 4, 2019
917b2e5
exception log updated
saadmk11 Jul 4, 2019
3f500e3
storage updated for external versions
saadmk11 Jul 6, 2019
f9634b6
update send_build_status process
saadmk11 Jul 9, 2019
ec1c6a4
removed gitlab build status constants
saadmk11 Jul 9, 2019
edab9b3
lint fix
saadmk11 Jul 9, 2019
1d4e0db
version type passed to function
saadmk11 Jul 9, 2019
7629360
only build html for external versions
saadmk11 Jul 9, 2019
b436ed1
doc string update
saadmk11 Jul 10, 2019
1117caa
remove log test
saadmk11 Jul 10, 2019
21bc227
add check for external version in conf.py.tmpl
saadmk11 Jul 10, 2019
d7b1d0c
remove external versions from get_latest_build
saadmk11 Jul 10, 2019
c4f06dc
Merge pull request #5865 from saadmk11/github-status-api
ericholscher Jul 10, 2019
9f492da
Merge branch 'gsoc-19-pr-builder' into update-storage
ericholscher Jul 10, 2019
92215ce
Merge pull request #5886 from saadmk11/update-storage
ericholscher Jul 10, 2019
f2719b5
Merge pull request #5901 from saadmk11/get-latest-build-update
ericholscher Jul 10, 2019
9bc0e33
Pass the build_pk to the task instead of the build object itself
ericholscher Jul 10, 2019
23a215e
added Feature flag to enable External version building
saadmk11 Jul 11, 2019
219e0df
lint fix
saadmk11 Jul 11, 2019
64174f4
Apply suggestions from code review
ericholscher Jul 11, 2019
9b23646
Merge pull request #5904 from readthedocs/pass-version-github-notific…
ericholscher Jul 11, 2019
b4a39aa
update conditions
saadmk11 Jul 11, 2019
5466b14
tests fixed
saadmk11 Jul 11, 2019
a6f4dd1
Merge pull request #5914 from saadmk11/test-fix
ericholscher Jul 11, 2019
b577d63
Merge pull request #5910 from saadmk11/feature-flag
ericholscher Jul 11, 2019
f03d076
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 Jul 11, 2019
1167c40
Update build list and detail page
saadmk11 Jul 11, 2019
d5af035
added commit url
saadmk11 Jul 11, 2019
1dd6bf2
Added commit url for build details page
saadmk11 Jul 12, 2019
2166770
Added tests
saadmk11 Jul 12, 2019
9af5521
setting commit url updated
saadmk11 Jul 12, 2019
8310e58
lint fix
saadmk11 Jul 12, 2019
ddf5259
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 Jul 12, 2019
9f593f2
Merge pull request #5916 from saadmk11/fix-build-ux
ericholscher Jul 15, 2019
763b857
commit url return updated
saadmk11 Jul 16, 2019
2537fc3
small updates according to suggestions
saadmk11 Jul 16, 2019
9e643dc
Send failure status when build state in unknown
saadmk11 Jul 16, 2019
999070b
Test Fix
saadmk11 Jul 16, 2019
4f1709e
build details page UI fix
saadmk11 Jul 16, 2019
ce1353e
Added get_or_create for external version creation
saadmk11 Jul 16, 2019
f84ee69
create external version updated
saadmk11 Jul 16, 2019
b1fe82f
comments updated
saadmk11 Jul 16, 2019
8ed0345
log message updated
saadmk11 Jul 16, 2019
290bab8
log mistake fix
saadmk11 Jul 16, 2019
bf8247f
test fix
saadmk11 Jul 16, 2019
ea09b41
Merge pull request #5933 from saadmk11/refine-pr-builder
ericholscher Jul 16, 2019
249e393
update build status message
saadmk11 Jul 17, 2019
008051a
small updates
saadmk11 Jul 17, 2019
b3128ae
external version feature flag fix
saadmk11 Jul 17, 2019
7861b0e
Merge pull request #5948 from saadmk11/pr-builder-update
ericholscher Jul 17, 2019
9c5a756
Merge pull request #5900 from saadmk11/external-version-warning
ericholscher Jul 17, 2019
a25be20
Merge branch 'gsoc-19-pr-builder' into update-status-msg
saadmk11 Jul 18, 2019
49e3fe4
update status msg
saadmk11 Jul 18, 2019
0b454bb
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 Jul 19, 2019
d89d519
Merge pull request #5947 from saadmk11/update-status-msg
ericholscher Jul 19, 2019
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
4 changes: 2 additions & 2 deletions readthedocs/api/v2/views/footer_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework_jsonp.renderers import JSONPRenderer

from readthedocs.api.v2.signals import footer_response
from readthedocs.builds.constants import LATEST, TAG
from readthedocs.builds.constants import LATEST, TAG, INTERNAL
from readthedocs.builds.models import Version
from readthedocs.projects.models import Project
from readthedocs.projects.version_handling import (
Expand All @@ -25,7 +25,7 @@ def get_version_compare_data(project, base_version=None):
:param base_version: We assert whether or not the base_version is also the
highest version in the resulting "is_highest" value.
"""
versions_qs = Version.objects.public(project=project)
versions_qs = Version.internal.public(project=project)
ericholscher marked this conversation as resolved.
Show resolved Hide resolved

# Take preferences over tags only if the project has at least one tag
if versions_qs.filter(type=TAG).exists():
Expand Down
35 changes: 34 additions & 1 deletion readthedocs/api/v2/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
webhook_github,
webhook_gitlab,
)
from readthedocs.core.views.hooks import build_branches, sync_versions
from readthedocs.core.views.hooks import (
build_branches,
sync_versions,
get_or_create_external_version,
)
from readthedocs.integrations.models import HttpExchange, Integration
from readthedocs.projects.models import Project

Expand All @@ -29,6 +33,9 @@
GITHUB_EVENT_HEADER = 'HTTP_X_GITHUB_EVENT'
GITHUB_SIGNATURE_HEADER = 'HTTP_X_HUB_SIGNATURE'
GITHUB_PUSH = 'push'
GITHUB_PULL_REQUEST = 'pull_request'
GITHUB_PULL_REQUEST_OPEN = 'opened'
GITHUB_PULL_REQUEST_SYNC = 'synchronize'
GITHUB_CREATE = 'create'
GITHUB_DELETE = 'delete'
GITLAB_TOKEN_HEADER = 'HTTP_X_GITLAB_TOKEN'
Expand Down Expand Up @@ -110,6 +117,10 @@ def handle_webhook(self):
"""Handle webhook payload."""
raise NotImplementedError

def get_external_version_data(self):
"""Get External Version data from payload."""
raise NotImplementedError

def is_payload_valid(self):
"""Validates the webhook's payload using the integration's secret."""
return False
Expand Down Expand Up @@ -218,6 +229,13 @@ def get_data(self):
pass
return super().get_data()

def get_external_version_data(self):
"""Get Commit Sha and pull request number from payload"""
identifier = self.data['pull_request']['head']['sha']
verbose_name = str(self.data['number'])

return identifier, verbose_name

def is_payload_valid(self):
"""
GitHub use a HMAC hexdigest hash to sign the payload.
Expand Down Expand Up @@ -271,6 +289,21 @@ def handle_webhook(self):
raise ParseError('Parameter "ref" is required')
if event in (GITHUB_CREATE, GITHUB_DELETE):
return self.sync_versions(self.project)

if (
event == GITHUB_PULL_REQUEST and
self.data['action'] in [GITHUB_PULL_REQUEST_OPEN, GITHUB_PULL_REQUEST_SYNC]
):
try:
identifier, verbose_name = self.get_external_version_data()
external_version = get_or_create_external_version(
self.project, identifier, verbose_name
)
return self.get_response_push(self.project, [external_version.verbose_name])

except KeyError:
raise ParseError('Parameters "sha" and "number" are required')

return None

def _normalize_ref(self, ref):
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/api/v2/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_framework.renderers import BaseRenderer, JSONRenderer
from rest_framework.response import Response

from readthedocs.builds.constants import BRANCH, TAG
from readthedocs.builds.constants import BRANCH, TAG, INTERNAL
from readthedocs.builds.models import Build, BuildCommandResult, Version
from readthedocs.core.utils import trigger_build
from readthedocs.core.utils.extend import SettingsOverrideObject
Expand Down Expand Up @@ -130,7 +130,7 @@ def active_versions(self, request, **kwargs):
Project.objects.api(request.user),
pk=kwargs['pk'],
)
versions = project.versions.filter(active=True)
versions = project.versions(manager=INTERNAL).filter(active=True)
return Response({
'versions': VersionSerializer(versions, many=True).data,
})
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/api/v3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class VersionsViewSet(APIv3Settings, NestedViewSetMixin, ProjectQuerySetMixin,
lookup_value_regex = r'[^/]+'

filterset_class = VersionFilter
queryset = Version.objects.all()
queryset = Version.internal.all()
permit_list_expands = [
'last_build',
'last_build.config',
Expand Down Expand Up @@ -269,7 +269,7 @@ class BuildsViewSet(APIv3Settings, NestedViewSetMixin, ProjectQuerySetMixin,
lookup_url_kwarg = 'build_pk'
serializer_class = BuildSerializer
filterset_class = BuildFilter
queryset = Build.objects.all()
queryset = Build.internal.all()
permit_list_expands = [
'config',
]
Expand Down
8 changes: 8 additions & 0 deletions readthedocs/builds/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@
('dash', _('Dash')),
)

# Manager name for Internal Versions or Builds.
# ie: Versions and Builds Excluding pull request/merge request Versions and Builds.
INTERNAL = 'internal'
# Manager name for External Versions or Builds.
# ie: Only pull request/merge request Versions and Builds.
EXTERNAL = 'external'

BRANCH = 'branch'
TAG = 'tag'
UNKNOWN = 'unknown'

VERSION_TYPES = (
(BRANCH, _('Branch')),
(TAG, _('Tag')),
(EXTERNAL, _('External')),
(UNKNOWN, _('Unknown')),
)

Expand Down
93 changes: 92 additions & 1 deletion readthedocs/builds/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
STABLE,
STABLE_VERBOSE_NAME,
TAG,
EXTERNAL,
)
from .querysets import VersionQuerySet
from .querysets import VersionQuerySet, BuildQuerySet

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,6 +86,96 @@ def get_object_or_log(self, **kwargs):
log.warning('Version not found for given kwargs. %s' % kwargs)


class InternalVersionManagerBase(VersionManagerBase):
Copy link
Member

Choose a reason for hiding this comment

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

It seems that InternalVersionManagerBase, ExternalVersionManagerBase and its Build versions can be just 2 classes instead of 4. They are exactly the same.


"""
Version manager that only includes internal version.

It will exclude pull request/merge request versions from the queries
and only include BRANCH, TAG, UNKONWN type Versions.
"""

def get_queryset(self):
return super().get_queryset().exclude(type=EXTERNAL)


class ExternalVersionManagerBase(VersionManagerBase):

"""
Version manager that only includes external version.

It will only include pull request/merge request Versions in the queries.
"""

def get_queryset(self):
return super().get_queryset().filter(type=EXTERNAL)


class VersionManager(SettingsOverrideObject):
_default_class = VersionManagerBase
_override_setting = 'VERSION_MANAGER'


class InternalVersionManager(SettingsOverrideObject):
_default_class = InternalVersionManagerBase


class ExternalVersionManager(SettingsOverrideObject):
_default_class = ExternalVersionManagerBase


class BuildManagerBase(models.Manager):
Copy link
Member

Choose a reason for hiding this comment

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

This class can be merged with VersionManagerBase with an attribute queryset_class to use in from_queryset method.


"""
Build manager for manager only queries.

For creating different Managers.
"""

@classmethod
def from_queryset(cls, queryset_class, class_name=None):
# This is overridden because :py:meth:`models.Manager.from_queryset`
# uses `inspect` to retrieve the class methods, and the proxy class has
# no direct members.
queryset_class = get_override_class(
BuildQuerySet,
BuildQuerySet._default_class, # pylint: disable=protected-access
)
return super().from_queryset(queryset_class, class_name)


class InternalBuildManagerBase(BuildManagerBase):

"""
Build manager that only includes internal version builds.

It will exclude pull request/merge request version builds from the queries
and only include BRANCH, TAG, UNKONWN type Version builds.
"""

def get_queryset(self):
return super().get_queryset().exclude(version__type=EXTERNAL)


class ExternalBuildManagerBase(BuildManagerBase):

"""
Build manager that only includes external version builds.

It will only include pull request/merge request version builds in the queries.
"""

def get_queryset(self):
return super().get_queryset().filter(version__type=EXTERNAL)


class BuildManager(SettingsOverrideObject):
_default_class = BuildManagerBase


class InternalBuildManager(SettingsOverrideObject):
_default_class = InternalBuildManagerBase


class ExternalBuildManager(SettingsOverrideObject):
_default_class = ExternalBuildManagerBase
25 changes: 25 additions & 0 deletions readthedocs/builds/migrations/0008_added_external_version_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-06-17 19:43
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('builds', '0007_add-automation-rules'),
]

operations = [
migrations.AlterField(
model_name='version',
name='type',
field=models.CharField(choices=[('branch', 'Branch'), ('tag', 'Tag'), ('external', 'External'), ('unknown', 'Unknown')], default='unknown', max_length=20, verbose_name='Type'),
),
migrations.AlterField(
model_name='versionautomationrule',
name='version_type',
field=models.CharField(choices=[('branch', 'Branch'), ('tag', 'Tag'), ('external', 'External'), ('unknown', 'Unknown')], max_length=32, verbose_name='Version type'),
),
]
Loading