<h1>Retry an autopkgtest job</h1>

<noscript>
  <p>
  To retry an autopkgtest job via this page, you need Javascript enabled on your
  browser.
  </p>

  <p>
  Without it, you will need to make a HTTP POST request to this page URL,
  for example using <code>curl</code> or <code>wget</code>, authenticated
  with a valid SSL client certificate or with a valid Debci key (see
  the <a href="/doc/file.API.html">API documentation</a>).
  </p>
</noscript>

<form method="POST">
  <p>
  Once you click the "Retry" button below, an autopkgtest with the same
  settings as the original will be triggered on the infrastructure.
  </p>

  <table class="table">
    <% prefix = @original_job.package.prefix %>
    <tbody>

      <tr>
        <td>Package name:</td>
        <td><a href="/packages/<%= prefix %>/<%= @original_job.package.name %>/"><%= @original_job.package.name %></a></td>
      </tr>
      <tr>
        <td>Suite and Arch:</td>
        <td>
          <a href="<%= '/packages/%s/%s/%s/%s/' % [prefix, @original_job.package.name, @original_job.suite, @original_job.arch] %>">
            <%= @original_job.suite %>/<%= @original_job.arch %>
          </a>
        </td>
      </tr>
      <tr>
        <td>Trigger:</td>
        <td><%= @original_job.trigger.nil? ? '&mdash;' : @original_job.trigger %></td>
      </tr>
      <tr>
        <td>Pinned packages:&nbsp;</td>
        <td>
          <% if @original_job.pin_packages.empty? %>
            &mdash;
          <% else %>
            <% @original_job.pin_packages.each do |package| %>
              <p>
                <% prefix = @original_job.package.prefix %>
                <a href="/packages/<%= prefix %>/<%= package %>/">
                  <%= package %>
                </a>
              </p>
            <% end %>
          <% end %>
        </td>
      </tr>

    </tbody>
  </table>

  <div id='result-info' style='display: none'>
    <p>
      Your request has been successfully submitted.
    </p>
  </div>

  </br>
  <input type='button' value='Retry' onclick='retry(this)' class='btn btn-primary'/>
</form>

<script type='text/javascript'>
  function displayresult() {
    var status = this.status
    if (Math.floor(status/100) == 2) {
      var resinfo = document.getElementById('result-info')
      resinfo.style.display = 'block'
    } else {
      var text = this.statusText
      alert("An error ocurred while requesting a retry: " + status + " " + text)
    }
  }

  function retry(button) {
    var request = new XMLHttpRequest();
    request.addEventListener('load', displayresult)
    request.open("POST", document.location.href)
    request.send()
  }
</script>
<noscript>
  <style type='text/css'>
    form { display: none }
  </style>
</noscript>
