Skip to content

Commit

Permalink
Build: reset notifications when reseting a build (#11027)
Browse files Browse the repository at this point in the history
* Build: reset notifications when reseting a build

When the build is retried for any reason we call `build.reset()` to make sure
the build is fresh. I'm adding the removal of all the notifications that were
attached to the build when reseting it.

* Add missing imports
  • Loading branch information
humitos authored Jan 11, 2024
1 parent 3e13e94 commit ce1d3a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ def reset(self):
self.builder = ''
self.cold_storage = False
self.commands.all().delete()
self.notifications.all().delete()
self.save()


Expand Down
9 changes: 9 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
LATEST,
)
from readthedocs.builds.models import APIVersion, Build, BuildCommandResult, Version
from readthedocs.doc_builder.exceptions import BuildUserError
from readthedocs.integrations.models import GenericAPIWebhook, Integration
from readthedocs.notifications.models import Notification
from readthedocs.oauth.models import (
RemoteOrganization,
RemoteOrganizationRelation,
Expand Down Expand Up @@ -108,7 +110,13 @@ def test_reset_build(self):
)
build.commands.add(command)

Notification.objects.add(
attached_to=build,
message_id=BuildUserError.SKIPPED_EXIT_CODE_183,
)

self.assertEqual(build.commands.count(), 1)
self.assertEqual(build.notifications.count(), 1)

client = APIClient()
_, build_api_key = BuildAPIKey.objects.create_key(self.project)
Expand All @@ -129,6 +137,7 @@ def test_reset_build(self):
self.assertEqual(build.builder, '')
self.assertFalse(build.cold_storage)
self.assertEqual(build.commands.count(), 0)
self.assertEqual(build.notifications.count(), 0)


def test_api_does_not_have_private_config_key_superuser(self):
Expand Down

0 comments on commit ce1d3a4

Please sign in to comment.