Skip to content

Re-sync Repository from VCS #6210

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

Closed
wants to merge 13 commits into from
5 changes: 5 additions & 0 deletions readthedocs/projects/urls/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ProjectNoticationsDelete,
ProjectRedirects,
ProjectRedirectsDelete,
ProjectVersionsSync,
ProjectTranslationsDelete,
ProjectTranslationsListAndCreate,
ProjectUpdate,
Expand Down Expand Up @@ -70,6 +71,10 @@
r'^(?P<project_slug>[-\w]+)/advanced/$',
ProjectAdvancedUpdate.as_view(), name='projects_advanced',
),
url(
r'^(?P<project_slug>[-\w]+)/resync/$',
ProjectVersionsSync.as_view(), name='project_version_sync',
),
url(
r'^(?P<project_slug>[-\w]+)/version/(?P<version_slug>[^/]+)/delete_html/$',
ProjectVersionDeleteHTML.as_view(),
Expand Down
28 changes: 28 additions & 0 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
from readthedocs.core.utils import broadcast, trigger_build
from readthedocs.core.utils.extend import SettingsOverrideObject
from readthedocs.core.views.hooks import sync_versions
from readthedocs.integrations.models import HttpExchange, Integration
from readthedocs.oauth.services import registry
from readthedocs.oauth.tasks import attach_webhook
Expand Down Expand Up @@ -213,6 +214,33 @@ def form_valid(self, form):
return HttpResponseRedirect(self.get_success_url())


class ProjectVersionsSync(ProjectVersionMixin, GenericView):

"""
Re-sync a project repository.

The signal will add a success/failure message on the request.
"""

def post(self, request, *args, **kwargs):
# pylint: disable=unused-argument
project = self.get_project()
sync = sync_versions(project)

if sync:
messages.success(
request,
_('Project version sync triggered'),
)
else:
messages.error(
request,
_("There was an error when syncing project's versions"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same feedback here, but also: there isn't much the user can do with this error. Do we have any additional information we can display in the sync variable? What error does a failure with the sync task point at otherwise? Perhaps there is more guidance that we can give the user.

As for the message, it's better to speak to the user -- something closer to:

Suggested change
_("There was an error when syncing project's versions"),
_("There was a problem updating the project versions"),

Copy link
Member Author

Choose a reason for hiding this comment

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

@agjohnson Actually sync_versions function only calls a celery task sync_repository_task So, I don't know if we can show much more information from sync variable.

)

return HttpResponseRedirect(self.get_success_url())


class ProjectVersionDeleteHTML(ProjectVersionMixin, GenericModelView):

http_method_names = ['get', 'post']
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/rtd_tests/tests/test_privacy_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
'/dashboard/pip/notifications/delete/': {'status_code': 405},
'/dashboard/pip/redirects/delete/': {'status_code': 405},
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
'/dashboard/pip/resync/': {'status_code': 405},
'/dashboard/pip/integrations/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
Expand Down Expand Up @@ -284,6 +285,7 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
'/dashboard/pip/notifications/delete/': {'status_code': 405},
'/dashboard/pip/redirects/delete/': {'status_code': 405},
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
'/dashboard/pip/resync/': {'status_code': 405},
'/dashboard/pip/integrations/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
Expand Down
15 changes: 15 additions & 0 deletions readthedocs/templates/projects/project_version_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
<h1>{% trans "Active Versions" %}</h1>
</div>

{% block resync_versions %}
{% if request.user|is_admin:project %}
<div class="button-bar">
<ul>
<li>
<form method="post" action="{% url 'project_version_sync' project_slug=project.slug %}">
{% csrf_token %}
<input type="submit" value="{% trans 'Sync Versions' %}">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a refresh icon button probably communicates what we need here and doesn't require us to add copy to our UI.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay :)

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 have added this one:
Screenshot from 2019-11-29 01-33-27

Another option might be:
Screenshot from 2019-11-29 01-33-11

</form>
</li>
</ul>
</div>
{% endif %}
{% endblock %}

<div class="module-list">
<div class="module-list-wrapper">
<ul>
Expand Down