Skip to content

Badge: exclude duplicated builds #8023

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

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 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,13 @@ 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we have another bug where builds are default set to finished when they are created. We should probably change that as well so we don't hit this as well 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean this is another problem (not something I need to change here)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it can be done in another PR.

.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