<div class="container">
  <div class='row'>
    <div class='col-lg-12'>
      <ol class='breadcrumb'>
        <li><a href='/packages/<%= @package.prefix %>'><%= @package.prefix %></a></li>
        <li><a href='/packages/<%= @package.prefix %>/<%= @package.name %>'><%= @package.name %></a></li>
        <li class='active'><%= @suite %>/<%= @architecture %></li>
      </ol>

      <h2>
        <%= @package.name %>
        <small>
          [ <%= @suite %>/<%= @architecture %> ]

          <a id='icon-rss'
             href='/data/feeds/<%= @package.prefix %>/<%= @package.name %>.xml'>
          </a>

          <a id='icon-tracker'
             href='https://tracker.debian.org/pkg/<%= @package.name %>'
             title='On the Package Tracking System'>
          </a>
        </small>
      </h2>

      <% if @package.blacklisted? %>
        <div class='alert alert-warning'>
          This package is currently <a href="/status/blacklist/">blacklisted</a> and will not have any new test runs.
        </div>
      <% end %>

      <% if @latest && @latest.status == :fail && @latest.failmsg %>
        <div class='alert alert-warning <%= @latest.extended_status %>'>
          This package is failing and has <%= @latest.failmsg %>.
        </div>
      <% end %>

      <table class="table">
        <tr>
          <td><b>Version</b></td>
          <td><b>Date</b></td>
          <td><b>Duration</b></td>
          <td><b>Status</b></td>
          <td><b>Results</b></td>
          <td></td>
          <td></td>
        </tr>

        <% begin %>
          <% Array(@package.history(@suite, @architecture)).each do |test| %>
            <tr>
              <td><%= test.version %></td>
              <td><%= test.date %></td>
              <td><%= test.duration_human %></td>
              <td class="<%= test.status %>"><%= test.status %></td>
              <% if test.expired? %>
                <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td>
              <% else %>
                <td><a href="/<%= @packages_dir %>/<%= @package_dir %>/<%= test.run_id %>.log">debci log</a></td>
              <% end %>
              <% if @artifacts_url_base %>
                <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= test.run_id %>/log.gz">test log</a></td>
                <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= test.run_id %>/artifacts.tar.gz">artifacts</a></td>
              <% else %>
                <% if test.expired? %>
                  <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td>
                  <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td>
                <% else %>
                  <td><a href="/<%= @autopkgtest_dir %>/<%= @package_dir %>/<%= test.run_id %>/log.gz">test log</a></td>
                  <td><a href="/<%= @autopkgtest_dir %>/<%= @package_dir %>/<%= test.run_id %>/artifacts.tar.gz">artifacts</a></td>
                <% end %>
              <% end %>
            </tr>
          <% end %>
        <% rescue JSON::ParserError %>
          </table>
          <div class='alert alert-warning' role='alert'>
            <span class='fa fa-warning'></span>
            Cannot display test history. There was an error when parsing the history data.
            <a href='/<%= @packages_dir %>/<%= @package_dir %>/history.json'>[ See raw JSON file ]</a>
          </div>
      <% end %>

      </table>

      <p>Automate:</p>

      <% automation_info = "<code># latest status of the package\n" +
                           "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/latest.json\n\n"

         if not @artifacts_url_base
                 automation_info += "# latest autopkgtest log of the package\n" +
                            "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/latest-autopkgtest/log.gz\n\n"
         end

         automation_info += "# test run history of the package\n" +
                            "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/history.json</code>"
      %>

      <pre><%= automation_info %></pre>

    </div>
  </div>
</div>
