{% macro repo_renderdiff(diff, diff_commits, pull_request, repo, username, namespace) -%} {% macro lineschanged(linesadded, linesremoved) -%}
{%if linesadded != 0 %} +{{linesadded}} {%endif%} {%if linesremoved != 0%} -{{linesremoved}} {%endif%}
{%endmacro%} {% macro viewfilelink(filepath, patch_new_id) %} {% if pull_request and not pull_request.remote %} {{ filepath | unicode }} {% elif not pull_request %} {{ filepath | unicode }} {% elif pull_request and pull_request.remote %} {{ filepath | unicode }} {% endif %} {% endmacro %} {% macro viewfilelinkbutton(filepath, patch_new_id, disabled=False) %} {% if pull_request and not pull_request.remote %} {% elif not pull_request %} {% elif pull_request and pull_request.remote %} {% endif %} {% endmacro %} {% macro changedlabel(thelabel, thecolor)%}
{{thelabel}}
{% endmacro %} {% macro diffcollapsebtn(loop)%} {% endmacro %} {% if diff %} {% for patch in diff %} {% set patchstats = (patch | patch_stats) %}
{%- if patchstats["status"] == 'D' -%}
{{ viewfilelink(patchstats["new_path"], patchstats["new_id"]) }}
{{ changedlabel("file removed", "danger")}} {{ lineschanged(patchstats["lines_added"], patchstats["lines_removed"]) }} {{ viewfilelinkbutton(patchstats["new_path"], patchstats["new_id"], disabled=True) }} {{ diffcollapsebtn(loop) }}
{%-elif patchstats["status"] == 'A' -%}
{{ viewfilelink(patchstats["new_path"], patchstats["new_id"]) }}
{{ changedlabel("file added", "success")}} {{ lineschanged(patchstats["lines_added"], patchstats["lines_removed"]) }} {{ viewfilelinkbutton(patchstats["new_path"], patchstats["new_id"]) }} {{ diffcollapsebtn(loop) }}
{%-elif patchstats["status"] == 'M' -%}
{{ viewfilelink(patchstats["new_path"], patchstats["new_id"]) }}
{{ changedlabel("file modified", "secondary")}} {{ lineschanged(patchstats["lines_added"], patchstats["lines_removed"]) }} {{ viewfilelinkbutton(patchstats["new_path"], patchstats["new_id"]) }} {{ diffcollapsebtn(loop) }}
{%- else -%}
{{ viewfilelink(patchstats["new_path"], patchstats["new_id"]) }}{{patchstats["old_path"]}}
{{ changedlabel("file renamed", "info")}} {{ lineschanged(patchstats["lines_added"], patchstats["lines_removed"]) }} {{ viewfilelinkbutton(patchstats["new_path"], patchstats["new_id"]) }} {{ diffcollapsebtn(loop) }}
{%- endif -%}
{% if patchstats["status"] == "R" and patchstats["lines_added"] == 0 and patchstats["lines_removed"] == 0%}
file was moved with no change to the file
{% elif patchstats["status"] == "A" and patchstats["lines_added"] == 0 %}
empty or binary file added
{% else %} {% if patchstats["status"] == "A" and patchstats["lines_added"] > 1000 %}
The added file is too large to be shown here, see it at: {{ viewfilelink(patchstats["new_path"], patchstats["new_id"]) }}
{% elif patchstats["status"] == "D" and patchstats["lines_added"] > 1000 %}
The removed file is too large to be shown here, see it at: {{ viewfilelink(patchstats["new_path"], patchstats["old_id"]) }}
{% else %}
{% autoescape false %} {{ patch | patch_to_diff | format_loc( filename=patchstats["new_path"], commit=patchstats["new_id"], prequest=pull_request, index=loop.index, tree_id=diff_commits[0].tree.id)}}
{% endautoescape %} {% endif %} {% endif %}
{% endfor %} {% endif %} {%- endmacro %}