-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Merge initial work from Pull Request Builder GSOC #5823
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
Changes from 179 commits
Commits
Show all changes
201 commits
Select commit
Hold shift + click to select a range
31b9bf2
Version Type Added
saadmk11 bd11994
Version Model Methods Updated
saadmk11 8f3e64b
Internal and External Version Manager added
saadmk11 66200a0
lint fix
saadmk11 34e4134
All Version Querysets Updated with InternalVersionManager
saadmk11 3a3cfdf
Manager names moved to Constants
saadmk11 3d3de29
Tests added
saadmk11 b55983f
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 6187272
Updated migrations
saadmk11 386ca07
footer API updated
saadmk11 29348ef
manager tests updated
saadmk11 11a0583
_override_setting removed from new managers
saadmk11 c100c81
BuildTriggerMixin updated
saadmk11 c1c03bb
More Update
saadmk11 5ea5f67
lint fix
saadmk11 73a46a5
Merge branch 'master' into version-update
saadmk11 56493fa
removed unused import
saadmk11 d8cff7e
Merge branch 'master' into version-update
saadmk11 84a6975
External version name added everywhere
saadmk11 05951cf
Migration name changed
saadmk11 e192300
Sitemap sort order priorities updated
saadmk11 d5ec837
ordering fix
saadmk11 1f13be1
doc string fix
saadmk11 e0232b3
sort_by_priority function added to sitemap
saadmk11 fdcfcf6
lint fix
saadmk11 ef13214
Sorting by swapping positions
saadmk11 736a337
index out of range issue fix
saadmk11 c18f381
Use a real SessionBase object on FooterNoSessionMiddleware
humitos 908860a
Version Type Added
saadmk11 f81bcf0
Version Model Methods Updated
saadmk11 66377c2
Internal and External Version Manager added
saadmk11 8bdf75c
lint fix
saadmk11 21f96de
All Version Querysets Updated with InternalVersionManager
saadmk11 014477d
Manager names moved to Constants
saadmk11 d3f5254
Tests added
saadmk11 6bca1e4
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 8830a18
Updated migrations
saadmk11 5ed38c4
footer API updated
saadmk11 2d8b072
manager tests updated
saadmk11 89f3c8a
_override_setting removed from new managers
saadmk11 7b63973
BuildTriggerMixin updated
saadmk11 3a2fc6d
More Update
saadmk11 bca152a
lint fix
saadmk11 5f90052
Move search functions
stsewd 120eb5d
removed unused import
saadmk11 ef3d061
External version name added everywhere
saadmk11 5b33bbd
Migration name changed
saadmk11 5180743
Build Managers added
saadmk11 8301679
Managers used in all the places
saadmk11 7b75ee8
build manager tests added
saadmk11 8c7b02b
More Tests added
saadmk11 5d6c750
External version name added
saadmk11 c5d1c09
Merge branch 'gsoc-19-pr-builder' into build-manager-update
saadmk11 5329036
Sitemap sort order priorities updated
saadmk11 d64e2d0
ordering fix
saadmk11 51ad395
doc string fix
saadmk11 884857b
sort_by_priority function added to sitemap
saadmk11 43b24d7
lint fix
saadmk11 3e278a2
Sorting by swapping positions
saadmk11 7d3f934
index out of range issue fix
saadmk11 4194a42
Use a real SessionBase object on FooterNoSessionMiddleware
humitos 5572dee
Version Type Added
saadmk11 7f90a88
Version Model Methods Updated
saadmk11 19e7fa1
Internal and External Version Manager added
saadmk11 bd256fd
lint fix
saadmk11 fef7191
All Version Querysets Updated with InternalVersionManager
saadmk11 0dd9eb2
Manager names moved to Constants
saadmk11 f267881
Tests added
saadmk11 cc1297f
Version Update, Delete Html and wipe updated to exclude PR Versions
saadmk11 20ca139
Updated migrations
saadmk11 cb17a79
footer API updated
saadmk11 f687302
manager tests updated
saadmk11 bf9bd5e
_override_setting removed from new managers
saadmk11 12cd686
BuildTriggerMixin updated
saadmk11 d7330c1
More Update
saadmk11 eed1a9c
lint fix
saadmk11 f3f86dc
Move search functions
stsewd 3d62248
removed unused import
saadmk11 09a09a2
External version name added everywhere
saadmk11 119a3ae
Migration name changed
saadmk11 df4705a
Removed PR Versions from Elasticsearch Indexing
saadmk11 9140a57
HTMLFile manager added
saadmk11 f902d65
typo fix
saadmk11 afd5e47
lint fix
saadmk11 f03db54
External naming updated
saadmk11 1173718
Merge branch 'master' into version-update
saadmk11 5a05b6c
naming update
saadmk11 7607268
Merge branch 'gsoc-19-pr-builder' into build-manager-update
saadmk11 560cfef
Merge branch 'gsoc-19-pr-builder' into remove-pr-from-es
saadmk11 75efef8
naming updated
saadmk11 3c13c38
naming update for External
saadmk11 51188e7
fix
saadmk11 3bdf03c
fix
saadmk11 9b99538
vcs_url() update
saadmk11 cfd085c
tests updated
saadmk11 0beaad6
Merge pull request #5779 from saadmk11/build-manager-update
ericholscher 13c5330
Merge branch 'gsoc-19-pr-builder' into remove-pr-from-es
saadmk11 6fd5f68
lint fix
saadmk11 be8f4de
Sync External versions to our database
ericholscher 30ac6ba
Remove unused patterns
ericholscher df122da
Small whitespace cleanup
ericholscher da4f71d
Clean up fetch logic a bit
ericholscher 1207afb
Add Comment
ericholscher c74d294
Initial changes for PR Builder
saadmk11 e7c7417
removed _default_class for BuildManager
saadmk11 5fb2e4e
Only build external version from webhook payload
saadmk11 a859eac
fix
saadmk11 5b883df
need to pass verbose_name as a list for get_response_push
saadmk11 12f6658
Merge pull request #5828 from saadmk11/pr-builder
ericholscher 7bcb3e1
Merge pull request #5805 from saadmk11/remove-pr-from-es
ericholscher a166563
Merge branch 'master' of github.com:rtfd/readthedocs.org into gsoc-19…
ericholscher 31041a3
add all versions and builds to version and build listing
saadmk11 9cf8ec3
fix tests
saadmk11 711ed9a
fix tests
saadmk11 65697cb
refine webhook handling
saadmk11 7fa5a01
lint fix
saadmk11 5718ea7
Doc string updated
saadmk11 5663dc3
Doc string updated
saadmk11 e5d9725
Updated Action
saadmk11 7c6abc7
Merge pull request #5837 from saadmk11/remove-internal-filtering
ericholscher 3427564
Pull Request Closed webhook handled
saadmk11 2f739f0
More refining
saadmk11 9fbb839
tests added
saadmk11 cdd38a1
vcs_repo updated
saadmk11 7ef5175
vcs_repo more update
saadmk11 30390fe
updated event handling
saadmk11 694a27b
vcs_repo method updated
saadmk11 d721fc0
fix
saadmk11 1692dfb
use named args
saadmk11 7b2bc6c
Docstring added and some changes added
saadmk11 d38e44a
Merge pull request #5838 from saadmk11/refine-pr-building
ericholscher 70be132
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 6400305
migrations updated
saadmk11 04d4dca
fix typo
saadmk11 40fb6ee
Send Build Status using Github Status API
saadmk11 c561486
docstring update
saadmk11 3cf07f2
Updated Constants and notification sending
saadmk11 d9a867b
cleanup
saadmk11 ef6707b
task update
saadmk11 66526be
send_build_status updated
saadmk11 8f2505a
updated get full url
saadmk11 ac67805
changed to PRODUCTION_DOMAIN
saadmk11 95264e0
tasks updated
saadmk11 1c0dda5
some tests added
saadmk11 9b10ea6
send_build_status tests added
saadmk11 e8098fb
tests for tasks added
saadmk11 e7a1641
try catch added to task
saadmk11 917b2e5
exception log updated
saadmk11 3f500e3
storage updated for external versions
saadmk11 f9634b6
update send_build_status process
saadmk11 ec1c6a4
removed gitlab build status constants
saadmk11 edab9b3
lint fix
saadmk11 1d4e0db
version type passed to function
saadmk11 7629360
only build html for external versions
saadmk11 b436ed1
doc string update
saadmk11 1117caa
remove log test
saadmk11 21bc227
add check for external version in conf.py.tmpl
saadmk11 d7b1d0c
remove external versions from get_latest_build
saadmk11 c4f06dc
Merge pull request #5865 from saadmk11/github-status-api
ericholscher 9f492da
Merge branch 'gsoc-19-pr-builder' into update-storage
ericholscher 92215ce
Merge pull request #5886 from saadmk11/update-storage
ericholscher f2719b5
Merge pull request #5901 from saadmk11/get-latest-build-update
ericholscher 9bc0e33
Pass the build_pk to the task instead of the build object itself
ericholscher 23a215e
added Feature flag to enable External version building
saadmk11 219e0df
lint fix
saadmk11 64174f4
Apply suggestions from code review
ericholscher 9b23646
Merge pull request #5904 from readthedocs/pass-version-github-notific…
ericholscher b4a39aa
update conditions
saadmk11 5466b14
tests fixed
saadmk11 a6f4dd1
Merge pull request #5914 from saadmk11/test-fix
ericholscher b577d63
Merge pull request #5910 from saadmk11/feature-flag
ericholscher f03d076
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 1167c40
Update build list and detail page
saadmk11 d5af035
added commit url
saadmk11 1dd6bf2
Added commit url for build details page
saadmk11 2166770
Added tests
saadmk11 9af5521
setting commit url updated
saadmk11 8310e58
lint fix
saadmk11 ddf5259
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 9f593f2
Merge pull request #5916 from saadmk11/fix-build-ux
ericholscher 763b857
commit url return updated
saadmk11 2537fc3
small updates according to suggestions
saadmk11 9e643dc
Send failure status when build state in unknown
saadmk11 999070b
Test Fix
saadmk11 4f1709e
build details page UI fix
saadmk11 ce1353e
Added get_or_create for external version creation
saadmk11 f84ee69
create external version updated
saadmk11 b1fe82f
comments updated
saadmk11 8ed0345
log message updated
saadmk11 290bab8
log mistake fix
saadmk11 bf8247f
test fix
saadmk11 ea09b41
Merge pull request #5933 from saadmk11/refine-pr-builder
ericholscher 249e393
update build status message
saadmk11 008051a
small updates
saadmk11 b3128ae
external version feature flag fix
saadmk11 7861b0e
Merge pull request #5948 from saadmk11/pr-builder-update
ericholscher 9c5a756
Merge pull request #5900 from saadmk11/external-version-warning
ericholscher a25be20
Merge branch 'gsoc-19-pr-builder' into update-status-msg
saadmk11 49e3fe4
update status msg
saadmk11 0b454bb
Merge branch 'master' into gsoc-19-pr-builder
saadmk11 d89d519
Merge pull request #5947 from saadmk11/update-status-msg
ericholscher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ logs/* | |
| media/dash | ||
| media/epub | ||
| media/export | ||
| media/external | ||
| media/html | ||
| media/htmlzip | ||
| media/json | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,16 +19,27 @@ | |
| 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, | ||
| delete_external_version, | ||
| build_external_version, | ||
| ) | ||
| from readthedocs.integrations.models import HttpExchange, Integration | ||
| from readthedocs.projects.models import Project | ||
| from readthedocs.projects.models import Project, Feature | ||
|
|
||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| 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_OPENED = 'opened' | ||
| GITHUB_PULL_REQUEST_CLOSED = 'closed' | ||
| GITHUB_PULL_REQUEST_REOPENED = 'reopened' | ||
| GITHUB_PULL_REQUEST_SYNC = 'synchronize' | ||
| GITHUB_CREATE = 'create' | ||
| GITHUB_DELETE = 'delete' | ||
| GITLAB_TOKEN_HEADER = 'HTTP_X_GITLAB_TOKEN' | ||
|
|
@@ -110,6 +121,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 | ||
|
|
@@ -183,28 +198,96 @@ def sync_versions(self, project): | |
| 'versions': [version], | ||
| } | ||
|
|
||
| def get_external_version_response(self, project): | ||
| """ | ||
| Build External version on pull/merge request events and return API response. | ||
saadmk11 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Return a JSON response with the following:: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returns a dictionary.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it meant to say that it provides a JSON response to the server. Others are saying the same thing :) |
||
|
|
||
| { | ||
| "build_triggered": true, | ||
| "project": "project_name", | ||
| "versions": [verbose_name] | ||
| } | ||
|
|
||
| :param project: Project instance | ||
| :type project: Project | ||
saadmk11 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| identifier, verbose_name = self.get_external_version_data() | ||
| # create or get external version object using `verbose_name`. | ||
| external_version = get_or_create_external_version( | ||
| project, identifier, verbose_name | ||
| ) | ||
| # returns external version verbose_name (pull/merge request number) | ||
| to_build = build_external_version(project, external_version) | ||
|
|
||
| return { | ||
| 'build_triggered': True, | ||
| 'project': project.slug, | ||
| 'versions': [to_build], | ||
| } | ||
|
|
||
| def get_delete_external_version_response(self, project): | ||
| """ | ||
| Delete External version on pull/merge request `closed` events and return API response. | ||
|
|
||
| Return a JSON response with the following:: | ||
|
|
||
| { | ||
| "version_deleted": true, | ||
| "project": "project_name", | ||
| "versions": [verbose_name] | ||
| } | ||
|
|
||
| :param project: Project instance | ||
| :type project: Project | ||
| """ | ||
| identifier, verbose_name = self.get_external_version_data() | ||
| # Delete external version | ||
| deleted_version = delete_external_version( | ||
| project, identifier, verbose_name | ||
| ) | ||
| return { | ||
| 'version_deleted': deleted_version is not None, | ||
| 'project': project.slug, | ||
| 'versions': [deleted_version], | ||
| } | ||
|
|
||
|
|
||
| class GitHubWebhookView(WebhookMixin, APIView): | ||
|
|
||
| """ | ||
| Webhook consumer for GitHub. | ||
|
|
||
| Accepts webhook events from GitHub, 'push' events trigger builds. Expects the | ||
| webhook event type will be included in HTTP header ``X-GitHub-Event``, and | ||
| we will have a JSON payload. | ||
| Accepts webhook events from GitHub, 'push' and 'pull_request' events trigger builds. | ||
| Expects the webhook event type will be included in HTTP header ``X-GitHub-Event``, | ||
| and we will have a JSON payload. | ||
|
|
||
| Expects the following JSON:: | ||
|
|
||
| { | ||
| "ref": "branch-name", | ||
| ... | ||
| } | ||
| For push, create, delete Events: | ||
| { | ||
| "ref": "branch-name", | ||
| ... | ||
| } | ||
|
|
||
| For pull_request Events: | ||
| { | ||
| "action": "opened", | ||
| "number": 2, | ||
| "pull_request": { | ||
| "head": { | ||
| "sha": "ec26de721c3235aad62de7213c562f8c821" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| See full payload here: | ||
|
|
||
| - https://developer.github.com/v3/activity/events/types/#pushevent | ||
| - https://developer.github.com/v3/activity/events/types/#createevent | ||
| - https://developer.github.com/v3/activity/events/types/#deleteevent | ||
| - https://developer.github.com/v3/activity/events/types/#pullrequestevent | ||
| """ | ||
|
|
||
| integration_type = Integration.GITHUB_WEBHOOK | ||
|
|
@@ -218,6 +301,17 @@ def get_data(self): | |
| pass | ||
| return super().get_data() | ||
|
|
||
| def get_external_version_data(self): | ||
| """Get Commit Sha and pull request number from payload.""" | ||
| try: | ||
| identifier = self.data['pull_request']['head']['sha'] | ||
| verbose_name = str(self.data['number']) | ||
|
|
||
| return identifier, verbose_name | ||
|
|
||
| except KeyError: | ||
| raise ParseError('Parameters "sha" and "number" are required') | ||
|
|
||
| def is_payload_valid(self): | ||
| """ | ||
| GitHub use a HMAC hexdigest hash to sign the payload. | ||
|
|
@@ -256,6 +350,7 @@ def get_digest(secret, msg): | |
|
|
||
| def handle_webhook(self): | ||
| # Get event and trigger other webhook events | ||
| action = self.data.get('action', None) | ||
| event = self.request.META.get(GITHUB_EVENT_HEADER, GITHUB_PUSH) | ||
| webhook_github.send( | ||
| Project, | ||
|
|
@@ -272,6 +367,26 @@ def handle_webhook(self): | |
| raise ParseError('Parameter "ref" is required') | ||
| if event in (GITHUB_CREATE, GITHUB_DELETE): | ||
| return self.sync_versions(self.project) | ||
|
|
||
| if ( | ||
| self.project.has_feature(Feature.ENABLE_EXTERNAL_VERSION_BUILD) and | ||
| event == GITHUB_PULL_REQUEST and action | ||
| ): | ||
| if ( | ||
| action in | ||
| [ | ||
| GITHUB_PULL_REQUEST_OPENED, | ||
| GITHUB_PULL_REQUEST_REOPENED, | ||
| GITHUB_PULL_REQUEST_SYNC | ||
| ] | ||
| ): | ||
| # Handle opened, synchronize, reopened pull_request event. | ||
| return self.get_external_version_response(self.project) | ||
|
|
||
| if action == GITHUB_PULL_REQUEST_CLOSED: | ||
| # Handle closed pull_request event. | ||
| return self.get_delete_external_version_response(self.project) | ||
|
|
||
| return None | ||
|
|
||
| def _normalize_ref(self, ref): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.