From 9b3fc8e8062320c82cea48fade673748ce0b416a Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 24 2016 15:39:36 +0000
Subject: [PATCH 1/6] Added Comment 0 to Create new PR


---

diff --git a/pagure/forms.py b/pagure/forms.py
index 2bbfe62..c0a1f25 100644
--- a/pagure/forms.py
+++ b/pagure/forms.py
@@ -92,6 +92,8 @@ class RequestPullForm(wtf.Form):
         'Title<span class="error">*</span>',
         [wtforms.validators.Required()]
     )
+    initial_comment = wtforms.TextAreaField(
+        'Initial Comment', [wtforms.validators.Optional()])
 
 
 class RemoteRequestPullForm(RequestPullForm):
diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html
index 4a31c60..8757a28 100644
--- a/pagure/templates/pull_request.html
+++ b/pagure/templates/pull_request.html
@@ -149,6 +149,7 @@
     </div>
     {% endif %}
     {{ render_bootstrap_field(form.title) }}
+    {{ render_bootstrap_field(form.initial_comment)}}
     <p class="buttons indent">
       <input type="submit" class="btn btn-primary" value="Create">
       {{ form.csrf_token }}
diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py
index b992ff8..9931c8b 100644
--- a/pagure/ui/fork.py
+++ b/pagure/ui/fork.py
@@ -946,6 +946,19 @@ def new_request_pull(repo, branch_to, branch_from, username=None):
                 user=flask.g.fas_user.username,
                 requestfolder=APP.config['REQUESTS_FOLDER'],
             )
+
+            if not form.initial_comment.data == '':
+                pagure.lib.add_pull_request_comment(
+                    SESSION,
+                    request=request,
+                    commit=None,
+                    filename=None,
+                    row=None,
+                    comment=form.initial_comment.data,
+                    user=flask.g.fas_user.username,
+                    requestfolder=APP.config['REQUESTS_FOLDER'],
+                )
+
             try:
                 SESSION.commit()
             except SQLAlchemyError as err:  # pragma: no cover

From f0a6d46c3ddbd39353a2a71abdc07907efcdacb4 Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 24 2016 15:39:36 +0000
Subject: [PATCH 2/6] Added tree id to add_pull_request_comment


Added initial comment to new_remote_pull_request

---

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py
index 9931c8b..5ff4378 100644
--- a/pagure/ui/fork.py
+++ b/pagure/ui/fork.py
@@ -952,6 +952,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None):
                     SESSION,
                     request=request,
                     commit=None,
+                    tree_id=None,
                     filename=None,
                     row=None,
                     comment=form.initial_comment.data,
@@ -1112,6 +1113,20 @@ def new_remote_request_pull(repo, username=None):
                 user=flask.g.fas_user.username,
                 requestfolder=APP.config['REQUESTS_FOLDER'],
             )
+
+            if not form.initial_comment.data == '':
+                pagure.lib.add_pull_request_comment(
+                    SESSION,
+                    request=request,
+                    commit=None,
+                    tree_id=None,
+                    filename=None,
+                    row=None,
+                    comment=form.initial_comment.data,
+                    user=flask.g.fas_user.username,
+                    requestfolder=APP.config['REQUESTS_FOLDER'],
+                )
+
             try:
                 SESSION.commit()
                 flask.flash('Request created')

From 14001421733503ceaac580ba0221379b045407bf Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 24 2016 15:39:36 +0000
Subject: [PATCH 3/6] Fixing pep8 errors


---

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py
index 5ff4378..0a2d3fb 100644
--- a/pagure/ui/fork.py
+++ b/pagure/ui/fork.py
@@ -122,7 +122,7 @@ def _get_pr_info(repo_obj, orig_repo, branch_from, branch_to):
             'Fork is empty, there are no commits to request pulling'
         )
 
-    return  (diff, diff_commits, orig_commit)
+    return(diff, diff_commits, orig_commit)
 
 
 @APP.route('/<repo>/pull-requests/')
@@ -358,7 +358,6 @@ def request_pull_patch(repo, requestid, username=None):
     return flask.Response(patch, content_type="text/plain;charset=UTF-8")
 
 
-
 @APP.route('/<repo>/pull-request/<int:requestid>/edit/',
            methods=('GET', 'POST'))
 @APP.route('/<repo>/pull-request/<int:requestid>/edit',
@@ -390,7 +389,7 @@ def request_pull_edit(repo, requestid, username=None):
         flask.abort(400, 'Pull-request is already closed')
 
     if not is_repo_admin(repo) \
-            and flask.g.fas_user.username != request.user.username :
+            and flask.g.fas_user.username != request.user.username:
         flask.abort(403, 'You are not allowed to edit this pull-request')
 
     form = pagure.forms.RequestPullForm()
@@ -753,10 +752,10 @@ def cancel_request_pull(repo, requestid, username=None):
             flask.abort(404, 'Pull-request not found')
 
         if not is_repo_admin(repo_obj) \
-            and not flask.g.fas_user.username == request.user.username:
-          flask.abort(
-              403,
-              'You are not allowed to cancel pull-request for this project')
+                and not flask.g.fas_user.username == request.user.username:
+            flask.abort(
+                403,
+                'You are not allowed to cancel pull-request for this project')
 
         pagure.lib.close_pull_request(
             SESSION, request, flask.g.fas_user.username,
@@ -992,7 +991,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None):
         form = None
 
     if len(diff_commits) == 1 and form:
-        form.title.data=diff_commits[0].message.strip().split('\n')[0]
+        form.title.data = diff_commits[0].message.strip().split('\n')[0]
 
     # Get the contributing templates from the requests git repo
     contributing = None

From f6e82be89fb684b5429d65f2bdb1b04c0ff0cd8d Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 24 2016 15:39:36 +0000
Subject: [PATCH 4/6] Modified if statement and added split() to exclude

whitespace only comments.

Added Initial comment to unit tests

Fixes issue #571

---

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py
index 0a2d3fb..f730650 100644
--- a/pagure/ui/fork.py
+++ b/pagure/ui/fork.py
@@ -946,7 +946,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None):
                 requestfolder=APP.config['REQUESTS_FOLDER'],
             )
 
-            if not form.initial_comment.data == '':
+            if form.initial_comment.data.strip() != '':
                 pagure.lib.add_pull_request_comment(
                     SESSION,
                     request=request,
@@ -1113,7 +1113,7 @@ def new_remote_request_pull(repo, username=None):
                 requestfolder=APP.config['REQUESTS_FOLDER'],
             )
 
-            if not form.initial_comment.data == '':
+            if form.initial_comment.data.strip() != '':
                 pagure.lib.add_pull_request_comment(
                     SESSION,
                     request=request,
diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py
index 55c88d4..822cbae 100644
--- a/tests/test_pagure_flask_ui_fork.py
+++ b/tests/test_pagure_flask_ui_fork.py
@@ -1404,6 +1404,7 @@ index 0000000..2a552bb
             data = {
                 'csrf_token': csrf_token,
                 'title': 'foo bar PR',
+                'initial_comment': 'Test Initial Comment',
             }
 
             output = self.app.post(
@@ -1412,6 +1413,7 @@ index 0000000..2a552bb
             self.assertIn(
                 '<title>PR#2: foo bar PR - test\n - Pagure</title>',
                 output.data)
+            self.assertIn('<p>Test Initial Comment</p>', output.data)
 
     @patch('pagure.lib.notify.send_email')
     def test_new_request_pull_empty_repo(self, send_email):

From 3207150dde67aa70e03bf9f177fdcd2b4a19d053 Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 24 2016 19:14:53 +0000
Subject: [PATCH 5/6] Added strip() to actual comment data


---

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py
index f730650..3b32050 100644
--- a/pagure/ui/fork.py
+++ b/pagure/ui/fork.py
@@ -954,7 +954,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None):
                     tree_id=None,
                     filename=None,
                     row=None,
-                    comment=form.initial_comment.data,
+                    comment=form.initial_comment.data.strip(),
                     user=flask.g.fas_user.username,
                     requestfolder=APP.config['REQUESTS_FOLDER'],
                 )
@@ -1121,7 +1121,7 @@ def new_remote_request_pull(repo, username=None):
                     tree_id=None,
                     filename=None,
                     row=None,
-                    comment=form.initial_comment.data,
+                    comment=form.initial_comment.data.strip(),
                     user=flask.g.fas_user.username,
                     requestfolder=APP.config['REQUESTS_FOLDER'],
                 )

From 43d191492cb932b2f79490ce576571b8753471b9 Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: Feb 25 2016 16:47:28 +0000
Subject: [PATCH 6/6] Added test case for empty initial comment


---

diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py
index 822cbae..2417027 100644
--- a/tests/test_pagure_flask_ui_fork.py
+++ b/tests/test_pagure_flask_ui_fork.py
@@ -1401,6 +1401,7 @@ index 0000000..2a552bb
             csrf_token = output.data.split(
                 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
 
+            # Case 1 - Add an initial comment
             data = {
                 'csrf_token': csrf_token,
                 'title': 'foo bar PR',
@@ -1415,6 +1416,22 @@ index 0000000..2a552bb
                 output.data)
             self.assertIn('<p>Test Initial Comment</p>', output.data)
 
+
+            # Case 2 - Add an empty initial comment
+            data = {
+                'csrf_token': csrf_token,
+                'title': 'foo bar PR',
+                'initial_comment': '',
+            }
+
+            output = self.app.post(
+                '/test/diff/master..feature', data=data, follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+            self.assertIn(
+                '<title>PR#3: foo bar PR - test\n - Pagure</title>',
+                output.data)
+            self.assertNotIn('<div id="comment-', output.data)
+
     @patch('pagure.lib.notify.send_email')
     def test_new_request_pull_empty_repo(self, send_email):
         """ Test the new_request_pull endpoint against an empty repo. """

