From 1ee5ad17ed97017a7ee312b490749a9df71ce20a Mon Sep 17 00:00:00 2001
From: Ryan Lerch <rlerch@redhat.com>
Date: Apr 11 2016 14:21:06 +0000
Subject: [PATCH 1/6] added and activity feed view for instances using datagrepper


---

diff --git a/pagure/static/pagure.css b/pagure/static/pagure.css
index 2dd7610..5dd5687 100644
--- a/pagure/static/pagure.css
+++ b/pagure/static/pagure.css
@@ -478,3 +478,19 @@ blockquote {
   color: #586e75;
   padding: 1em 1em 0.1em 1em;
 }
+
+.messagetitle{
+  border-top: 1px solid #eee;
+}
+
+.messageitem{
+  padding-left: 2em;
+}
+
+.messageicon{
+float: left;
+font-size: 1.5em;
+padding-right: 0.5em;
+margin-top: -4px;
+color: #999;
+}
diff --git a/pagure/templates/activity.html b/pagure/templates/activity.html
new file mode 100644
index 0000000..c68db22
--- /dev/null
+++ b/pagure/templates/activity.html
@@ -0,0 +1,140 @@
+{% extends "repo_master.html" %}
+
+{% block title %}Activity - {{ repo.name }}{% endblock %}
+{% set tag = "home" %}
+
+
+{% block repo %}
+<div class="list-group" id="messages">
+</div>
+<div class="text-xs-center"><span id="noactivity" style="display:none;">No activity reported on the {{repo.name}} project</span><button class="btn btn-secondary" style="display:none;" id='loadmore'>Load more</button><img id="spinnergif" src="{{ url_for('static', filename='images/spinner.gif') }}"></div>
+{% endblock %}
+
+{% block jscripts %}
+{{ super() }}
+<script>
+function processMessages(item, lastitem) {
+  console.log(item["topic"]);
+  console.log(item);
+  if (item["topic"].indexOf("io.pagure.prod.pagure.pull-request") > -1 ){
+    if (lastitem.valueOf() != new String("PR#"+item["msg"]["pullrequest"]["id"]).valueOf())
+    {
+      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='data-transfer-download'></span></div>New activity on <strong><span class='label label-default'>PR#"+item["msg"]["pullrequest"]["id"]+"</span> "+item["msg"]["pullrequest"]["title"]+"</strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+    }
+    messagedetail = $("<a href="+item["meta"]["link"]+"><div class='messageitem clearfix'><small>"+item["msg"]["agent"]+" <span class='activity-message'> PR#"+item["msg"]["pullrequest"]["id"]+"</span> <span>"+item["meta"]["date"]+"</span></small></div></a>")
+    if (item["topic"]=="io.pagure.prod.pagure.pull-request.new"){
+        $(messagedetail).find(".activity-message").addClass("text-success").prepend("created");
+    } else if (item['topic']=="io.pagure.prod.pagure.pull-request.comment.added") {
+        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("commented on");
+    } else if (item['topic']=="io.pagure.prod.pagure.pull-request.comment.edited") {
+      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited comment on");
+    } else if (item['topic']=="io.pagure.prod.pagure.pull-request.closed") {
+      if (item["msg"]["merged"] == true){
+        $(messagedetail).find(".activity-message").addClass("text-success").prepend("merged");
+      } else if (item["msg"]["merged"] == false){
+        $(messagedetail).find(".activity-message").addClass("text-danger").prepend("closed");
+      }
+    } else {
+      $(messagedetail).html("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+    }
+    $("#messages").append(messagedetail);
+    return "PR#"+item["msg"]["pullrequest"]["id"]
+  } else if (item["topic"].indexOf("io.pagure.prod.pagure.issue") > -1 ){
+    if (lastitem.valueOf() != new String("ISSUE#"+item["msg"]["issue"]["id"]).valueOf())
+    {
+      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='warning'></div></span>New activity on <strong><span class='label label-default'>Issue#"+item["msg"]["issue"]["id"]+"</span> "+item["msg"]["issue"]["title"]+"</strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+    }
+    messagedetail = $("<a href="+item["meta"]["link"]+"><div class='messageitem clearfix'><small>"+item["msg"]["agent"]+" <span class='activity-message'> Issue #"+item["msg"]["issue"]["id"]+" </span> <span>"+item["meta"]["date"]+"</span></small></div></a>")
+    if (item["topic"]=="io.pagure.prod.pagure.issue.new"){
+      $(messagedetail).find(".activity-message").addClass("text-success").prepend("created");
+    } else if (item['topic']=="io.pagure.prod.pagure.issue.edit") {
+      if (item["msg"]["fields"].length == 1){
+        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited the "+item["msg"]["fields"][0]+" field in");
+      } else {
+        var outputstring = "";
+        for (var i in item["msg"]["fields"]){
+          outputstring = outputstring+item["msg"]["fields"][i]
+          if (i < item["msg"]["fields"].length-1){
+          outputstring = outputstring +" & "
+          }
+        }
+        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited the "+outputstring+" fields in");
+      }
+
+    } else if (item['topic']=="io.pagure.prod.pagure.issue.comment.added") {
+      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("commented on");
+    } else if (item['topic']=="io.pagure.prod.pagure.issue.comment.edited") {
+      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited a comment on");
+    } else if (item['topic']=="io.pagure.prod.pagure.issue.assigned.added") {
+      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("assigned ").append(" to "+item["msg"]["issue"]["assignee"]["name"]);
+    } else {
+      $(messagedetail).html("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+    }
+    $("#messages").append(messagedetail);
+    return "ISSUE#"+item["msg"]["issue"]["id"]
+  } else if (item["topic"].indexOf("io.pagure.prod.pagure.project") > -1 ){
+    if (item["topic"]=="io.pagure.prod.pagure.project.forked"){
+      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='fork'></div></span>"+item["msg"]["agent"]+" forked "+item["msg"]["project"]["name"]+" into <a href='"+item["meta"]["link"]+"'>"+item["msg"]["agent"]+"/"+item["msg"]["project"]["name"]+"</a></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+    } else {
+      $("#messages").append("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+    }
+    return "";
+  } else {
+    $("#messages").append("<div style='background-color:pink'>"+item["meta"]["subtitle"]+"</div>");
+    return "";
+  }
+}
+
+$(document).ready(function() {
+  var page = null;
+  pants = $.ajax({
+   type: 'GET',
+  url: "{{ config.get('DATAGREPPER_URL') }}/raw?category={{ config.get('DATAGREPPER_CATEGORY') }}&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle",
+  async: false,
+  contentType: "application/json",
+  dataType: 'jsonp',
+  success:function(data) {
+  if(data) {
+      console.log(data)
+      if (data["count"] == 0){
+        $("#noactivity").show();
+        $("#spinnergif").hide();
+      } else {
+        var last_item = ""
+        for (var i=0; i<data['raw_messages'].length; i++) {
+          last_item = processMessages(data['raw_messages'][i], last_item)
+        }
+        /*data['raw_messages'].forEach(processMessages(lastitem));*/
+        page = 2
+        $("#loadmore").show();
+        $("#spinnergif").hide();
+        $("#loadmore").click(function(){
+          $("#spinnergif").show();
+          $("#loadmore").hide();
+          $.ajax({
+            type: 'GET',
+            url: "{{ config.get('DATAGREPPER_URL') }}/raw?category={{ config.get('DATAGREPPER_CATEGORY') }}&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle&page="+page,
+            async: false,
+            contentType: "application/json",
+            dataType: 'jsonp',
+            success:function(data) {
+              if(data) {
+                page = page+1;
+                console.log(data)
+                var last_item = ""
+                for (var i=0; i<data['raw_messages'].length; i++) {
+                  last_item = processMessages(data['raw_messages'][i], last_item)
+                }
+                $("#loadmore").show();
+                $("#spinnergif").hide();
+              }
+            }
+          });
+        });
+      }
+  }
+}
+});
+});
+</script>
+{% endblock %}
diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py
index fa819d1..6a3eb3a 100644
--- a/pagure/ui/repo.py
+++ b/pagure/ui/repo.py
@@ -1548,3 +1548,20 @@ def view_docs(repo, username=None, filename=None):
         endpoint='view_docs',
         select='docs',
     )
+
+@APP.route('/<repo>/activity/')
+@APP.route('/<repo>/activity')
+def view_project_activity(repo):
+    """ Display the documentation
+    """
+    repo_obj = pagure.lib.get_project(SESSION, repo, user=None)
+
+    if not repo_obj:
+        flask.abort(404, 'Project not found')
+    if not APP.config.get('DATAGREPPER_URL'):
+        flask.abort(404)
+
+    return flask.render_template(
+        'activity.html',
+        repo=repo_obj,
+    )

From 8eb9dde266876802e26194f88f100fbbbf963a85 Mon Sep 17 00:00:00 2001
From: Ryan Lerch <rlerch@redhat.com>
Date: Apr 11 2016 14:21:06 +0000
Subject: [PATCH 2/6] move the config check above the DB call


---

diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py
index 6a3eb3a..af8cf36 100644
--- a/pagure/ui/repo.py
+++ b/pagure/ui/repo.py
@@ -1552,14 +1552,16 @@ def view_docs(repo, username=None, filename=None):
 @APP.route('/<repo>/activity/')
 @APP.route('/<repo>/activity')
 def view_project_activity(repo):
-    """ Display the documentation
+    """ Display the activity feed
     """
+
+    if not APP.config.get('DATAGREPPER_URL'):
+        flask.abort(404)
+
     repo_obj = pagure.lib.get_project(SESSION, repo, user=None)
 
     if not repo_obj:
         flask.abort(404, 'Project not found')
-    if not APP.config.get('DATAGREPPER_URL'):
-        flask.abort(404)
 
     return flask.render_template(
         'activity.html',

From 8b40bac85fa2e897311e8754214ce08dc954a4be Mon Sep 17 00:00:00 2001
From: Ryan Lerch <rlerch@redhat.com>
Date: Apr 11 2016 14:21:06 +0000
Subject: [PATCH 3/6] updated the feed to show git commits too


---

diff --git a/pagure/static/pagure.css b/pagure/static/pagure.css
index 5dd5687..9e4d314 100644
--- a/pagure/static/pagure.css
+++ b/pagure/static/pagure.css
@@ -494,3 +494,8 @@ padding-right: 0.5em;
 margin-top: -4px;
 color: #999;
 }
+.msg-git-hash{
+  font-family:monospace;
+  background-color:#eee;
+  color:#777;
+}
diff --git a/pagure/templates/activity.html b/pagure/templates/activity.html
index c68db22..4113642 100644
--- a/pagure/templates/activity.html
+++ b/pagure/templates/activity.html
@@ -74,7 +74,24 @@ function processMessages(item, lastitem) {
     return "ISSUE#"+item["msg"]["issue"]["id"]
   } else if (item["topic"].indexOf("io.pagure.prod.pagure.project") > -1 ){
     if (item["topic"]=="io.pagure.prod.pagure.project.forked"){
-      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='fork'></div></span>"+item["msg"]["agent"]+" forked "+item["msg"]["project"]["name"]+" into <a href='"+item["meta"]["link"]+"'>"+item["msg"]["agent"]+"/"+item["msg"]["project"]["name"]+"</a></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='fork'></span></div>"+item["msg"]["agent"]+" forked "+item["msg"]["project"]["name"]+" into <a href='"+item["meta"]["link"]+"'>"+item["msg"]["agent"]+"/"+item["msg"]["project"]["name"]+"</a></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+    } else {
+      $("#messages").append("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+    }
+    return "";
+  } else if (item["topic"].indexOf("io.pagure.prod.pagure.git") > -1 ){
+    if (lastitem.valueOf() != new String("GITCOMMIT#"+item["msg"]["commit"]["branch"]).valueOf())
+    {
+      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='spreadsheet'></div></span>New commits to <strong><span class='pr-toplabel'> <span class='oi' data-glyph='random'> </span> "+item['msg']['commit']['branch'].replace("refs/heads/","")+"</span></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+    }
+    if (item["topic"]=="io.pagure.prod.pagure.git.receive"){
+      $("#messages").append("\
+      <a href="+item["meta"]["link"]+">\
+        <div class='messageitem'>\
+          <small>"+item["msg"]["commit"]["name"]+" <span class='activity-message text-muted'> committed </span></small><span class='label label-default msg-git-hash'>"+item["msg"]["commit"]["rev"].substring(0,6)+"</span><small> <span class='text-muted'>"+item["msg"]["commit"]["message"]+"</span> </small>\
+        </div>\
+      </a>");
+      return "GITCOMMIT#"+item["msg"]["commit"]["branch"];
     } else {
       $("#messages").append("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
     }
@@ -89,7 +106,7 @@ $(document).ready(function() {
   var page = null;
   pants = $.ajax({
    type: 'GET',
-  url: "{{ config.get('DATAGREPPER_URL') }}/raw?category={{ config.get('DATAGREPPER_CATEGORY') }}&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle",
+  url: "{{ config.get('DATAGREPPER_URL') }}/raw?delta=2592000&category={{ config.get('DATAGREPPER_CATEGORY') }}&category=git&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle",
   async: false,
   contentType: "application/json",
   dataType: 'jsonp',
@@ -113,7 +130,7 @@ $(document).ready(function() {
           $("#loadmore").hide();
           $.ajax({
             type: 'GET',
-            url: "{{ config.get('DATAGREPPER_URL') }}/raw?category={{ config.get('DATAGREPPER_CATEGORY') }}&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle&page="+page,
+            url: "{{ config.get('DATAGREPPER_URL') }}/raw?delta=2592000&category={{ config.get('DATAGREPPER_CATEGORY') }}&category=git&contains=%22name%22:%22{{repo.name}}%22&meta=link&meta=date&meta=subtitle&page="+page,
             async: false,
             contentType: "application/json",
             dataType: 'jsonp',

From 6f83abc9c05298c4b14f5f55671218dc54e2973f Mon Sep 17 00:00:00 2001
From: Ryan Lerch <rlerch@redhat.com>
Date: Apr 11 2016 14:21:06 +0000
Subject: [PATCH 4/6] cleaned up code, removed long lines


---

diff --git a/pagure/templates/activity.html b/pagure/templates/activity.html
index 4113642..cefb2bd 100644
--- a/pagure/templates/activity.html
+++ b/pagure/templates/activity.html
@@ -7,49 +7,115 @@
 {% block repo %}
 <div class="list-group" id="messages">
 </div>
-<div class="text-xs-center"><span id="noactivity" style="display:none;">No activity reported on the {{repo.name}} project</span><button class="btn btn-secondary" style="display:none;" id='loadmore'>Load more</button><img id="spinnergif" src="{{ url_for('static', filename='images/spinner.gif') }}"></div>
+<div class="text-xs-center">
+  <span id="noactivity" style="display:none;">
+    No activity reported on the {{repo.name}} project
+  </span>
+  <button class="btn btn-secondary" style="display:none;" id='loadmore'>
+    Load more
+  </button>
+  <img id="spinnergif" src="{{ url_for('static', filename='images/spinner.gif') }}">
+</div>
 {% endblock %}
 
 {% block jscripts %}
 {{ super() }}
 <script>
 function processMessages(item, lastitem) {
-  console.log(item["topic"]);
-  console.log(item);
   if (item["topic"].indexOf("io.pagure.prod.pagure.pull-request") > -1 ){
     if (lastitem.valueOf() != new String("PR#"+item["msg"]["pullrequest"]["id"]).valueOf())
     {
-      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='data-transfer-download'></span></div>New activity on <strong><span class='label label-default'>PR#"+item["msg"]["pullrequest"]["id"]+"</span> "+item["msg"]["pullrequest"]["title"]+"</strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+      $("#messages").append("\
+      <div class='messagetitle m-t-2 p-t-2'>\
+        <div class='messageicon'>\
+          <span class='oi' data-glyph='data-transfer-download'></span>\
+        </div>\
+        New activity on\
+          <strong>\
+            <span class='label label-default'>\
+              PR#"+item["msg"]["pullrequest"]["id"]+"\
+            </span>\
+            "+item["msg"]["pullrequest"]["title"]+"\
+          </strong>\
+        <div class='pull-xs-right'>"+item["meta"]["date"]+"</div>\
+      </div>");
     }
-    messagedetail = $("<a href="+item["meta"]["link"]+"><div class='messageitem clearfix'><small>"+item["msg"]["agent"]+" <span class='activity-message'> PR#"+item["msg"]["pullrequest"]["id"]+"</span> <span>"+item["meta"]["date"]+"</span></small></div></a>")
+    messagedetail = $("\
+    <a href="+item["meta"]["link"]+">\
+      <div class='messageitem clearfix'>\
+        <small>"+item["msg"]["agent"]+"\
+          <span class='activity-message'> PR#"+item["msg"]["pullrequest"]["id"]+"</span>\
+          <span>"+item["meta"]["date"]+"</span>\
+        </small>\
+      </div>\
+    </a>\
+    ")
     if (item["topic"]=="io.pagure.prod.pagure.pull-request.new"){
-        $(messagedetail).find(".activity-message").addClass("text-success").prepend("created");
+        $(messagedetail).find(".activity-message")
+            .addClass("text-success").prepend("created");
     } else if (item['topic']=="io.pagure.prod.pagure.pull-request.comment.added") {
-        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("commented on");
+        $(messagedetail).find(".activity-message")
+           .addClass("text-muted").prepend("commented on");
+
     } else if (item['topic']=="io.pagure.prod.pagure.pull-request.comment.edited") {
-      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited comment on");
+      $(messagedetail).find(".activity-message")
+           .addClass("text-muted").prepend("edited comment on");
+
     } else if (item['topic']=="io.pagure.prod.pagure.pull-request.closed") {
       if (item["msg"]["merged"] == true){
-        $(messagedetail).find(".activity-message").addClass("text-success").prepend("merged");
+        $(messagedetail).find(".activity-message")
+           .addClass("text-success").prepend("merged");
       } else if (item["msg"]["merged"] == false){
-        $(messagedetail).find(".activity-message").addClass("text-danger").prepend("closed");
+        $(messagedetail).find(".activity-message")
+           .addClass("text-danger").prepend("closed");
       }
     } else {
-      $(messagedetail).html("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+      $(messagedetail).html("\
+      <div style='background-color:red'>\
+        "+item["meta"]["subtitle"]+"\
+      </div>");
     }
     $("#messages").append(messagedetail);
     return "PR#"+item["msg"]["pullrequest"]["id"]
   } else if (item["topic"].indexOf("io.pagure.prod.pagure.issue") > -1 ){
     if (lastitem.valueOf() != new String("ISSUE#"+item["msg"]["issue"]["id"]).valueOf())
     {
-      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='warning'></div></span>New activity on <strong><span class='label label-default'>Issue#"+item["msg"]["issue"]["id"]+"</span> "+item["msg"]["issue"]["title"]+"</strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+      $("#messages").append("\
+      <div class='messagetitle m-t-2 p-t-2'>\
+        <div class='messageicon'>\
+          <span class='oi' data-glyph='warning'></span>\
+        </div>\
+        New activity on \
+        <strong>\
+          <span class='label label-default'>\
+            Issue#"+item["msg"]["issue"]["id"]+"\
+          </span> \
+          "+item["msg"]["issue"]["title"]+"\
+        </strong>\
+        <div class='pull-xs-right'>"+item["meta"]["date"]+"</div>\
+      </div>\
+      ");
     }
-    messagedetail = $("<a href="+item["meta"]["link"]+"><div class='messageitem clearfix'><small>"+item["msg"]["agent"]+" <span class='activity-message'> Issue #"+item["msg"]["issue"]["id"]+" </span> <span>"+item["meta"]["date"]+"</span></small></div></a>")
+    messagedetail = $("\
+    <a href="+item["meta"]["link"]+">\
+      <div class='messageitem clearfix'>\
+        <small>"+item["msg"]["agent"]+"\
+         <span class='activity-message'> \
+          Issue #"+item["msg"]["issue"]["id"]+" \
+         </span> \
+         <span>"+item["meta"]["date"]+"</span>\
+        </small>\
+      </div>\
+    </a>\
+    ");
     if (item["topic"]=="io.pagure.prod.pagure.issue.new"){
-      $(messagedetail).find(".activity-message").addClass("text-success").prepend("created");
+      $(messagedetail).find(".activity-message")
+         .addClass("text-success").prepend("created");
     } else if (item['topic']=="io.pagure.prod.pagure.issue.edit") {
       if (item["msg"]["fields"].length == 1){
-        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited the "+item["msg"]["fields"][0]+" field in");
+        $(messagedetail).find(".activity-message")
+           .addClass("text-muted")
+           .prepend("edited the "+item["msg"]["fields"][0]+" field in");
       } else {
         var outputstring = "";
         for (var i in item["msg"]["fields"]){
@@ -58,46 +124,93 @@ function processMessages(item, lastitem) {
           outputstring = outputstring +" & "
           }
         }
-        $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited the "+outputstring+" fields in");
+        $(messagedetail).find(".activity-message")
+           .addClass("text-muted")
+           .prepend("edited the "+outputstring+" fields in");
       }
 
     } else if (item['topic']=="io.pagure.prod.pagure.issue.comment.added") {
-      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("commented on");
+      $(messagedetail).find(".activity-message")
+         .addClass("text-muted").prepend("commented on");
     } else if (item['topic']=="io.pagure.prod.pagure.issue.comment.edited") {
-      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("edited a comment on");
+      $(messagedetail).find(".activity-message")
+         .addClass("text-muted").prepend("edited a comment on");
     } else if (item['topic']=="io.pagure.prod.pagure.issue.assigned.added") {
-      $(messagedetail).find(".activity-message").addClass("text-muted").prepend("assigned ").append(" to "+item["msg"]["issue"]["assignee"]["name"]);
+      $(messagedetail).find(".activity-message")
+         .addClass("text-muted")
+         .prepend("assigned ")
+         .append(" to "+item["msg"]["issue"]["assignee"]["name"]);
     } else {
-      $(messagedetail).html("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+      $(messagedetail).html("\
+        <div style='background-color:red'>\
+          "+item["meta"]["subtitle"]+"\
+        </div>\
+        ");
     }
     $("#messages").append(messagedetail);
     return "ISSUE#"+item["msg"]["issue"]["id"]
   } else if (item["topic"].indexOf("io.pagure.prod.pagure.project") > -1 ){
     if (item["topic"]=="io.pagure.prod.pagure.project.forked"){
-      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='fork'></span></div>"+item["msg"]["agent"]+" forked "+item["msg"]["project"]["name"]+" into <a href='"+item["meta"]["link"]+"'>"+item["msg"]["agent"]+"/"+item["msg"]["project"]["name"]+"</a></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+      $("#messages").append("\
+        <div class='messagetitle m-t-2 p-t-2'>\
+          <div class='messageicon'>\
+            <span class='oi' data-glyph='fork'></span>\
+          </div>\
+          "+item["msg"]["agent"]+" forked "+item["msg"]["project"]["name"]+"\
+           into <a href='"+item["meta"]["link"]+"'>"+item["msg"]["agent"]+"\
+           /"+item["msg"]["project"]["name"]+"</a>\
+           <div class='pull-xs-right'>"+item["meta"]["date"]+"</div>\
+        </div>");
     } else {
-      $("#messages").append("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+      $("#messages").append("\
+        <div style='background-color:red'>\
+          "+item["meta"]["subtitle"]+"\
+        </div>");
     }
     return "";
   } else if (item["topic"].indexOf("io.pagure.prod.pagure.git") > -1 ){
     if (lastitem.valueOf() != new String("GITCOMMIT#"+item["msg"]["commit"]["branch"]).valueOf())
     {
-      $("#messages").append("<div class='messagetitle m-t-2 p-t-2'><div class='messageicon'><span class='oi' data-glyph='spreadsheet'></div></span>New commits to <strong><span class='pr-toplabel'> <span class='oi' data-glyph='random'> </span> "+item['msg']['commit']['branch'].replace("refs/heads/","")+"</span></strong><div class='pull-xs-right'>"+item["meta"]["date"]+"</div></div>");
+      $("#messages").append("\
+        <div class='messagetitle m-t-2 p-t-2'>\
+          <div class='messageicon'>\
+            <span class='oi' data-glyph='spreadsheet'></span>\
+          </div>\
+          New commits to <strong><span class='pr-toplabel'> \
+          <span class='oi' data-glyph='random'> </span> \
+          "+item['msg']['commit']['branch'].replace("refs/heads/","")+"\
+          </span></strong>\
+          <div class='pull-xs-right'>"+item["meta"]["date"]+"</div>\
+        </div>\
+        ");
     }
     if (item["topic"]=="io.pagure.prod.pagure.git.receive"){
       $("#messages").append("\
       <a href="+item["meta"]["link"]+">\
         <div class='messageitem'>\
-          <small>"+item["msg"]["commit"]["name"]+" <span class='activity-message text-muted'> committed </span></small><span class='label label-default msg-git-hash'>"+item["msg"]["commit"]["rev"].substring(0,6)+"</span><small> <span class='text-muted'>"+item["msg"]["commit"]["message"]+"</span> </small>\
+          <small>"+item["msg"]["commit"]["name"]+" \
+          <span class='activity-message text-muted'> committed </span></small>\
+          <span class='label label-default msg-git-hash'>\
+            "+item["msg"]["commit"]["rev"].substring(0,6)+"\
+          </span>\
+          <small> \
+          <span class='text-muted'>"+item["msg"]["commit"]["message"]+"</span> \
+          </small>\
         </div>\
       </a>");
       return "GITCOMMIT#"+item["msg"]["commit"]["branch"];
     } else {
-      $("#messages").append("<div style='background-color:red'>"+item["meta"]["subtitle"]+"</div>");
+      $("#messages").append("\
+      <div style='background-color:red'>\
+      "+item["meta"]["subtitle"]+"\
+      </div>");
     }
     return "";
   } else {
-    $("#messages").append("<div style='background-color:pink'>"+item["meta"]["subtitle"]+"</div>");
+    $("#messages").append("\
+    <div style='background-color:pink'>\
+    "+item["meta"]["subtitle"]+"\
+    </div>");
     return "";
   }
 }

From 0fc819c71d4fc5d731388b1dd10567ba626afcbb Mon Sep 17 00:00:00 2001
From: Ryan Lerch <rlerch@redhat.com>
Date: Apr 11 2016 14:21:07 +0000
Subject: [PATCH 5/6] added tests for activity feed page


---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index ad24261..0bbc3a4 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -2324,6 +2324,18 @@ index 0000000..fb7093d
         output = self.app.get('/docs/test/')
         self.assertEqual(output.status_code, 404)
 
+    def test_view_project_activity(self):
+        """ Test the view_project_activity endpoint. """
+        output = self.app.get('/foo/activity/')
+        # project doesnt exist
+        self.assertEqual(output.status_code, 404)
+
+        tests.create_projects(self.session)
+
+        output = self.app.get('/test/activity/')
+        # Project Exists, but No DATAGREPPER_URL set
+        self.assertEqual(output.status_code, 404)
+
 
 if __name__ == '__main__':
     SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskRepotests)

From 68cdc3dfd012dc4103b071f073c2e9583317df81 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Apr 11 2016 14:21:07 +0000
Subject: [PATCH 6/6] Rework and improve the test for the view_project_activity endpoint


---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 0bbc3a4..b0c281d 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -2326,14 +2326,23 @@ index 0000000..fb7093d
 
     def test_view_project_activity(self):
         """ Test the view_project_activity endpoint. """
-        output = self.app.get('/foo/activity/')
-        # project doesnt exist
-        self.assertEqual(output.status_code, 404)
-
         tests.create_projects(self.session)
 
-        output = self.app.get('/test/activity/')
         # Project Exists, but No DATAGREPPER_URL set
+        output = self.app.get('/test/activity/')
+        self.assertEqual(output.status_code, 404)
+
+        # Project Exists, and DATAGREPPER_URL set
+        pagure.APP.config['DATAGREPPER_URL'] = 'foo'
+        output = self.app.get('/test/activity/')
+        self.assertEqual(output.status_code, 200)
+        self.assertIn(
+            '<title>Activity - test - Pagure</title>', output.data)
+        self.assertIn(
+            'No activity reported on the test project', output.data)
+
+        # project doesnt exist
+        output = self.app.get('/foo/activity/')
         self.assertEqual(output.status_code, 404)
 
 

