{% extends "base.html" %}
{% block title %}#{{ pull_request.number }} {{ pull_request.title }} · {{ owner }}/{{ repository }} · tit{% endblock %}
{% block content %}
  <header class="repository-header">
    <h1><a href="/{{ owner }}/{{ repository }}">{{ owner }}/{{ repository }}</a></h1>
    <nav aria-label="Repository">
      <a href="/{{ owner }}/{{ repository }}">Summary</a>
      <a href="/{{ owner }}/{{ repository }}/refs">Refs</a>
      <a href="/{{ owner }}/{{ repository }}/issues">Issues</a>
      <a href="/{{ owner }}/{{ repository }}/pulls">Pull requests</a>
      <a href="/{{ owner }}/{{ repository }}/watch">Watch</a>
    </nav>
  </header>

  <article>
    <h2>#{{ pull_request.number }} {{ pull_request.title }}</h2>
    <p>{{ pull_request.state }} · opened by {{ pull_request.author }} at <time>{{ pull_request.created_at }}</time> · updated <time>{{ pull_request.updated_at }}</time></p>
    <p>Base: <code>{{ pull_request.base_ref }}</code> at <code>{{ pull_request.base_object_id }}</code></p>
    <p>Head: <code>{{ pull_request.head_ref }}</code> at <code>{{ pull_request.head_object_id }}</code></p>
    <p>Fetch: <code>git fetch origin refs/pull/{{ pull_request.number }}/head</code></p>
    <div class="markdown">{{ body_html|safe }}</div>
  </article>

  <section aria-labelledby="revisions-heading">
    <h2 id="revisions-heading">Revisions</h2>
    <ol>
{% for revision in revisions %}
      <li value="{{ revision.number }}">
        {{ revision.author }} recorded <code>{{ revision.head_object_id }}</code> against <code>{{ revision.base_object_id }}</code> at <time>{{ revision.created_at }}</time>.
{% if revision.number == selected_revision %}
        <strong>Selected</strong>
{% else %}
        <a href="/{{ owner }}/{{ repository }}/pulls/{{ pull_request.number }}?revision={{ revision.number }}">Compare this revision</a>
{% endif %}
      </li>
{% endfor %}
    </ol>
  </section>

  <section aria-labelledby="comparison-heading">
    <h2 id="comparison-heading">Comparison for revision {{ selected_revision }}</h2>
    <p>Merge base: <code>{{ comparison.merge_base }}</code></p>
    <p>Mergeability: {{ comparison.mergeability }}</p>

    <h3>Commits</h3>
{% if comparison.commits.is_empty() %}
    <p>This revision has no commits that are not in the base.</p>
{% else %}
    <ol>
{% for commit in comparison.commits %}
      <li><code>{{ commit.id }}</code> <span class="preserve-whitespace">{{ commit.message }}</span></li>
{% endfor %}
    </ol>
{% endif %}

    <h3>Changed paths</h3>
{% if comparison.changed_paths.is_empty() %}
    <p>This revision does not change a path.</p>
{% else %}
    <ul>
{% for path in comparison.changed_paths %}
      <li><code>{{ path }}</code></li>
{% endfor %}
    </ul>
{% endif %}

    <h3>Diff</h3>
{% for file in comparison.files %}
    <article>
      <h4><code>{{ file.path }}</code></h4>
{% if file.binary %}
      <p>This file has binary content.</p>
{% else %}
      <pre>{{ file.hunks }}</pre>
{% endif %}
    </article>
{% endfor %}
  </section>

{% if can_revise %}
  <form method="post" action="/{{ owner }}/{{ repository }}/pulls/{{ pull_request.number }}/revisions">
    <input type="hidden" name="csrf" value="{{ csrf }}">
    <button type="submit">Record current branch heads</button>
  </form>
{% endif %}
{% endblock %}
