Skip to content

Commit 798afe2

Browse files
committed
PR Build tab added to project dashboard
1 parent 3dd0cbf commit 798afe2

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

readthedocs/builds/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ def is_stale(self):
745745
def using_latest_config(self):
746746
return int(self.config.get('version', '1')) == LATEST_CONFIGURATION_VERSION
747747

748+
@property
749+
def is_pr(self):
750+
"""Return if build is a Pull Request Build."""
751+
return self.version.type == PULL_REQUEST
752+
748753

749754
class BuildCommandResultMixin:
750755

readthedocs/builds/views.py

+36
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@ def get_context_data(self, **kwargs):
117117
return context
118118

119119

120+
class PRBuildList(BuildBase, BuildTriggerMixin, ListView):
121+
template_name = 'builds/pr_build_list.html'
122+
123+
def get_queryset(self):
124+
# this is used to include only internal version
125+
# builds in the build list page
126+
self.project_slug = self.kwargs.get('project_slug', None)
127+
self.project = get_object_or_404(
128+
Project.objects.protected(self.request.user),
129+
slug=self.project_slug,
130+
)
131+
queryset = Build.external.public(
132+
user=self.request.user,
133+
project=self.project,
134+
).select_related('project', 'version')
135+
136+
return queryset
137+
138+
def get_context_data(self, **kwargs):
139+
context = super().get_context_data(**kwargs)
140+
141+
active_builds = self.get_queryset().exclude(
142+
state='finished',
143+
).values('id')
144+
145+
context['project'] = self.project
146+
context['active_builds'] = active_builds
147+
context['versions'] = Version.external.public(
148+
user=self.request.user,
149+
project=self.project,
150+
)
151+
context['build_qs'] = self.get_queryset()
152+
153+
return context
154+
155+
120156
class BuildDetail(BuildBase, DetailView):
121157
pk_url_kwarg = 'build_pk'
122158

readthedocs/projects/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,14 @@ def get_builds_url(self):
519519
},
520520
)
521521

522+
def get_pr_builds_url(self):
523+
return reverse(
524+
'pr_builds_project_list',
525+
kwargs={
526+
'project_slug': self.slug,
527+
},
528+
)
529+
522530
def get_canonical_url(self):
523531
if settings.DONT_HIT_DB:
524532
return api.project(self.pk).canonical_url().get()['url']

readthedocs/projects/urls/public.py

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
build_views.BuildList.as_view(),
7272
name='builds_project_list',
7373
),
74+
url(
75+
(r'^(?P<project_slug>{project_slug})/builds/pr/$'.format(**pattern_opts)),
76+
build_views.PRBuildList.as_view(),
77+
name='pr_builds_project_list',
78+
),
7479
url(
7580
r'^(?P<project_slug>{project_slug})/versions/$'.format(**pattern_opts),
7681
public.project_versions,

readthedocs/templates/builds/build_detail.html

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@
2222
{% endblock %}
2323

2424
{% block project_editing %}
25-
{% with builds_active="active" %}
26-
{% include "core/project_bar.html" %}
27-
{% endwith %}
25+
26+
{% if build.is_pr %}
27+
28+
{% with pr_builds_active="active" %}
29+
{% include "core/project_bar.html" %}
30+
{% endwith %}
31+
{% else %}
32+
{% with builds_active="active" %}
33+
{% include "core/project_bar.html" %}
34+
{% endwith %}
35+
36+
{% endif %}
37+
2838
{% endblock %}
2939

3040
{% block content %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% extends "projects/base_project.html" %}
2+
3+
{% load i18n %}
4+
{% load static %}
5+
6+
{% load pagination_tags %}
7+
{% load privacy_tags %}
8+
{% load projects_tags %}
9+
10+
{% block title %}Builds{% endblock %}
11+
12+
{% block project_editing %}
13+
{% with pr_builds_active="active" %}
14+
{% include "core/project_bar.html" %}
15+
{% endwith %}
16+
{% endblock %}
17+
18+
{% block content %}
19+
20+
21+
<div id="build_list">
22+
23+
{% autopaginate build_qs 15 %}
24+
25+
<!-- BEGIN builds list -->
26+
<div class="module">
27+
<div class="module-wrapper">
28+
<h1>{% trans "Recent Pull Request Builds" %}</h1>
29+
30+
<div class="module-list">
31+
<div class="module-list-wrapper">
32+
<ul>
33+
{% include "core/build_list_detailed.html" %}
34+
</ul>
35+
</div>
36+
</div>
37+
38+
</div>
39+
</div>
40+
<!-- END builds list -->
41+
42+
{% paginate %}
43+
44+
</div>
45+
46+
{% endblock %}

readthedocs/templates/core/project_bar_base.html

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ <h1>
4545

4646
<li class="{{ builds_active }}"><a href="{{ project.get_builds_url }}">{% trans "Builds" %}</a></li>
4747

48+
<li class="{{ pr_builds_active }}"><a href="{{ project.get_pr_builds_url }}">{% trans "PR Builds" %}</a></li>
49+
4850
<li class="{{ versions_active }}"><a href="{% url "project_version_list" project.slug %}">{% trans "Versions" %}</a></li>
4951

5052
{% comment %}

0 commit comments

Comments
 (0)