Skip to content

Update build list and detail page UX #5916

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 6 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions readthedocs/builds/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@
'description': 'The build succeeded!',
},
}

GITHUB_EXTERNAL_VERSION_NAME = 'Pull Request'
33 changes: 33 additions & 0 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from readthedocs.projects.constants import (
BITBUCKET_URL,
GITHUB_URL,
GITHUB_PULL_REQEST_URL,
GITLAB_URL,
PRIVACY_CHOICES,
PRIVATE,
Expand All @@ -36,6 +37,7 @@
BUILD_STATE_FINISHED,
BUILD_STATE_TRIGGERED,
BUILD_TYPES,
GITHUB_EXTERNAL_VERSION_NAME,
INTERNAL,
LATEST,
NON_REPOSITORY_VERSIONS,
Expand Down Expand Up @@ -539,6 +541,23 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
source_suffix=source_suffix,
)

def get_external_version_url(self):
"""Return a Pull/Merge Request URL."""
repo_url = self.project.repo
user, repo = get_github_username_repo(repo_url)

if not user and not repo:
return ''

if 'github' in repo_url:
repo = repo.rstrip('/')
return GITHUB_PULL_REQEST_URL.format(
user=user,
repo=repo,
number=self.verbose_name
)
return ''


class APIVersion(Version):

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

@property
def is_external(self):
return self.version.type == EXTERNAL

@property
def external_version_name(self):
if self.is_external:
try:
if self.project.remote_repository.account.provider == 'github':
return GITHUB_EXTERNAL_VERSION_NAME
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

We should log this exception, otherwise it will hide real issues. What exception are we really trying to catch?

return None
return None

def using_latest_config(self):
return int(self.config.get('version', '1')) == LATEST_CONFIGURATION_VERSION

Expand Down
15 changes: 0 additions & 15 deletions readthedocs/builds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,6 @@ def post(self, request, project_slug):

class BuildList(BuildBase, BuildTriggerMixin, ListView):

def get_queryset(self):
# this is used to include only internal version
# builds in the build list page
self.project_slug = self.kwargs.get('project_slug', None)
self.project = get_object_or_404(
Project.objects.protected(self.request.user),
slug=self.project_slug,
)
queryset = Build.objects.public(
user=self.request.user,
project=self.project,
).select_related('project', 'version')

return queryset

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@
'https://github.com/{user}/{repo}/'
'{action}/{version}{docroot}{path}{source_suffix}'
)
GITHUB_PULL_REQEST_URL = (
'https://github.com/{user}/{repo}/'
'pull/{number}'
)
BITBUCKET_URL = (
'https://bitbucket.org/{user}/{repo}/'
'src/{version}{docroot}{path}{source_suffix}'
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

project = self.get_object()
context['versions'] = Version.objects.public(
context['versions'] = Version.internal.public(
user=self.request.user,
project=project,
)
Expand Down Expand Up @@ -274,7 +274,7 @@ def project_versions(request, project_slug):
slug=project_slug,
)

versions = Version.objects.public(
versions = Version.internal.public(
user=request.user,
project=project,
only_active=False,
Expand Down
11 changes: 9 additions & 2 deletions readthedocs/templates/builds/build_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@

<div class="build-version">
<span class="build-version-slug">
{% if request.user|is_admin:project %}
{% if request.user|is_admin:project and not build.is_external %}
<a href="{% url "project_version_detail" build.version.project.slug build.version.slug %}">{{ build.version.slug }}</a>
{% else %}
{{ build.version.slug }}
{% if build.is_external %}
{% blocktrans with build.external_version_name as external_version_name %}
<b>{{ external_version_name }}</b> #
{% endblocktrans %}
<a href="{{ build.version.get_external_version_url }}">{{ build.version.verbose_name }}</a>
{% else %}
{{ build.version.slug }}
{% endif %}
{% endif %}
</span>
<span class="build-commit"
Copy link
Member

Choose a reason for hiding this comment

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

I'd also love to link the commit as well, using the same pattern.

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/core/build_list_detailed.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div id="build-{{ build.id }}">
<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>
<img src="{% static 'core/img/loader.gif' %}" class="build-loading hide">
<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>
<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>
</a>
</div>
</li>
Expand Down