Skip to content

Commit 1552523

Browse files
committed
Reset more fields
1 parent 1dce09b commit 1552523

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

readthedocs/api/v2/views/model_views.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from rest_framework.renderers import BaseRenderer, JSONRenderer
1313
from rest_framework.response import Response
1414

15-
from readthedocs.builds.constants import INTERNAL
15+
from readthedocs.builds.constants import BUILD_STATE_TRIGGERED, INTERNAL
1616
from readthedocs.builds.models import Build, BuildCommandResult, Version
1717
from readthedocs.builds.tasks import sync_versions_task
1818
from readthedocs.oauth.models import RemoteOrganization, RemoteRepository
@@ -277,15 +277,21 @@ def retrieve(self, *args, **kwargs):
277277
permission_classes=[permissions.IsAdminUser],
278278
methods=['post'],
279279
)
280-
def restart(self, request, **kwargs):
280+
def reset(self, request, **kwargs):
281281
"""
282-
Restart the build so it can be re-used when re-trying.
282+
Reset the build so it can be re-used when re-trying.
283283
284284
Dates and states are usually overriden by the build,
285285
we care more about deleting the commands.
286286
"""
287287
instance = self.get_object()
288+
instance.state = BUILD_STATE_TRIGGERED
289+
instance.status = ''
290+
instance.success = True
288291
instance.output = ''
292+
instance.error = ''
293+
instance.exit_code = None
294+
instance.builder = ''
289295
instance.cold_storage = False
290296
instance.commands.all().delete()
291297
instance.save()

readthedocs/projects/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def run_setup(self, record=True):
670670
671671
Return True if successful.
672672
"""
673-
api_v2.build(self.build['id']).restart.post()
673+
api_v2.build(self.build['id']).reset.post()
674674

675675
if settings.DOCKER_ENABLE:
676676
env_cls = DockerBuildEnvironment

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@
3737
GitLabWebhookView,
3838
)
3939
from readthedocs.api.v2.views.task_views import get_status_data
40-
from readthedocs.builds.constants import EXTERNAL, LATEST
40+
from readthedocs.builds.constants import (
41+
BUILD_STATE_CLONING,
42+
BUILD_STATE_TRIGGERED,
43+
BUILD_STATUS_DUPLICATED,
44+
EXTERNAL,
45+
LATEST,
46+
)
4147
from readthedocs.builds.models import Build, BuildCommandResult, Version
4248
from readthedocs.integrations.models import Integration
4349
from readthedocs.oauth.models import RemoteOrganization, RemoteRepository
@@ -87,11 +93,19 @@ def test_make_build(self):
8793
self.assertEqual(build['output'], 'Test Output')
8894
self.assertEqual(build['state_display'], 'Cloning')
8995

90-
def test_restart_build(self):
96+
def test_reset_build(self):
9197
build = get(
9298
Build,
9399
project=self.project,
94100
version=self.version,
101+
state=BUILD_STATE_CLONING,
102+
status=BUILD_STATUS_DUPLICATED,
103+
success=False,
104+
output='Output',
105+
error='Error',
106+
exit_code=9,
107+
builder='Builder',
108+
cold_storage=True,
95109
)
96110
command = get(
97111
BuildCommandResult,
@@ -103,8 +117,20 @@ def test_restart_build(self):
103117

104118
client = APIClient()
105119
client.force_login(self.user)
106-
r = client.post(reverse('build-restart', args=(build.pk,)))
120+
r = client.post(reverse('build-reset', args=(build.pk,)))
121+
107122
self.assertEqual(r.status_code, 204)
123+
build.refresh_from_db()
124+
self.assertEqual(build.project, self.project)
125+
self.assertEqual(build.version, self.version)
126+
self.assertEqual(build.state, BUILD_STATE_TRIGGERED)
127+
self.assertEqual(build.status, '')
128+
self.assertTrue(build.success)
129+
self.assertEqual(build.output, '')
130+
self.assertEqual(build.error, '')
131+
self.assertIsNone(build.exit_code)
132+
self.assertEqual(build.builder, '')
133+
self.assertFalse(build.cold_storage)
108134
self.assertEqual(build.commands.count(), 0)
109135

110136

readthedocs/rtd_tests/tests/test_privacy_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def setUp(self):
382382
}
383383
self.response_data = {
384384
'build-concurrent': {'status_code': 403},
385-
'build-restart': {'status_code': 403},
385+
'build-reset': {'status_code': 403},
386386
'project-sync-versions': {'status_code': 403},
387387
'project-token': {'status_code': 403},
388388
'emailhook-list': {'status_code': 403},

0 commit comments

Comments
 (0)