{% extends "layout.html" %}
{% block sidebar %}{% include "cupboard/sidebar.html" %}{% endblock %}
{% from "codeblock.html" import include_console_log with context %}
{% from "run_util.html" import local_command, merge_command, reschedule_button, schedule_control_button, publish_buttons, install_commands, display_result_code, result_code_explanation, display_branch_url, display_upstream_branch_url, display_vcs_diffs, display_publish_result, file_bug_button, reprocess_logs_button with context %}
{% from "debian_util.html" import display_lintian_result with context %}
{% block page_title %}Run details - {{ package }}{% endblock %}
{% block body %}
<div class="section" id="{{ run_id }}">
<h1>Run of {{ suite }} for {{ package }}</h1>

<!-- {{ run.result_branches }} -->

<ul class="metadata">
<li>Worker: {% if worker_link %}<a href="{{ worker_link }}">{% endif %}{{ worker_name }}{% if worker_link %}</a>{% endif %}</li>
<li>Package: <a class="reference external" href="..">{{ package }}</a>{% if tracker_url and tracker_url(package) %} (<a href="{{ tracker_url(package) }}">QA Page</a>){% endif %}</li>
{% if vcs_url %}
<li>Branch URL: {{ display_branch_url(vcs_browse, vcs_url, vcswatch_version) }}</li>
{% endif %}
{% if run.result and 'upstream_branch_url' in run.result %}
<li>Upstream Branch URL: {{ display_upstream_branch_url(result) }}</li>
{% endif %}
<li>Start time: {{ format_timestamp(start_time) }}</li>
<li>Duration: {{ format_duration(finish_time - start_time) }}</li>
<li>Success probability: {{ success_probability }} (based on {{ total_previous_runs }} previous runs)</li>
<li>Status: {{ display_result_code(result_code)|safe }}{% if unchanged_run and suite != 'unchanged' %} (<a href="/cupboard/pkg/{{ unchanged_run.package }}/{{ unchanged_run.id }}">run</a> without changes: {{ display_result_code(unchanged_run.result_code)|safe }}){% elif suite != 'unchanged' %} ({{ schedule_control_button(run.id, "schedule control run", id='schedule-control') }}){% endif %}{% if run.resume_from %} (<a href="/cupboard/pkg/{{ run.package }}/{{ run.resume_from }}">base run</a>){% endif %}
</li>
<li>Description: {{ description }}</li>
{% if result_code == 'success' %}
<li>Review Status: {% if is_qa_reviewer %}<select id="review-status" name='review-status' onchange="submit_review(this.value)">
  <option value="unreviewed"{% if run.review_status == 'unreviewed' %} selected="true"{% endif %}>Unreviewed</option>
  <option value="approved"{% if run.review_status == 'approved' %} selected="true"{% endif %}>Approved</option>
  <option value="abstained"{% if run.review_status == 'abstained' %} selected="true"{% endif %}>Abstained</option>
  <option value="rejected"{% if run.review_status == 'rejected' %} selected="true"{% endif %}>Rejected</option>
</select>
<script>
function submit_review(status) {
  var comment = undefined;
  if (status == 'rejected') {
      comment = window.prompt('Please specify a comment for the rejection');
  }
  console.log("Submitting review " + status + " for run {{ run_id }} ");
  $.post('/api/run/{{ run_id }}', {'review-status': status, 'review-comment': comment});
}
</script>{% else %}{{ run.review_status }}{% endif %}
{% if run.review_comment %}(<i>{{ run.review_comment }}</i>){% endif %}
</li>
{% endif %}
{% if queue_position %}
<li class='queue-position.{{ package }}'><a href="/cupboard/queue">Queue</a> position: {{ queue_position }}{% if queue_wait_time %} (a {{ format_duration(queue_wait_time) }} wait){% endif %}</li>
{% else %}
<li class='queue-position.{{ package }}' style='display:none'/>
{% endif %}

{{ result_code_explanation(result_code, run) }}

{% if suite != 'unchanged' %}
{% set debdiff = show_debdiff() %}
{% else %}
{% set debdiff = '' %}
{% endif %}

{% if revision and suite != 'unchanged' %}
<li>Diff: <a href="/api/run/{{ run_id }}/diff">raw diff</a>,
    {% if debdiff %}<a href="/api/run/{{ run_id }}/debdiff?filter_boring=true">raw debdiff</a>{% else %}debdiff is not available{% endif %},
    {% if debdiff %}<a href="/api/run/{{ run_id }}/diffoscope?filter_boring=true">diffoscope</a> (<a href="/api/run/{{ run_id }}/diffoscope">unfiltered</a>){% else %}diffoscope diff is not available{% endif %}
</li>
{% endif %}
<li style="display: none">Command: {{ command }}</li>
<li style="display: none">Build Version: {{ run.build_version }}</li>
</ul>

{{ local_command(command, None, package, vcs_type, vcs_url) }}

{% if branch_url %}
{{ reschedule_button(suite, package, "Reschedule") }}
{{ reschedule_button(suite, package, "Reschedule (from scratch)", data={'refresh': '1'}, id='reschedule-refresh') }}
{% if run.result_branches %}
{{ publish_buttons(suite, package) }}
{% endif %}
{% endif %}
{{ reprocess_logs_button(run_id) }}
{{ file_bug_button(run_id, result_code, verbatim_id="#log") }}

{% if run.result_branches %}
{%  if suite != 'unchanged' %}
{{ merge_command(package, suite, run.result_branches, vcs) }}
{%  endif %}
{% else %}
{%  if result_code not in ('nothing-to-do', 'nothing-new-to-do', 'missing-control-file', 'unparseable-changelog', 'inconsistent-source-format', 'upstream-branch-unknown', 'requires-nested-tree-support', 'upstream-unsupported-vcs-svn', 'control-files-in-root', 'success') %}
{%   if primary_log == 'build' %}
{%    with f = get_log(build_log_name) %}
{{     include_console_log(f, build_log_include_lines or (max(1, build_log_line_count), None), build_log_highlight_lines, id="log") }}
{%    endwith %}
{%   elif primary_log == 'dist' %}
{%    with f = get_log(dist_log_name) %}
{{     include_console_log(f, dist_log_include_lines or (max(1, dist_log_line_count), None), dist_log_highlight_lines, id="log") }}
{%    endwith %}
{%   elif primary_log == 'worker' %}
{%    with f = get_log(worker_log_name) %}
{{     include_console_log(f, id="log") }}
{%    endwith %}
{%   else %}
<!-- No logs to display :( -->
{%   endif %}
{%  endif %}
{% endif %}

{% if result %}
<h3>Summary</h3>
{% include [suite + "/summary.html", "generic/summary.html"] %}
{% endif %}

{% if revision and result_code in ('success', 'nothing-to-do') and suite != 'unchanged' %}
{{ display_vcs_diffs(show_diff, run.result_branches, run.result_tags) }}
{% endif %}

{% if debdiff %}
<h3>Debdiff</h3>

{% if debdiff.split('\n')|length < 200 %}

{{ debdiff|safe }}

{% else %}
<p>Debdiff is too long (more than 200 lines). Download the <a href="/api/run/{{ run_id }}/debdiff?filter_boring=1">raw debdiff</a>.</p>
{% endif %}

{% endif %}

{% if publish_history %}
<h2>Publish History</h2>

<ul>
{% for pmode, mp_url, pdesc, pcode, requestor, timestamp in publish_history[:10] %}
<li>{{ format_timestamp(timestamp) }}: {{ display_publish_result(pmode, pcode, pdesc, mp_url) }}{% if requestor and not requestor.startswith('publisher') %} (requested by {{ requestor }}){% endif %}</li>
{% endfor %}
</ul>

{% endif %}

{% if binary_packages %}
<h2>Resulting package</h2>

{{ install_commands(binary_packages, build_distribution) }}

{% endif %}

{% if lintian_result %}
<h2>Lintian Result</h2>

{{ display_lintian_result(lintian_result) }}

{% endif %}

{% if reviews %}
<h2>Reviews</h2>

<table class="reviews">
   <thead><tr><th>Reviewer</th><th>Verdict</th><th>Comment</th></tr></thead>

   {% for review in reviews %}
   <tr><td>{{ review['reviewer'] }}</td><td><span class="review-{{ review['review_status'] }}">{{ review['review_status'] }}</span></td><td>{{ review['review_comment'] }}</td></tr>
   {% endfor %}
</table>

{% endif %}

<p>{% if worker_log_name %}<a class="reference external" href="{{ worker_log_name }}">Full worker log</a>{% endif %}{% if build_log_name %} <a class="reference external" href="{{ build_log_name }}">Full build log</a>{% if earlier_build_log_names %} ({% for i, name in earlier_build_log_names %}<a href="{{ name }}">{{ i }}{% if not loop.last %}, {% endif %}</a>{% endfor %}){% endif %} {% endif %}{% if dist_log_name %} <a class="reference external" href="{{ dist_log_name }}">Full dist log</a>{% endif %}</p>

</div>
{% endblock %}
