Skip to content

Commit a89562a

Browse files
committed
Update build list and detail page
1 parent 9b23646 commit a89562a

File tree

7 files changed

+51
-20
lines changed

7 files changed

+51
-20
lines changed

readthedocs/builds/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@
8787
'description': 'The build succeeded!',
8888
},
8989
}
90+
91+
GITHUB_EXTERNAL_VERSION_NAME = 'Pull Request'

readthedocs/builds/models.py

+33
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from readthedocs.projects.constants import (
2323
BITBUCKET_URL,
2424
GITHUB_URL,
25+
GITHUB_PULL_REQEST_URL,
2526
GITLAB_URL,
2627
PRIVACY_CHOICES,
2728
PRIVATE,
@@ -36,6 +37,7 @@
3637
BUILD_STATE_FINISHED,
3738
BUILD_STATE_TRIGGERED,
3839
BUILD_TYPES,
40+
GITHUB_EXTERNAL_VERSION_NAME,
3941
INTERNAL,
4042
LATEST,
4143
NON_REPOSITORY_VERSIONS,
@@ -539,6 +541,23 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
539541
source_suffix=source_suffix,
540542
)
541543

544+
def get_external_version_url(self):
545+
"""Return a Pull/Merge Request URL."""
546+
repo_url = self.project.repo
547+
user, repo = get_github_username_repo(repo_url)
548+
549+
if not user and not repo:
550+
return ''
551+
552+
if 'github' in repo_url:
553+
repo = repo.rstrip('/')
554+
return GITHUB_PULL_REQEST_URL.format(
555+
user=user,
556+
repo=repo,
557+
number=self.verbose_name
558+
)
559+
return ''
560+
542561

543562
class APIVersion(Version):
544563

@@ -756,6 +775,20 @@ def is_stale(self):
756775
mins_ago = timezone.now() - datetime.timedelta(minutes=5)
757776
return self.state == BUILD_STATE_TRIGGERED and self.date < mins_ago
758777

778+
@property
779+
def is_external(self):
780+
return self.version.type == EXTERNAL
781+
782+
@property
783+
def external_version_name(self):
784+
if self.is_external:
785+
try:
786+
if self.project.remote_repository.account.provider == 'github':
787+
return GITHUB_EXTERNAL_VERSION_NAME
788+
except Exception:
789+
return None
790+
return None
791+
759792
def using_latest_config(self):
760793
return int(self.config.get('version', '1')) == LATEST_CONFIGURATION_VERSION
761794

readthedocs/builds/views.py

-15
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,6 @@ def post(self, request, project_slug):
8484

8585
class BuildList(BuildBase, BuildTriggerMixin, ListView):
8686

87-
def get_queryset(self):
88-
# this is used to include only internal version
89-
# builds in the build list page
90-
self.project_slug = self.kwargs.get('project_slug', None)
91-
self.project = get_object_or_404(
92-
Project.objects.protected(self.request.user),
93-
slug=self.project_slug,
94-
)
95-
queryset = Build.objects.public(
96-
user=self.request.user,
97-
project=self.project,
98-
).select_related('project', 'version')
99-
100-
return queryset
101-
10287
def get_context_data(self, **kwargs):
10388
context = super().get_context_data(**kwargs)
10489

readthedocs/projects/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@
325325
'https://github.com/{user}/{repo}/'
326326
'{action}/{version}{docroot}{path}{source_suffix}'
327327
)
328+
GITHUB_PULL_REQEST_URL = (
329+
'https://github.com/{user}/{repo}/'
330+
'pull/{number}'
331+
)
328332
BITBUCKET_URL = (
329333
'https://bitbucket.org/{user}/{repo}/'
330334
'src/{version}{docroot}{path}{source_suffix}'

readthedocs/projects/views/public.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_context_data(self, **kwargs):
9393
context = super().get_context_data(**kwargs)
9494

9595
project = self.get_object()
96-
context['versions'] = Version.objects.public(
96+
context['versions'] = Version.internal.public(
9797
user=self.request.user,
9898
project=project,
9999
)
@@ -269,7 +269,7 @@ def project_versions(request, project_slug):
269269
slug=project_slug,
270270
)
271271

272-
versions = Version.objects.public(
272+
versions = Version.internal.public(
273273
user=request.user,
274274
project=project,
275275
only_active=False,

readthedocs/templates/builds/build_detail.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@
7979

8080
<div class="build-version">
8181
<span class="build-version-slug">
82-
{% if request.user|is_admin:project %}
82+
{% if request.user|is_admin:project and not build.is_external %}
8383
<a href="{% url "project_version_detail" build.version.project.slug build.version.slug %}">{{ build.version.slug }}</a>
8484
{% else %}
85-
{{ build.version.slug }}
85+
{% if build.is_external %}
86+
{% blocktrans with build.external_version_name as external_version_name %}
87+
<b>{{ external_version_name }}</b> #
88+
{% endblocktrans %}
89+
<a href="{{ build.version.get_external_version_url }}">{{ build.version.verbose_name }}</a>
90+
{% else %}
91+
{{ build.version.slug }}
92+
{% endif %}
8693
{% endif %}
8794
</span>
8895
<span class="build-commit"

readthedocs/templates/core/build_list_detailed.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div id="build-{{ build.id }}">
77
<a href="{{ build.get_absolute_url }}">{% if build.is_stale %}<span class="icon-warning" title="{% trans 'This build is still waiting to be built' %}"></span>{% endif %}<span id="build-state">{% if build.state != 'finished' %}{{ build.get_state_display }} {% else %} {% if build.success %}{% trans "Passed" %}{% else %}{% trans "Failed" %}{% endif %}{% endif %}</span>
88
<img src="{% static 'core/img/loader.gif' %}" class="build-loading hide">
9-
<span class="quiet">{% if build.version %}{% blocktrans with build.version.slug as slug and build.type as type %}version {{ slug }} ({{ type }}){% endblocktrans %}{% endif %}</span><span class="quiet right">{% blocktrans with build.date|timesince as date %}{{ date }} ago{% endblocktrans %}</span>
9+
<span class="quiet">{% if build.version %}{% if build.is_external %}{% blocktrans %}External {% endblocktrans %}{% endif %}{% blocktrans with build.version.slug as slug and build.type as type %}version {{ slug }} ({{ type }}){% endblocktrans %}{% endif %}</span><span class="quiet right">{% blocktrans with build.date|timesince as date %}{{ date }} ago{% endblocktrans %}</span>
1010
</a>
1111
</div>
1212
</li>

0 commit comments

Comments
 (0)