$ pre-commit run python-import-sorter --files `find readthedocs -name '*.py'`
It was ran with this configuration: https://github.com/rtfd/common/pull/28
* Upgrade all packages using pur
for reqs in `ls requirements`;
do
pur
--skip django-tastypie,django,docker,elasticsearch,pyelasticsearch,commonmark,stripe,djangorestframework,mkdocs,django-allauth,django-filter,mercurial
--requirement requirements/$reqs;
done
* Run lint with Python 3.6
* Downgrade gitpython to 2.1.10
* Linting error fixed
* Upgrade common
Branch: https://github.com/rtfd/common/pull/17
* Remove old note for testing
* Add note for django-filter
* no-else-return fixed in all the files
Some block needed to be re-idented to fulfill this check.
Basically, if you have a "if something: return another" the "else"
clause is not needed since it will be the common case for the flow to
continue if the condition is not met.
* Only # noqa comment
* Note about gitpython
* Allow to hook the initial build from outside
Add a new attribute to `trigger_build` to do not execute the task but
just return the immutable signature of it, so it can be chained into a
bigger task from outside when it's needed to do something else
before/after it's execution.
* Remove unused basic attribute on trigger build
* Split trigger_build to be able to prepare_build first
Added a ``ImportWizard.trigger_initial_build`` method to be override
from corporate site.
Also, instead of using ``trigger_build`` to create the Celery task and
call it immediately, split it to use ``prepare_build`` first to create
the task and use ``trigger_build`` to effectively triggers it.
* Remove now unused signal
* Fix Celery signature creation
* Fix testcases with basic on trigger_build
* Fix mock calls in test cases
* Fix test mock check
* Use async task to attach webhook
* Use proper context object
* Make it compatible with newer Django versions
* Py2 and Py3 compatible line
* Dismiss the sticky message and stay in the same page
* Use Context to render the template
* Lint errors fixed
* Call the task in a sync way properly
* Update common submodule to latest
* Define NonPersistentStorage for one-time notifications
NonPersistentNotification backed together with SiteNotification class
helps us to create one-time site notifications and attach it to a user
without the needs of a request/session object.
The message/notification is saved into the database as a
PersistentMessage and it's marked as read while it's retrived the
first time.
This system is useful for notifications that need to be attached from
a Celery task where we know the user but we don't have the request.
* Make string translatable
* Fix merge conflicts
* Recover accidentally deleted line
* Fixed linting errors
* Replace message_key with reason to be clearer
* Rename non persistent storage class
* Remove old templates
* Make SiteNotification more flexible
- render strings messages as Django Templates
- accept extra_context for the template
- do not crash if the reason is incorrect
* Adapt AttachWebhookNotification to the new features
* Refactor the task to attach a webhook
Instantiate only once the notification and adapt it depending the
context.
Also, if there are no connected services into our application do not
show a message to the user, but log it as a warning.
* Test cases for SiteNotification and NonPersistentStorage
* Remove unnecessary lines
* Show a persistent message for invalid project webhook
If we can setup a valid webhook, we show a persistent message with an
actionable link using our notifications abstraction.
At this point, the message is duplicated because we have a "fixed
template message" also which is planned to be removed soon.
* Improve copy
* Allow to hook the initial build from outside
Add a new attribute to `trigger_build` to do not execute the task but
just return the immutable signature of it, so it can be chained into a
bigger task from outside when it's needed to do something else
before/after it's execution.
* Remove unused basic attribute on trigger build
* Split trigger_build to be able to prepare_build first
Added a ``ImportWizard.trigger_initial_build`` method to be override
from corporate site.
Also, instead of using ``trigger_build`` to create the Celery task and
call it immediately, split it to use ``prepare_build`` first to create
the task and use ``trigger_build`` to effectively triggers it.
* Remove now unused signal
* Fix Celery signature creation
* Fix testcases with basic on trigger_build
* Fix mock calls in test cases
* Fix test mock check
* Use proper context object
* Make it compatible with newer Django versions
* Py2 and Py3 compatible line
* Dismiss the sticky message and stay in the same page
* Use Context to render the template
* Lint errors fixed
* Call the task in a sync way properly
* Update common submodule to latest
* Define NonPersistentStorage for one-time notifications
NonPersistentNotification backed together with SiteNotification class
helps us to create one-time site notifications and attach it to a user
without the needs of a request/session object.
The message/notification is saved into the database as a
PersistentMessage and it's marked as read while it's retrived the
first time.
This system is useful for notifications that need to be attached from
a Celery task where we know the user but we don't have the request.
* Make string translatable
* Use async task to attach webhook
* Fix merge conflicts
* Recover accidentally deleted line
* Fixed linting errors
* Replace message_key with reason to be clearer
* Rename non persistent storage class
* Remove old templates
* Make SiteNotification more flexible
- render strings messages as Django Templates
- accept extra_context for the template
- do not crash if the reason is incorrect
* Adapt AttachWebhookNotification to the new features
* Refactor the task to attach a webhook
Instantiate only once the notification and adapt it depending the
context.
Also, if there are no connected services into our application do not
show a message to the user, but log it as a warning.
* Test cases for SiteNotification and NonPersistentStorage
* Remove unnecessary lines
* Show a persistent message for invalid project webhook
If we can setup a valid webhook, we show a persistent message with an
actionable link using our notifications abstraction.
At this point, the message is duplicated because we have a "fixed
template message" also which is planned to be removed soon.
* Improve copy
* Remove fixed template notification about Project.has_valid_webhook
* Handle general oauth services errors
This is a way to protect ourselves from random errors when syncing
OAuth services (create repository/organizations).
If a global exception is raised, we just skip this service and
continue with the rest of the connected ones.
* Handle revoked oauth permissions by the user
If the user revoked our app permission from the external service web
page, we are not notified. So, next time we try to use it, we will
receive a 401 status code in the first request.
Here we handle this case and we show a Persistent Notification to the
user so he/she knows that a reconnection of the account is needed.
* Remove unnecessary exception handling
* Style
* Add a user persistent notification when social access is revoked
* Raise an Exception when permissions revoked
Raise a simple Exception when the permissions from a particular social
service are revoked instead of using a persistent notification.
We want an Exception because it's immediately communicated using the
PublicTask mechanism. Otherwise, the user needs to refresh the page to
see the notification.
* Remove invalid imports
* Improve comment
* Add final dot to the phrase
* Remove unused return
* Allow import Gitlab repo manually and set a webhook automatically
When we import a Project manually we don't have a RemoteRepository
associated with that Project, so we use the old technique of getting
the username and repo names from the URL using
`get_gitlab_username_repo` function.
This case (Manual Import) won't support custom Gitlab installations in
the future with this code.
* Handle username,repo not found
* Test case
When a project is imported manually, if the user has a valid social
account we setup a webhook for this project.
If the user goes to Integrations and try to resync, we handle that
properly (use the Project.remote_repository only when available,
otherwise use the accounts registered for that service even if they
are not associated with that project)
If the user delete the RTD webhook integration for whatever reason
from the project under the external service (GitHub, etc) when the
Resync button is pressed we re-create / setup the webhook as it was
never existed.
* Organize logging levels
Log only what we need as ERROR when it's something that we need/want
to take a look that something could be a bug/issue.
There are some ERROR that were replaced by WARNING since they are some
failures but that we don't need to take a look and the message shown
to the user should be enough for them.
* Fix lint issues
* Use the proper exc_info instead of custom formatting
Because of a python quirk, we are currently returning an empty list during
pagination against oauth proviers. The quirk breaks down to this:
```python
def foo():
try:
return 'duck'
except Exception:
return 'duck'
finally:
return 'goose'
assert foo() == 'goose'
```
I didn't realize `finally` behaved in this manner with respect to `return`, so
hey, The More You Know™
* Do not convert to bytes the `refresh_token`
When the body is encoded, a mix of bytes and unicode happens and it
fails at this line
c472e6bf04/requests_oauthlib/oauth2_session.py (L285)
(Pdb) body
u'grant_type=refresh_token&allow_redirects=True&refresh_token=b%27z9BSRKqf2QD4pcDhqj%27&client_id=CLIENT_ID&client_secret=CLIENT_SECRET'
(note those weird `%27` in the string)
* Handle OAuth specific exception properly at `paginate`
* Do not convert the `acess_token` to bytes
* Fix lint :(
* Refactor `paginate` to handle exception in Bitbucket and Github
`paginate` method is shared between both services and each service
implement `get_next_url_to_paginate` and `get_paginated_results`.
* Names and attributes fixes
* Use new Celery, use new application pattern
* Use modern celery
* Drop djcelery
* New pattern for starting celery
* Bump redis to 2.10.6 to avoid startup bug, change autodiscover call
* Update docs mentioning Celery
* Goof on package name
* Missed djcelery import
* Fix rebased task that was missed
* Handle change to Celery group calls in 4.x
* Fix tests
* Fix up some linting issues and problems starting the application
* Fix celery task registration
* We don't need shared_task anymore, swap for readthedocs.worker.app.task
* Fix call to chord
This apparently changed at some point. This was triggered when no accounts were
connected and a project import was attempted. Webhook setup would try to emit a
warning message for the provider.
The privacy app was a strange mixture of various application models managers,
querysets, and syncers. Instead, logic is moved to where we should be using it,
inside the other applications
* Resolve first round of linting errors in restapi.
This is a first step and only adds docstrings, etc. It doesn't refactor any
code.
Conflicts:
prospector-more.yml
readthedocs/restapi/views/model_views.py
* Reduce unused params.
In several cases, we can use the provided `request` rather than access `self`
(which could make these functions easier to test in isolation). In others, the
unused args could be folded into an unnamed kwarg param.
* Don't replace section variable.
This worked as intended, but only because the overridden section variable
would later evaluate to True. Using a different variable name makes this a bit
less error-prone.
* Minor docstring update
* Fix indent on docstring
* Punt on refactoring
* Fix call args
* Try unpinning testing reqs
* Bump up prospector higher level strictness
* Linting issues: arguments-differ, len-as-condition, redefined variables
* Remove unnecessary elses
This addresses no-else-return, which removes a `return` in an `else` after an
`if` that already has a `return`. This makes the default return more obvious in
most cases.
* Fix new linting issues with import order
Also, update travis and tox config for multiple versions of python
* Another fix on travis envs