Skip to content

Commit

Permalink
Badge: exclude duplicated builds
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Mar 16, 2021
1 parent 5013d89 commit ed7c12d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
16 changes: 11 additions & 5 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from readthedocs.analytics.tasks import analytics_event
from readthedocs.analytics.utils import get_client_ip
from readthedocs.builds.constants import LATEST
from readthedocs.builds.constants import LATEST, BUILD_STATUS_DUPLICATED
from readthedocs.builds.models import Version
from readthedocs.builds.views import BuildTriggerMixin
from readthedocs.core.permissions import AdminPermission
Expand Down Expand Up @@ -177,10 +177,16 @@ def get(self, request, project_slug, *args, **kwargs):
).first()

if version:
last_build = version.builds.filter(
type='html',
state='finished',
).order_by('-date').first()
last_build = (
version.builds
.filter(
type='html',
state='finished',
)
.exclude(status=BUILD_STATUS_DUPLICATED)
.order_by('-date')
.first()
)
if last_build:
if last_build.success:
status = self.STATUS_PASSING
Expand Down
21 changes: 20 additions & 1 deletion readthedocs/rtd_tests/tests/test_project_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.views.generic.base import ContextMixin
from django_dynamic_fixture import get, new

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

def test_ignore_duplicated_build(self):
"""Ignore builds marked as duplicate from the badge status."""
get(
Build,
project=self.project,
version=self.version,
success=True,
)
get(
Build,
project=self.project,
version=self.version,
success=False,
status=BUILD_STATUS_DUPLICATED,
)
res = self.client.get(self.badge_url, {'version': self.version.slug})
self.assertContains(res, 'passing')
self.assertEqual(res['Content-Type'], 'image/svg+xml')

def test_failing_badge(self):
get(Build, project=self.project, version=self.version, success=False)
res = self.client.get(self.badge_url, {'version': self.version.slug})
Expand Down

0 comments on commit ed7c12d

Please sign in to comment.