#3162 Add an option to include diff in pull request notification
Closed 5 years ago by pingou. Opened 6 years ago by anar.
anar/pagure notify_with_diff  into  master

file modified
+3 -1
@@ -1778,7 +1778,9 @@ 

      log_action(session, 'created', request, user_obj)

  

      if notify:

-         pagure.lib.notify.notify_new_pull_request(request)

+         with_diff = repo_to.settings

I'd rather we split like:

with_diff = repo_to.settings.get(
    'notify_on_pull-request_with_diff_flag')

+             .get('notify_on_pull-request_with_diff_flag')

+         pagure.lib.notify.notify_new_pull_request(request, with_diff)

  

      pagure.lib.notify.log(

          request.project,

file modified
+1
@@ -530,6 +530,7 @@ 

              'pull_request_access_only': False,

              'roadmap_on_issues_page': False,

              'notify_on_pull-request_flag': False,

+             'notify_on_pull-request_with_diff_flag': False,

There is not flag involved there, what about: 'Include_diff_in_pull-request_notification' ?

              'notify_on_commit_flag': False,

          }

  

file modified
+32 -2
@@ -26,6 +26,7 @@ 

  from email.mime.text import MIMEText

  

  import flask

+ import pygit2

  import pagure.lib

  import pagure.lib.tasks_services

  from pagure.config import config as pagure_config
@@ -34,6 +35,7 @@ 

  _log = logging.getLogger(__name__)

  

  

+ MAX_EMAIL_LENGTH = 500000

  REPLY_MSG = 'To reply, visit the link below'

  if pagure_config['EVENTSOURCE_SOURCE']:

      REPLY_MSG += ' or just reply to this email'
@@ -582,10 +584,32 @@ 

      )

  

  

- def notify_new_pull_request(request):

+ def notify_new_pull_request(request, with_diff=False):

      ''' Notify the people following a project that a new pull-request was

      added to it.

      '''

+ 

+     diff = ""

+     if with_diff:

+         if request.remote:

+             repopath = pagure.utils.get_remote_repo_path(

+                 request.remote_git, request.branch_from)

+             parentpath = pagure.utils.get_repo_path(request.project)

+         else:

+             repo_from = request.project_from

+             parentpath = pagure.utils.get_repo_path(request.project)

+             repopath = parentpath

+             if repo_from:

+                 repopath = pagure.utils.get_repo_path(repo_from)

+ 

+         repo_obj = pygit2.Repository(repopath)

+         orig_repo = pygit2.Repository(parentpath)

+ 

+         diff_commits, diff = pagure.lib.git.diff_pull_request(

+             flask.g.session, request, repo_obj, orig_repo,

+             requestfolder=pagure_config['REQUESTS_FOLDER'])

+         diff = diff.patch[:MAX_EMAIL_LENGTH]

+ 

      text = u"""

  %s opened a new pull-request against the project: `%s` that you are following:

  ``
@@ -594,6 +618,10 @@ 

  

  %s

  %s

+ 

+ ~~~~~~~~~

If there is no diff, this line will look odd.

Should we create the body of the email, check if there is a diff and if so extent the email?

+ 

+ %s

  """ % (request.user.user,

         request.project.name,

         request.title,
@@ -602,7 +630,9 @@ 

             pagure_config['APP_URL'],

             _fullname_to_url(request.project.fullname),

             'pull-request',

-            request.id))

+            request.id),

+         diff)

+ 

      mail_to = _get_emails_for_obj(request)

  

      send_email(

#3025

Added an a setting to the Project, which is responsible for whether we send a notification with or without a diff. Put maximum number of characters in email to 500000.
I didn't actually manage to send myself an email locally (I guess because there is not smtp server?), but I could see the updated emails with diff in the logs.

I'd rather we split like:

with_diff = repo_to.settings.get(
    'notify_on_pull-request_with_diff_flag')

There is not flag involved there, what about: 'Include_diff_in_pull-request_notification' ?

If there is no diff, this line will look odd.

Should we create the body of the email, check if there is a diff and if so extent the email?

Going to close this PR.

There was no update in the last month.

If you feel like working on this again, please open a new one :)

Pull-Request has been closed by pingou

5 years ago