Blob Blame Raw
{% extends "repo_master.html" %}
{% from "_formhelper.html" import render_field_in_row, show_comment %}

{% block title %}
  {%- if pull_request -%}
    PR#{{ requestid }}: {{ pull_request.title }} - {{ repo.name }}
  {%- else -%}
    Diff from {{ branch_from }} to {{ branch_to }} - {{ repo.name }}
  {%- endif -%}
{% endblock %}

{%block tag %}home{% endblock %}

{% block header %}
<link href="{{ url_for('static', filename='fontawesome/font-awesome.min.css') }}"
  rel="stylesheet" />
<link href="{{ url_for('static', filename='emoji/emojione.sprites.css') }}"
  rel="stylesheet" />
{% endblock %}

{% block repo %}


{% if pull_request %}
<h2>Pull Request: {{ pull_request.title | noJS(ignore="img") | safe
  }}{% if authenticated and (g.fas_user.username == pull_request.user.username
    or repo_admin) and pull_request.status == 'Open'
  %}<a class="edit_icon"
    href="{{ url_for('request_pull_edit', username=username,
            repo=repo.name, requestid=requestid) }}" title="Update title"></a>{%
  endif %}</h2>

<div class="header">
    <ul class="buttons">
  {% if pull_request.status == 'Open' and repo_admin %}
      <li>
        <form action="{{ url_for('merge_request_pull', username=username,
            repo=repo.name, requestid=requestid) }}" method="POST">
          {{ mergeform.csrf_token }}
          <input class="button" type="submit" value="Merge"/>
        </form>
      </li>
  {% endif %}
  {% if pull_request.status == 'Open' and authenticated and
        (repo_admin or g.fas_user.username == pull_request.user.username) %}
      <li>
        <form action="{{ url_for('cancel_request_pull', username=username,
            repo=repo.name, requestid=requestid) }}" method="POST">
          {{ mergeform.csrf_token }}
          <input type="submit" value="Close" id="cancel_pr" class="button"/>
        </form>
      </li>
  {% endif %}
  {% if pull_request.status != 'Open' %}
    <li>
      <span class="error">{{ pull_request.status }} by
        <a href="{{ url_for('view_user', username=pull_request.closed_by.user)}} ">
          {{ pull_request.closed_by.user if pull_request.closed_by else ''}}
        </a>
      </span>
    </li>
  {% endif %}
      <li>
        <a class="button patch" href="{{ url_for('request_pull_patch', username=username,
            repo=repo.name, requestid=requestid) }}">Patch</a>
      </li>
    </ul>
</div>
{% else %}
<h2>Diff
      (<a href="{{ url_for('view_tree', username=username,
               repo=repo.name, identifier=commitid) }}"
      >tree</a>)</h2>
{% endif %}

{% if form and repo_admin %}
<section class="new_project">
  {% if remote_git %}
  <form action="{{ url_for('.new_remote_request_pull', username=username,
    repo=repo.name, confirm=True) }}" method="post">
    <input type="hidden" value="{{ branch_from }}" name="branch_from" />
    <input type="hidden" value="{{ remote_git }}" name="git_repo" />
  {% else %}
  <form action="{{ url_for('.new_request_pull', username=username,
    repo=repo.name, commitid=commitid, branch_from=branch_from,
    branch_to=branch_to) }}" method="post">
  {% endif %}
    <table>
      {{ render_field_in_row(form.title, size=80) }}
      <tr>
        <td>From branch:</td>
        <td>{{ branch_from }}</td>
      </tr>
      {% if remote_git %}
      <tr>
          <td>Git repo:</td>
          <td>{{ remote_git }}</td>
      </tr>
      {% endif %}
      <tr>
        <td>To branch:</td>
        <td>
          <select id="branch_select" name="branch_to">
              <option>{{ branch_to }}</option>
            {% for branch in branches |reverse %}
              {% if branch != branch_to %}
              <option>{{ branch }}</option>
              {% endif %}
            {% endfor %}
          </select>
        </td>
      </tr>
    </table>
    <p class="buttons indent">
      <input type="submit" class="submit positive button" value="Create">
      {{ form.csrf_token }}
      <a href="{{ url_for('view_repo', username=username, repo=repo.name)}}">
        <input type="button" value="Cancel" />
      </a>
    </p>
  </form>
</section>
{% endif %}

{% if pull_request %}
<section class="pr_info">
  <table>
    <tr>
      <th>By</th>
      <td>
        <a href="{{ url_for('view_user', username=pull_request.user.user) }}">
        {{ pull_request.user.user | avatar(16) | safe }}
        {{ pull_request.user.fullname }} ({{ pull_request.user.user }})
      </a>
      </td>
    </tr>
    <tr>
      <th>From</th>
      <td>
        <a href="{{ url_for('view_repo_branch',
          username=pull_request.project_from.user.user
            if pull_request.project_from.is_fork else None,
          repo=pull_request.project_from.name,
          branchname=pull_request.branch_from)
        }}">
          {{ pull_request.project_from.fullname or pull_request.remote_git
            }} ({{ pull_request.branch_from }})
        </a>
      </td>
    </tr>
    <tr>
      <th>To</th>
      <td>
        <a href="{{ url_for('view_repo_branch',
          username=pull_request.project.user.user
            if pull_request.project.is_fork else None,
          repo=pull_request.project.name,
          branchname=pull_request.branch)
        }}">
          {{ pull_request.project.fullname }} ({{ pull_request.branch }})
        </a>
      </td>
    </tr>
    <tr>
      <th>Created</th>
      <td title="{{ pull_request.date_created.strftime('%b %d %Y %H:%M:%S') }}">
        {{ pull_request.date_created |humanize }}
      </td>
    </tr>
    <tr>
      <th>Assignee</th>
      <td>
        {% if authenticated and mergeform and pull_request.status == True %}
        <form method="POST" action="{{ url_for('.set_assignee_requests',
            username=username, repo=repo.name, requestid=requestid) }}">
          <input value="{{ pull_request.assignee.username or '' }}"
            name="user" id="assignee" placeholder="username" >
          {{ mergeform.csrf_token }}
          <input type="submit" class="submit positive button" value="Update">
        </form>
        {% else %}
        {{ pull_request.assignee.username or '' }}
        {% endif %}
      </td>
    </tr>
  </table>
</section>

{% if pull_request.flags %}
<section id="pr_flags">
  <table>
    {% for flag in pull_request.flags %}
      <tr style="background-color: {{ flag.percent | toRGB }}">
        <td>{{ flag.percent }}%</td>
        <td><a href="{{ flag.url }}">{{ flag.username }}</a></td>
        <td>{{ flag.comment }}</td>
        <td title="{{ flag.date_created }}" class="right">
          {{ flag.date_created | humanize }}
        </td>
      </tr>
    {% endfor %}
  </table>
</section>
{% endif %}

{% endif %}

<div class="tabs">
  <ul>
    <li><a href="#request_diff">Diff</a></li>
    <li><a href="#commit_list">Commits ({{ diff_commits|length }})</a></li>
  </ul>

<div class="commit_list" id="commit_list">
  <table>
      {% for commit in diff_commits %}
      <tr>
        <td class="commitid">{{ commit.oid.hex|short }}</td>
        <td>
          {% if pull_request and pull_request.status and pull_request.project_from.is_fork %}
          <a href="{{ url_for('view_commit', username=pull_request.project_from.user.user,
                    repo=pull_request.project_from.name, commitid=commit.oid.hex)}}">
          {% elif pull_request and pull_request.remote %}
          <a>
          {% else %}
          <a href="{{ url_for('view_commit', username=username,
                        repo=repo.name, commitid=commit.oid.hex)}}">
          {% endif %}
            {{ commit.message.strip().split('\n')[0] }}
            <div class="commit_msg_txt commit_message_body" id="commit_msg_{{ loop.index }}">
                {{ commit.message.strip().split('\n')[2:] | join('\n') }}
            </div>
          </a>
        </td>
        {% if commit.message.strip().split('\n') | length > 1 %}
        <td class="commit_msg_btn" data-id="{{ loop.index }}">more</td>
        {% else %}
        <td></td>
        {% endif %}
        <td class="commitdate" title="{{ commit.commit_time|format_ts }}">
          {{ commit.commit_time|humanize }}</td>
      </tr>
      {% else %}
      <tr><td class="error"> No commits found </td></tr>
      {% endfor %}
  </table>
</div>

<div class="request_diff" id="request_diff">

{% if authenticated and pull_request %}
<form action="{{ url_for('.pull_request_drop_comment', username=username,
    repo=repo.name, requestid=requestid) }}" method="post" class="icon">
{% endif %}

{% if diff %}
{% for patch in diff %}
<section class="commit_diff">
<header>
    <h3>
        {%- if patch.new_file_path == patch.old_file_path -%}
        {{ patch.new_file_path }}
        {%- else -%}
        {{ patch.new_file_path }} (Renamed from "{{ patch.old_file_path }}")
        {%- endif -%}
    </h3>
    <ul class="buttons">
      <li class="addrem_bar">
      {% if (patch.additions + patch.deletions) %}
        <span style="width: {{ (100.0 * patch.additions / (patch.additions + patch.deletions))|round|int }}%">
          {% if patch.additions > 0 %}+{{ patch.additions }}{% endif %}
          {% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %}
        </span>
      {% endif %}
      </li>
      <li>
        {% if pull_request %}
        <a class="button view" href="{{
            url_for(
                'view_file',
                username=pull_request.project_from.user.username
                    if pull_request.project_from.is_fork else None,
                repo=pull_request.project_from.name,
                identifier=pull_request.branch_from,
                filename=patch.new_file_path) }}"
        {% else %}
        <a class="button view" href="{{
            url_for(
                'view_file',
                username=username,
                repo=repo.name,
                identifier=branch_from,
                filename=patch.new_file_path) }}"
        {% endif %}
        {% if patch |hasattr('new_id') %}
        title="View file as of {{ patch.new_id|short }}">View</a>
        {% else %}
        title="View file as of {{ patch.new_oid|short }}">View</a>
        {% endif %}
      </li>
    </ul>
</header>
{% autoescape false %}
    {{ patch | patch_to_diff | html_diff | format_loc(
            filename=patch.new_file_path,
            commit=patch.new_id or patch.new_oid,
            prequest=pull_request,
            index=loop.index)}}
{% endautoescape %}
</section>
{% endfor %}
{% endif %}

{% if authenticated and pull_request %}
{{ mergeform.csrf_token }}
</form>
{% endif %}

</div>
</div>


{% if pull_request %}
<section class="request_comment" id="request_comment">
{% if pull_request.discussion %}
<form action="{{ url_for('.pull_request_drop_comment', username=username,
    repo=repo.name, requestid=requestid) }}" method="post">

{% for comment in pull_request.discussion %}
  {% if not comment.commit_id %}
    {{ show_comment(comment, comment.id, repo, username,
                    requestid, form, repo_admin) }}
  {% endif %}
{% endfor %}
{{ mergeform.csrf_token }}
</form>
{% endif %}
</section>
{% endif %}

<section class="request_comment add_comment">
{% if authenticated and mergeform and pull_request %}
  <form action="{{ url_for(
      'pull_request_add_comment', username=username, repo=repo.name,
      requestid=requestid) }}"
      method="post" onsubmit="return try_async_comment(this, false)">
    {{ mergeform.csrf_token }}
    <header>
      <label for="comment">Add new comment</label>
      (supports the <a href="http://daringfireball.net/projects/markdown/syntax"
        target="_blank">Markdown syntax</a>)
    </header>
    <div class="tabs" id="comment_block">
      <ul>
        <li><a href="#edit">Comment</a></li>
        <li><a href="#preview">Preview</a></li>
      </ul>
      <div id="edit">
        <div>
          <textarea id="comment" name="comment" placeholder="Enter your comment here"></textarea>
        </div>
      </div>
      <div id="preview">
      </div>
      <div>
        <input type="submit" class="submit positive button" value="Comment">
        <input type="button" value="Clear" id="clear_comment" />
      </div>
    </div>
  </form>
{% elif pull_request %}
  <p><a href="{{ url_for('auth_login', next=request.url) }}">Login</a> to comment.</p>
{% endif %}
</section>


{% endblock %}

{% block jscripts %}
{{ super() }}
<script type="text/javascript"
    src="{{ url_for('static', filename='emoji/jquery.textcomplete.min.js') }}">
</script>
<script type="text/javascript"
    src="{{ url_for('static', filename='emoji/emojione.min.js') }}">
</script>

<script type="text/javascript">

 $(document).ready(function() {

  $( ".commit_msg_txt" ).hide();
  $( ".commit_msg_btn" ).click(function() {
    var msgid = $( this ).attr('data-id');
    $( '#commit_msg_' + msgid).toggle();
  });

  var folder = '{{url_for("static", filename="emoji/png/") }}';
  var json_url = '{{ url_for("static", filename="emoji/emoji_strategy.json") }}';

  $( "#branch_select" ).change(
    function() {
      var sel = $('#branch_select');
      var final_url = "{{ url_for('.new_request_pull', username=username,
        repo=repo.name, branch_from=branch_from,
        branch_to='--') }}";
      final_url = final_url.replace('--', sel.val());
      window.location.href = final_url;
    }
  );

  $( ".tabs" ).tabs({
    activate: function( event, ui ) {
      var _title = ui.newPanel.attr('id');
      if ($.inArray( _title, [ "request_diff", "commit_list" ] ) >= 0) {
        window.location.hash = _title;
      }
    }
  });

{% if pull_request %}
{# These lines are only for existing pull-requests, not new ones #}

  emoji_complete(json_url, folder);

  $('#cancel_pr').click(function(){
    return window.confirm("Are you sure you want to close this requested pull?");
  });

  function comment() {
    $( ".cancel" ).click(
      function() {
        $(this).parent().parent().parent().parent().remove();
      }
    );
  };

  $( ".code_table tr" ).hover(
    function() {
      $( this ).find( "img" ).show().width(13);
    }, function() {
      $( this ).find( "img" ).hide();
    }
  );

  $( ".prc" ).click(
    function() {
      var row = $( this ).attr('data-row');
      var commit = $( this ).attr('data-commit');
      var filename = $( this ).attr('data-filename');
      var url = "{{ url_for(
        'pull_request_add_comment', username=username, repo=repo.name,
        requestid=requestid, commit='', filename='', row='') }}".slice(0, -2);
      url = url + commit + '/' + filename + '/' + row;
      var rowid = $(this).prev().find('a').attr('id');
      var table = $( this ).parent().parent();
      var nextid = rowid.replace('_' + row, '_' + (Number(row) + 1));
      var next_row = table.find('#' + nextid).parent().parent();
      if (next_row.prev().find('.pr_comment_form').length == 0){
        $.get( url , function( data ) {
          next_row.before(
            '<tr><td></td><td colspan="2" class="pr_comment_form">' + data + '</td></tr>' );
          comment();
          emoji_complete(json_url, folder);
        });
      } else {
        next_row.prev().find('.pr_comment_form').parent().remove();
      }
    }
  );

  $( ".tabs" ).on('tabsactivate',
    function(event, ui) {
      if (ui.newPanel.selector == '#preview') {
        var _text = $( "#comment" ).val();
        var _url = "{{ url_for('markdown_preview') }}";
        $.ajax({
            url: _url ,
            type: 'POST',
            data: {
              content: _text,
              csrf_token: "{{ mergeform.csrf_token.current_token }}",
            },
            dataType: 'html',
            success: function(res) {
                $( "#preview" ).html(res);
            },
            error: function() {
                alert('Unable to generate preview!');
            }
        });
        return false;
      }
    }
  );

  $( ".reply" ).click(
    function() {
        var _section = $(this).parent().parent().parent();
        var _comment = _section.find('.comment_body');
        var _text = _comment.text().split("\n");
        var _output = new Array();
        for (cnt = 0; cnt < _text.length - 1; cnt ++) {
            _output[cnt] = '> ' + jQuery.trim(_text[cnt + 1]);
        }
        $( "#comment" ).val(_output.join("\n"));
    }
  );

  var cur_hash = null;

  highlight_comment = function() {
    var _hash = window.location.hash;
    if (_hash != cur_hash) {
      $( cur_hash ).css(
        "background", "linear-gradient(to bottom, #ededed 0%, #fff 100%)"
      );
    };
    cur_hash = _hash;
    if ( _hash ) {
      $( _hash ).css(
        "background", "linear-gradient(to bottom, #eded98 0%, #fff 100%)"
      );
    };
    return false;
  };

  $(window.onload=highlight_comment());
  $(window).on('hashchange', highlight_comment);

  $(".comment_body").each(function(ind, obj) {
    var source = $(obj).html();
    var preview = emojione.toImage(source);
    $(obj).html(preview);
  });
  $(".pr_comment").each(function(ind, obj) {
    var source = $(obj).html();
    var preview = emojione.toImage(source);
    $(obj).html(preview);
  });

  {% if pull_request.status == 'Open' %}
  $(function(){
    $.ajax({
      url: '{{ url_for("internal_ns.mergeable_request_pull") }}' ,
      type: 'POST',
      data: {
        requestid: "{{ pull_request.uid }}",
        csrf_token: "{{ mergeform.csrf_token.current_token }}",
      },
      dataType: 'json',
      success: function(res) {
        var _obj = $('.header .buttons');
        _obj.prepend($('<li><span class="'+res.code+'" title="'
          +res.message+'">'+res.short_code+'</span></li>'));
      },
      error: function() {
        var _obj = $('.header .buttons');
        _obj.prepend($('<li>Could not determine if the PR can be merged</li>'));
      }
    });
    return false;
  });
  {% endif %}

{% endif %}

 });

{% if authenticated and pull_request %}
function try_async_comment(form, inline) {
  if (!sse) {
    $(form).off('submit');
    form.submit();
    return false;
  }
  $.post( form.action + "?js=1", $(form).serialize() )
    .done(function(data) {
      if(data == 'ok') {
        // We have submitted the comment correctly
        $('#comment').val('');
        if (inline){
            $(form).remove();
        }
      } else {
        // Make the browser submit the form sync
        $(form).off('submit');
        form.submit();
      }
    })
    .fail(function() {
      // Make the browser submit the form sync
      $(form).off('submit');
      form.submit();
    })
  return false;
};
{% endif %}

</script>


{% if config['EVENTSOURCE_SOURCE'] and pull_request %}
<script type="text/javascript"
  src="{{ url_for('static', filename='request_ev.js') }}"></script>

<script type="text/javascript">
var source = null;
var sse = true;
if (!!window.EventSource) {
  source = new EventSource('{{ config["EVENTSOURCE_SOURCE"]
    + request.script_root + request.path }}');
  source.addEventListener('error', function(e) {
    sse = false;
  }, false);
}

window.onbeforeunload = function() {
    source.close()
};

source.addEventListener('message', function(e) {
  console.log(e.data);
  var data = $.parseJSON(e.data);
  process_event(data, "{{ request.uid }}");

  }, false);
</script>
{% endif %}

{% endblock %}