Skip to content

Commit 1311bec

Browse files
committed
Badge: exclude duplicated builds
1 parent 5013d89 commit 1311bec

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

readthedocs/projects/views/public.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from readthedocs.analytics.tasks import analytics_event
2828
from readthedocs.analytics.utils import get_client_ip
29-
from readthedocs.builds.constants import LATEST
29+
from readthedocs.builds.constants import LATEST, BUILD_STATUS_DUPLICATED
3030
from readthedocs.builds.models import Version
3131
from readthedocs.builds.views import BuildTriggerMixin
3232
from readthedocs.core.permissions import AdminPermission
@@ -177,10 +177,13 @@ def get(self, request, project_slug, *args, **kwargs):
177177
).first()
178178

179179
if version:
180-
last_build = version.builds.filter(
181-
type='html',
182-
state='finished',
183-
).order_by('-date').first()
180+
last_build = (
181+
version.builds
182+
.filter(type='html', state='finished')
183+
.exclude(status=BUILD_STATUS_DUPLICATED)
184+
.order_by('-date')
185+
.first()
186+
)
184187
if last_build:
185188
if last_build.success:
186189
status = self.STATUS_PASSING

readthedocs/rtd_tests/tests/test_project_views.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.views.generic.base import ContextMixin
1212
from django_dynamic_fixture import get, new
1313

14-
from readthedocs.builds.constants import EXTERNAL
14+
from readthedocs.builds.constants import BUILD_STATUS_DUPLICATED, EXTERNAL
1515
from readthedocs.builds.models import Build, Version
1616
from readthedocs.integrations.models import GenericAPIWebhook, GitHubWebhook
1717
from readthedocs.oauth.models import RemoteRepository
@@ -611,6 +611,25 @@ def test_passing_badge(self):
611611
self.assertContains(res, 'passing')
612612
self.assertEqual(res['Content-Type'], 'image/svg+xml')
613613

614+
def test_ignore_duplicated_build(self):
615+
"""Ignore builds marked as duplicate from the badge status."""
616+
get(
617+
Build,
618+
project=self.project,
619+
version=self.version,
620+
success=True,
621+
)
622+
get(
623+
Build,
624+
project=self.project,
625+
version=self.version,
626+
success=False,
627+
status=BUILD_STATUS_DUPLICATED,
628+
)
629+
res = self.client.get(self.badge_url, {'version': self.version.slug})
630+
self.assertContains(res, 'passing')
631+
self.assertEqual(res['Content-Type'], 'image/svg+xml')
632+
614633
def test_failing_badge(self):
615634
get(Build, project=self.project, version=self.version, success=False)
616635
res = self.client.get(self.badge_url, {'version': self.version.slug})

0 commit comments

Comments
 (0)