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 @@ -26,6 +26,7 @@
ProjectAdvancedUpdate,
ProjectAdvertisingUpdate,
ProjectDashboard,
ProjectRepositoryReSync,
ProjectUpdate,
)

Expand Down Expand Up @@ -59,6 +60,10 @@
r'^(?P<project_slug>[-\w]+)/advanced/$',
ProjectAdvancedUpdate.as_view(), name='projects_advanced',
),
url(
r'^(?P<project_slug>[-\w]+)/resync/$',
ProjectRepositoryReSync.as_view(), name='project_repository_resync',
),
url(
r'^(?P<project_slug>[-\w]+)/version/(?P<version_slug>[^/]+)/delete_html/$',
private.project_version_delete_html, name='project_version_delete_html',
Expand Down
34 changes: 34 additions & 0 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -184,6 +185,39 @@ def project_version_detail(request, project_slug, version_slug):
)


class ProjectRepositoryReSync(ProjectAdminMixin, PrivateViewMixin, 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 repository re-sync triggered!'),
)
else:
messages.error(
request,
_('Unable to re-sync project repository!'),
)

return HttpResponseRedirect(self.get_success_url())

def get_success_url(self):
return reverse(
'project_version_list',
kwargs={'project_slug': self.get_project().slug},
)


@login_required
def project_delete(request, project_slug):
"""
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 @@ -22,6 +22,21 @@
<div class="module project-versions-active">
<div class="module-wrapper">

{% block resync_versions %}
{% if request.user|is_admin:project %}
<div class="button-bar">
<ul>
<li>
<form method="post" action="{% url 'project_repository_resync' project_slug=project.slug %}">
{% csrf_token %}
<input type="submit" value="{% trans 'Re-sync Versions' %}">
</form>
</li>
</ul>
</div>
{% endif %}
{% endblock %}

<div class="module-header">
<h1>{% trans "Active Versions" %}</h1>
</div>
Expand Down