From 37bf99dafebf16ce132994b12765709ddb28667f Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 13 2017 23:36:08 +0000
Subject: [PATCH 1/6] fix spelling mistake in model.py


---

diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index ad01277..983398a 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -1826,7 +1826,7 @@ class PagureLog(BASE):
         elif self.pull_request and self.log_type == 'created':
             verb = 'created PR'
         elif self.pull_request and self.log_type == 'commented':
-            verb = 'comment on PR'
+            verb = 'commented on PR'
         elif self.pull_request and self.log_type == 'closed':
             verb = 'closed PR'
         elif self.pull_request and self.log_type == 'merged':

From 6b462c233ed7347f1753e499e8948b2785b08ae8 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 13 2017 23:36:08 +0000
Subject: [PATCH 2/6] fix spelling mistake in model.py#2


---

diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 983398a..6dcd212 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -1822,7 +1822,7 @@ class PagureLog(BASE):
         if self.issue and self.log_type == 'created':
             verb = 'created issue'
         elif self.issue and self.log_type == 'commented':
-            verb = 'comment on issue'
+            verb = 'commented on issue'
         elif self.pull_request and self.log_type == 'created':
             verb = 'created PR'
         elif self.pull_request and self.log_type == 'commented':

From c70a81aecbb6e24220762037efb84ef51a7b9f74 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 13 2017 23:36:08 +0000
Subject: [PATCH 3/6] fix issue_comment log user_id


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index abcbb94..2ae4d8f 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -273,7 +273,7 @@ def add_issue_comment(session, issue, comment, user, ticketfolder,
     pagure.lib.git.update_git(
         issue, repo=issue.project, repofolder=ticketfolder)
 
-    log_action(session, 'commented', issue)
+    log_action(session, 'commented', issue_comment)
 
     if notify:
         pagure.lib.notify.notify_new_comment(issue_comment, user=user_obj)

From d3ab99e00eb26844fcdc0d27e1fbb561f5ee427e Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 14 2017 10:48:15 +0000
Subject: [PATCH 4/6] fix spelling mistake in model.py


---

diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 6dcd212..d320352 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -381,7 +381,7 @@ class Project(BASE):
 
     @property
     def isa(self):
-        ''' A string to allow finding out that this is an project. '''
+        ''' A string to allow finding out that this is a project. '''
         return 'project'
 
     @property

From 44494187ae73a6b363ebd3e6ddadcc0590da3b3b Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 14 2017 10:48:15 +0000
Subject: [PATCH 5/6] fix pull_request close log user_id


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 2ae4d8f..b9f7832 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -922,7 +922,7 @@ def add_pull_request_comment(session, request, commit, tree_id, filename,
     pagure.lib.git.update_git(
         request, repo=request.project, repofolder=requestfolder)
 
-    log_action(session, 'commented', request)
+    log_action(session, 'commented', pr_comment)
 
     if notify:
         pagure.lib.notify.notify_pull_request_comment(pr_comment, user_obj)
@@ -3574,6 +3574,7 @@ def log_action(session, action, obj):
             'Unsupported object found: "%s"' % obj
         )
 
+
     log = model.PagureLog(
         user_id=obj.user_id,
         project_id=project_id,
@@ -3586,7 +3587,8 @@ def log_action(session, action, obj):
         setattr(log, 'issue_uid', obj.uid)
     elif obj.isa == 'pull-request':
         setattr(log, 'pull_request_uid', obj.uid)
-
+        if obj.closed_by_id and obj.closed_by_id != '':
+            setattr(log, 'user_id', obj.closed_by_id)
 
     session.add(log)
     session.commit()

From 21b423fcd9568a8fb86da75fa9dbc25675f3f308 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Jan 14 2017 23:34:44 +0000
Subject: [PATCH 6/6] modify log_action method


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index b9f7832..ea7c724 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -3565,15 +3565,6 @@ def log_action(session, action, obj):
     ''' Log an user action on a project/issue/PR. '''
 
     project_id = None
-    if obj.isa in ['issue', 'pull-request']:
-        project_id = obj.project_id
-    elif obj.isa == 'project':
-        project_id = obj.id
-    else:
-        raise pagure.exceptions.InvalidObjectException(
-            'Unsupported object found: "%s"' % obj
-        )
-
 
     log = model.PagureLog(
         user_id=obj.user_id,
@@ -3583,12 +3574,28 @@ def log_action(session, action, obj):
         date=obj.date_created.date(),
         date_created=obj.date_created
     )
+
     if obj.isa == 'issue':
-        setattr(log, 'issue_uid', obj.uid)
+        setattr( log, 'issue_uid', obj.uid)
+        project_id = obj.project_id
     elif obj.isa == 'pull-request':
-        setattr(log, 'pull_request_uid', obj.uid)
+        setattr( log, 'pull_request_uid', obj.uid)
+        project_id = obj.project_id
         if obj.closed_by_id and obj.closed_by_id != '':
-            setattr(log, 'user_id', obj.closed_by_id)
+            setattr( log, 'user_id', obj.closed_by_id)
+    elif obj.isa == 'project':
+        project_id = obj.id
+    elif hasattr(obj, 'issue'):
+        project_id = obj.issue.project_id
+    elif hasattr( obj, 'pull_request'):
+        project_id = obj.pull_request.project_id
+    else:
+        log = None
+        raise pagure.exceptions.InvalidObjectException(
+            'Unsupported object found: "%s"' % obj
+        )
+
+    setattr( log, 'project_id', project_id)
 
     session.add(log)
     session.commit()

