{% macro repo_renderdiff(diff, diff_commits, pull_request, repo, username, namespace) -%} {% if diff %} {% for patch in diff %} {% if patch |hasattr('new_id') %} {% set patch_new_id = patch.new_id %} {% elif patch |hasattr('delta') %} {% set patch_new_id = patch.delta.new_file.id %} {% else %} {% set patch_new_id = patch.new_oid %} {% endif %} {% if patch |hasattr('old_id') %} {% set patch_old_id = patch.old_id %} {% elif patch |hasattr('delta') %} {% set patch_old_id = patch.delta.old_file.id %} {% else %} {% set patch_old_id = patch.old_oid %} {% endif %} {% if patch | hasattr('new_file_path') %} {% set patch_new_file_path = patch.new_file_path -%} {% if patch.new_file_path != patch.old_file_path %} {% set patch_old_file_path = patch.old_file_path %} {%- endif -%} {%- elif patch | hasattr('delta') -%} {% set patch_new_file_path = patch.delta.new_file.path -%} {%- if patch.delta.new_file.path != patch.delta.old_file.path -%} {% set patch_old_file_path = patch.delta.old_file.path %} {%- endif -%} {%- endif -%}
{% set linesadded = patch.line_stats[1] %} {% set linesremoved = patch.line_stats[2] %} {% macro lineschanged(added, removed) -%}
{%if added%} +{{linesadded}} {%endif%} {%if removed%} -{{linesremoved}} {%endif%}
{%endmacro%} {% macro viewfilelink(filepath, identifier=False)%} {% if pull_request and not pull_request.remote %} {% if not identifier %} {% set identifier = pull_request.branch_from %} {% endif %} {{ filepath | unicode }} {% elif not pull_request %} {{ filepath | unicode }} {% elif pull_request and pull_request.remote %} {{ filepath | unicode }} {% endif %} {% endmacro %} {% macro viewfilelinkbutton(filepath, disabled=False, identifier=False) %} {% if pull_request and not pull_request.remote %} {% if not identifier %} {% set identifier = pull_request.branch_from %} {% endif %} {% elif not pull_request %} {% elif pull_request and pull_request.remote %} {% endif %} {% endmacro %} {% macro changedlabel(thelabel, thecolor)%}
{{thelabel}}
{% endmacro %} {% macro diffcollapsebtn()%} {% endmacro %} {% if patch | hasattr('new_file_path') %} {%- if patch.new_file_path == patch.old_file_path -%} {%- if patch.status == 'D' -%} {% set patchtype = "removed"%}
{{ viewfilelink(patch.new_file_path) }}
{{ changedlabel("file removed", "danger")}} {{ lineschanged(False, True) }} {{ viewfilelinkbutton(patch.new_file_path, disabled=True) }} {{ diffcollapsebtn() }}
{%-elif patch.status == 'A' -%} {% set patchtype = "added"%}
{{ viewfilelink(patch.new_file_path) }}
{{ changedlabel("file added", "success")}} {{ lineschanged(True, False) }} {{ viewfilelinkbutton(patch.new_file_path) }} {{ diffcollapsebtn() }}
{%-elif patch.status == 'M' -%} {% set patchtype = "changed"%}
{{ viewfilelink(patch.new_file_path) }}
{{ changedlabel("file modified", "secondary")}} {{ lineschanged(True, True) }} {{ viewfilelinkbutton(patch.new_file_path) }} {{ diffcollapsebtn() }}
{%-endif-%} {%- else -%} {% set patchtype = "moved"%}
{{ viewfilelink(patch.new_file_path) }}{{patch.old_file_path}}
{{ changedlabel("file renamed", "info")}} {% if linesadded != 0 and linesremoved != 0%} {{ lineschanged(True, True) }} {% endif %} {{ viewfilelinkbutton(patch.new_file_path) }} {{ diffcollapsebtn() }}
{%- endif -%} {%- elif patch | hasattr('delta') -%} {%- if patch.delta.new_file.path == patch.delta.old_file.path -%} {%- if patch.delta.new_file.mode == 0 and patch.delta.old_file.mode in [33188, 33261] -%} {% set patchtype = "removed"%}
{{ viewfilelink(patch.delta.new_file.path) }}
{{ changedlabel("file removed", "danger")}} {{ lineschanged(False, True) }} {{ viewfilelinkbutton(patch.delta.new_file.path, disabled=True) }} {{ diffcollapsebtn() }}
{%-elif patch.delta.new_file.mode in [33188, 33261] and patch.delta.old_file.mode == 0 -%} {% set patchtype = "added"%}
{{ viewfilelink(patch.delta.new_file.path) }}
{{ changedlabel("file added", "success")}} {{ lineschanged(True, False) }} {{ viewfilelinkbutton(patch.delta.new_file.path) }} {{ diffcollapsebtn() }}
{%-elif patch.delta.new_file.mode in [33188, 33261] and patch.delta.old_file.mode in [33188, 33261] -%} {% set patchtype = "changed"%}
{{ viewfilelink(patch.delta.new_file.path) }}
{{ changedlabel("file modified", "secondary")}} {{ lineschanged(True, True) }} {{ viewfilelinkbutton(patch.delta.new_file.path) }} {{ diffcollapsebtn() }}
{%-endif-%} {%- else -%} {% set patchtype = "moved"%}
{{ viewfilelink(patch.delta.new_file.path) }}{{patch.delta.old_file.path}}
{{ changedlabel("file renamed", "info")}} {% if linesadded != 0 and linesremoved != 0%} {{ lineschanged(True, True) }} {% endif %} {{ viewfilelinkbutton(patch.delta.new_file.path) }} {{ diffcollapsebtn() }}
{%- endif -%} {%- endif -%}
{% if patchtype == "moved" and linesadded == 0 and linesremoved == 0%}
file was moved with no change to the file
{% elif patchtype == "added" and linesadded == 0 %}
empty file added
{% else %} {% if patchtype == "added" and linesadded > 1000 %}
The added file is too large to be shown here, see it at: {{ viewfilelink(patch_new_file_path) }}
{% elif patchtype == "removed" and linesadded > 1000 %}
The removed file is too large to be shown here, see it at: {{ viewfilelink(patch_new_file_path, patch_old_id) }}
{% else %}
{% autoescape false %} {{ patch | patch_to_diff | format_loc( filename=patch_new_file_path, commit=patch_new_id, prequest=pull_request, index=loop.index, isprdiff=True, tree_id=diff_commits[0].tree.id)}}
{% endautoescape %} {% endif %} {% endif %}
{% endfor %} {% endif %} {%- endmacro %}