From fd882af91c58f325ea8b7723eff9584f487fa26a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2017 16:48:50 +0000 Subject: [PATCH 1/4] Import the commit.html and commits.html templates from pagure These are the templates as of 3.8 vanilla. Signed-off-by: Pierre-Yves Chibon --- diff --git a/template/commit.html b/template/commit.html new file mode 100644 index 0000000..b52b680 --- /dev/null +++ b/template/commit.html @@ -0,0 +1,226 @@ +{% extends "repo_master.html" %} + +{% block title %}Commit - {{ + repo.namespace + '/' if repo.namespace }}{{ repo.name }} - {{ commitid }}{% endblock %} +{% set tag = "commit"%} + +{% block repo %} + +{% set splitted_message = commit.message.split('\n') %} +
+

+ Commit {{ commitid|short }} + {{ splitted_message[0] }} +
+ raw + patch + tree + {% if commit.parents|length == 1 %} + parent + {% elif commit.parents|length > 1 %} +
+ + +
+ {% endif%} +
+

+
+ {% if commit.author| author2user == commit.committer| author2user %} + {{ diff|count}} file{{'s' if diff|count > 1 }} + {% if commit.parents | length == 1 %} + Authored and Committed by {{ commit.author | author2user |safe }} + {% else %} + Merged and Committed by {{ commit.author | author2user |safe }} + {% endif %} + + {{ commit.commit_time | humanize }} + + {% else %} + {{ diff|count}} file{{'s' if diff|count > 1 }} + {% if commit.parents | length == 1 %} + Authored by {{ commit.author | author2user |safe }} + {% else %} + Merged by {{ commit.author | author2user |safe }} + {% endif %} + + {{ commit.commit_time | humanize }} + , + Committed by {{ commit.committer | author2user |safe }} + + {{ commit.commit_time | humanize }} + , + {% endif%} +
+
+ + + +
+ {% if splitted_message|length > 1 %} +
+        {% for message in splitted_message %}
+{{ message }}
+        {% endfor %}
+    
+ {% endif %} +
+ +{% set filecount = 0 %} +{% for patch in diff %} + {% set filecount = filecount + 1 %} +
+
+ {% if patch | hasattr('new_file_path') %} + + {{ patch.new_file_path | unicode }} + + {% elif patch | hasattr('delta') %} + + {{ patch.delta.new_file.path | unicode }} + + {% endif %} + {% if not patch.is_binary %} + {% if patch | hasattr('additions') %} + {% if (patch.additions + patch.deletions) %} + + {% if patch.additions > 0 %}+{{ patch.additions }} {% endif %} + {% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %} + + {% endif %} + {% else %} + {% if (patch.line_stats[1] + patch.line_stats[2]) %} + + {% if patch.line_stats[1] > 0 %}+{{ patch.line_stats[1] }} {% endif %} + {% if patch.line_stats[2] > 0 %}-{{ patch.line_stats[2] }}{% endif %} + + {% endif %} + {% endif %} + {% endif %} +
+ + {% if patch.is_binary %} +

Binary diffs cannot be rendered.

+ {% else %} + {% autoescape false %} + {{ patch|patch_to_diff|html_diff}} + {% endautoescape %} + {% endif %} +
+ +{% endfor %} + +{% endblock %} + + + +{% block jscripts %} + {{ super() }} + +{% endblock %} diff --git a/template/commits.html b/template/commits.html new file mode 100644 index 0000000..92a37dc --- /dev/null +++ b/template/commits.html @@ -0,0 +1,181 @@ +{% extends "repo_master.html" %} + +{% from "_render_repo.html" import pagination_link %} + +{% block title %}{{ select.capitalize() }} - {{ + repo.namespace + '/' if repo.namespace }}{{ repo.name }}{% endblock %} +{% set tag = "home" %} + +{% block repo %} +
+ {% if g.repo_obj and g.repo_obj.is_empty %} +
+ +
+ {% else %} +
+

+ Commits {{number_of_commits}} +

+
+ +
+
+
+ {% if repo.is_fork %} + + {{ repo.user.user }}/{{ repo.name }} + {% else %} + {{ repo.name }} + {% endif %} + +
+ {% if branchname %} +
+ + +
+ {% endif %} +
+
+
+ + {% if diff_commits|count > 0 and head %} + + {% endif %} + +
+ {% for commit in last_commits %} +
+ {% if diff_commits and commit.oid.hex in diff_commits %} +
+ +
+ {% endif %} +
+ + {{ commit.message.split('\n')[0] }} +
+ + {{ commit.commit_time|humanize }} + +
+
+
+ {{commit.author|author2user_commits( + link=url_for('view_commits', + repo=repo.name, + branchname=branchname, + username=username, + namespace=repo.namespace, + author=commit.author.email), + cssclass="notblue")|safe}} +
+ {{ commit.hex|short }} +
+
+ {% endfor %} +
+ + {{ pagination_link('page', g.page, total_page) }} + + {% endif %} + +{% endblock %} + +{% block jscripts %} +{{ super() }} + +{% endblock %} From 664f660bf2bb3fd0942f98159e22ef2af7feb2ab Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2017 16:49:28 +0000 Subject: [PATCH 2/4] Customize the commit.html template to show Atomic CI status With simple change, we now show a small banner with the results of this commit in the Atomic CI pipeline. Signed-off-by: Pierre-Yves Chibon --- diff --git a/template/commit.html b/template/commit.html index b52b680..4b6702e 100644 --- a/template/commit.html +++ b/template/commit.html @@ -83,6 +83,7 @@ {% endif%} +
'); } }); + {% if config.get('RESULTSDB_URL') %} + var _base_url = '{{ config.get("RESULTSDB_URL").rstrip("/") }}/api/v2.0/'; + var _url = _base_url + + "results/latest?rev=" + '{{ commitid }}' + + "&repo=" + '{{ repo.name }}' + + "&namespace=" + '{{ repo.namespace }}' + + "&testcases=org.centos.prod.ci.pipeline.complete"; + $.ajax({ + url: _url , + type: 'GET', + dataType: 'jsonp', + success: function(res) { + var el = $('#msg_banner'); + ref_url = res.data[0]['ref_url']; + status = res.data[0]['outcome']; + var _lbl = 'label-danger'; + if (status == 'PASSED') { + _lbl = 'label-success'; + } + var html = ' \ + '; + el.html(html); + } + }); + {% endif %} {% endblock %} From 1b7b68745569e903de7851b35f73d88795c1ff4a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2017 16:50:55 +0000 Subject: [PATCH 3/4] Customize the commits.html template to show Atomic CI status With simple change, we now show a small banner with the results of each commit when it ran in the Atomic CI pipeline Signed-off-by: Pierre-Yves Chibon --- diff --git a/template/commits.html b/template/commits.html index 92a37dc..e01267d 100644 --- a/template/commits.html +++ b/template/commits.html @@ -6,6 +6,16 @@ repo.namespace + '/' if repo.namespace }}{{ repo.name }}{% endblock %} {% set tag = "home" %} +{% block header %} + {{ super() }} + +{% endblock %} + {% block repo %}
{% if g.repo_obj and g.repo_obj.is_empty %} @@ -157,7 +167,9 @@ author=commit.author.email), cssclass="notblue")|safe}}
- {{ commit.hex|short }} + + {{ commit.hex|short }} +
{% endfor %} @@ -177,5 +189,37 @@ $('#diff_commits').toggle(); }); }); + {% if config.get('RESULTSDB_URL') %} + var _base_url = '{{ config.get("RESULTSDB_URL").rstrip("/") }}/api/v2.0/'; + var _url = _base_url + + "results/latest?repo=" + '{{ repo.name }}' + + "&namespace=" + '{{ repo.namespace }}' + + "&testcases=org.centos.prod.ci.pipeline.complete"; + var listItems = $(".commithash"); + listItems.each(function(idx, li) { + var _id = $(li).attr('id'); + var _h = _id.substring(2) + $.ajax({ + url: _url + '&rev=' + _h, + type: 'GET', + dataType: 'jsonp', + success: function(res) { + var el = $(li); + ref_url = res.data[0]['ref_url']; + status = res.data[0]['outcome']; + var _lbl = 'red'; + if (status == 'PASSED') { + _lbl = '#06ea10'; + } + var html = '\ + \ + '; + el.after(html); + } + }); + }); + {% endif %} {% endblock %} From d4619eb080c498fdc3758972add8ad4f6a552972 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 04 2017 08:47:40 +0000 Subject: [PATCH 4/4] Adjust code style in the commits and commit templates Signed-off-by: Pierre-Yves Chibon --- diff --git a/template/commit.html b/template/commit.html index 4b6702e..76119bb 100644 --- a/template/commit.html +++ b/template/commit.html @@ -2,15 +2,15 @@ {% block title %}Commit - {{ repo.namespace + '/' if repo.namespace }}{{ repo.name }} - {{ commitid }}{% endblock %} -{% set tag = "commit"%} +{% set tag = "commit" %} {% block repo %} -{% set splitted_message = commit.message.split('\n') %} +{% set split_message = commit.message.split('\n') %}

Commit {{ commitid|short }} - {{ splitted_message[0] }} + {{ split_message[0] }}
tree - {% if commit.parents|length == 1 %} + {% if (commit.parents|length) == 1 %} parent - {% elif commit.parents|length > 1 %} + {% elif (commit.parents|length) > 1 %}
- {% endif%} + {% endif %}

- {% if commit.author| author2user == commit.committer| author2user %} - {{ diff|count}} file{{'s' if diff|count > 1 }} - {% if commit.parents | length == 1 %} - Authored and Committed by {{ commit.author | author2user |safe }} + {% if (commit.author|author2user) == (commit.committer|author2user) %} + {{ diff|count }} file{{'s' if (diff|count) > 1 }} + {% if (commit.parents|length) == 1 %} + Authored and Committed by {{ commit.author|author2user|safe }} {% else %} - Merged and Committed by {{ commit.author | author2user |safe }} + Merged and Committed by {{ commit.author|author2user|safe }} {% endif %} - - {{ commit.commit_time | humanize }} + + {{ commit.commit_time|humanize }} {% else %} - {{ diff|count}} file{{'s' if diff|count > 1 }} - {% if commit.parents | length == 1 %} - Authored by {{ commit.author | author2user |safe }} + {{ diff|count }} file{{'s' if (diff|count) > 1 }} + {% if (commit.parents|length) == 1 %} + Authored by {{ commit.author|author2user|safe }} {% else %} - Merged by {{ commit.author | author2user |safe }} + Merged by {{ commit.author|author2user|safe }} {% endif %} - - {{ commit.commit_time | humanize }} + + {{ commit.commit_time|humanize }} , - Committed by {{ commit.committer | author2user |safe }} - - {{ commit.commit_time | humanize }} + Committed by {{ commit.committer|author2user|safe }} + + {{ commit.commit_time|humanize }} , - {% endif%} + {% endif %}
@@ -89,16 +89,16 @@ {% set filecount = 0 %} {% for patch in diff %} {% set filecount = filecount + 1 %} - {% if patch | hasattr('new_file_path') %} + {% if patch|hasattr('new_file_path') %} - {{ patch.new_file_path | unicode}} - {% elif patch | hasattr('delta') %} + {{ patch.new_file_path|unicode}} + {% elif patch|hasattr('delta') %} - {{ patch.delta.new_file.path | unicode }} + {{ patch.delta.new_file.path|unicode }} {% endif %}
{% if not patch.is_binary %} - {% if patch | hasattr('additions') %} + {% if patch|hasattr('additions') %} {% if (patch.additions + patch.deletions) %} {% if patch.additions > 0 %}+{{ patch.additions }}{% endif %} @@ -115,15 +115,15 @@ {% endif %} {% endif %}
- {{ patch.new_file_path | unicode }} + {{ patch.new_file_path|unicode }}
{% endfor %}
- {% if splitted_message|length > 1 %} + {% if split_message|length > 1 %}
-        {% for message in splitted_message %}
+        {% for message in split_message %}
 {{ message }}
         {% endfor %}
     
@@ -135,23 +135,23 @@ {% set filecount = filecount + 1 %}
- {% if patch | hasattr('new_file_path') %} + {% if patch|hasattr('new_file_path') %} - {{ patch.new_file_path | unicode }} + {{ patch.new_file_path|unicode }} - {% elif patch | hasattr('delta') %} + {% elif patch|hasattr('delta') %} - {{ patch.delta.new_file.path | unicode }} + {{ patch.delta.new_file.path|unicode }} {% endif %} {% if not patch.is_binary %} - {% if patch | hasattr('additions') %} + {% if patch|hasattr('additions') %} {% if (patch.additions + patch.deletions) %} {% if patch.additions > 0 %}+{{ patch.additions }} {% endif %} @@ -242,13 +242,11 @@ if (status == 'PASSED') { _lbl = 'label-success'; } - var html = ' \ - '; + var html = ''; el.html(html); } }); diff --git a/template/commits.html b/template/commits.html index e01267d..83aae2a 100644 --- a/template/commits.html +++ b/template/commits.html @@ -67,7 +67,7 @@
- {% if diff_commits|count > 0 and head %} + {% if (diff_commits|count) > 0 and head %} - {{ diff_commit_full.author | author2avatar(20) | safe }} + {{ diff_commit_full.author|author2avatar(20)|safe }} {{ diff_commit_full.author.name }}
@@ -158,16 +158,16 @@
- {{commit.author|author2user_commits( + {{ commit.author|author2user_commits( link=url_for('view_commits', repo=repo.name, branchname=branchname, username=username, namespace=repo.namespace, author=commit.author.email), - cssclass="notblue")|safe}} + cssclass="notblue")|safe }}
- + {{ commit.hex|short }}
@@ -211,11 +211,10 @@ if (status == 'PASSED') { _lbl = '#06ea10'; } - var html = '\ - \ - '; + var html = '' + + ''; el.after(html); } });