From b3503735245899dc672584e69f58db876a928e78 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 1/13] Add an intial_comment field in the PR table --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index bb06e28..ec9654a 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -779,6 +779,9 @@ class PullRequest(BASE): commit_stop = sa.Column( sa.Text(), nullable=True) + initial_comment = sa.Column( + sa.Text(), + nullable=True) user_id = sa.Column( sa.Integer, sa.ForeignKey('users.id', onupdate='CASCADE'), From 2800a8402293fe0988ff179c67e985fd9ecbff1d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 2/13] Add an alembic migration field to add the initial_comment field in the PR table --- diff --git a/alembic/versions/4cae55a80a42_add_the_initial_comment_on_the_pr_table.py b/alembic/versions/4cae55a80a42_add_the_initial_comment_on_the_pr_table.py new file mode 100644 index 0000000..c329944 --- /dev/null +++ b/alembic/versions/4cae55a80a42_add_the_initial_comment_on_the_pr_table.py @@ -0,0 +1,29 @@ +"""Add the initial_comment on the PR table + +Revision ID: 4cae55a80a42 +Revises: 1f3de3853a1a +Create Date: 2016-03-01 12:00:34.823097 + +""" + +# revision identifiers, used by Alembic. +revision = '4cae55a80a42' +down_revision = '1f3de3853a1a' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ''' Add the column initial_comment to the table pull_requests. + ''' + op.add_column( + 'pull_requests', + sa.Column('initial_comment', sa.Text, nullable=True) + ) + + +def downgrade(): + ''' Remove the column initial_comment from the table pull_requests. + ''' + op.drop_column('pull_requests', 'initial_comment') From 47947e824eff0a3bb488f2c33d57f7c915089249 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 3/13] Support initial_comment in new_pull_request in the internal API --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index af2cdff..92684ca 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1107,7 +1107,8 @@ def drop_issue(session, issue, user, ticketfolder): def new_pull_request(session, branch_from, repo_to, branch_to, title, user, - requestfolder, repo_from=None, remote_git=None, + requestfolder, initial_comment=None, + repo_from=None, remote_git=None, requestuid=None, requestid=None, status='Open', notify=True): ''' Create a new pull request on the specified repo. ''' @@ -1127,6 +1128,7 @@ def new_pull_request(session, branch_from, branch=branch_to, branch_from=branch_from, title=title, + initial_comment=initial_comment or None, user_id=user_obj.id, status=status, ) From aa6975aae84a1899b6c7205ce1fb8fb841caf58f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 4/13] just some small indentation --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 72c7642..e35b11a 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -1,5 +1,7 @@ {% extends "repo_master.html" %} -{% from "_formhelper.html" import render_field, render_bootstrap_field, show_comment, show_initial_comment %} +{% from "_formhelper.html" + import render_field, render_bootstrap_field, + show_comment, show_initial_comment %} {% block title %}Issue #{{ issueid }}: {{issue.title | noJS(ignore="img") | safe }} - {{ repo.name }}{% endblock %} {% set tag = "home"%} From 273d1bd69256e26757593ebbea407cd6ec242a6a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 5/13] Save the initial_comment when creating a new PR --- diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 27f3e05..96595f0 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -936,6 +936,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None): if orig_commit: orig_commit = orig_commit.oid.hex + initial_comment = form.initial_comment.data.strip() or None request = pagure.lib.new_pull_request( SESSION, repo_to=parent, @@ -943,23 +944,11 @@ def new_request_pull(repo, branch_to, branch_from, username=None): branch_from=branch_from, repo_from=repo, title=form.title.data, + initial_comment=initial_comment, user=flask.g.fas_user.username, requestfolder=APP.config['REQUESTS_FOLDER'], ) - if form.initial_comment.data.strip() != '': - pagure.lib.add_pull_request_comment( - SESSION, - request=request, - commit=None, - tree_id=None, - filename=None, - row=None, - comment=form.initial_comment.data.strip(), - user=flask.g.fas_user.username, - requestfolder=APP.config['REQUESTS_FOLDER'], - ) - try: SESSION.commit() except SQLAlchemyError as err: # pragma: no cover From fac18535c5ade4fd286bcfb397cecb6a4dc49a38 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 6/13] Adjust indentation in the HTML --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 38381fa..afb6e65 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -198,34 +198,34 @@ From 53e6517b05229b1698f4394251a26ddd9aa7c9dd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 7/13] Support editing the initial comment when editing a pull-request --- diff --git a/pagure/templates/pull_request_title.html b/pagure/templates/pull_request_title.html index 19c168f..c7fbd6d 100644 --- a/pagure/templates/pull_request_title.html +++ b/pagure/templates/pull_request_title.html @@ -25,7 +25,12 @@ }}" method="post"> - {{ render_bootstrap_field(form.title, field_description="the new title of your pull-request") }} + {{ render_bootstrap_field( + form.title, + field_description="the new title of your pull-request") }} + {{ render_bootstrap_field( + form.initial_comment, + field_description="description of your pull-request") }}

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 96595f0..3b2c9d0 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -394,7 +394,8 @@ def request_pull_edit(repo, requestid, username=None): form = pagure.forms.RequestPullForm() if form.validate_on_submit(): - request.title = form.title.data + request.title = form.title.data.strip() + request.initial_comment = form.initial_comment.data.strip() SESSION.add(request) try: SESSION.commit() @@ -410,6 +411,7 @@ def request_pull_edit(repo, requestid, username=None): repo=repo.name, requestid=requestid)) elif flask.request.method == 'GET': form.title.data = request.title + form.initial_comment.data = request.initial_comment return flask.render_template( 'pull_request_title.html', From a1aaf147b85add393069cae7b6de0a3e3cedacde Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 8/13] add the initial comment to the top of the PR --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index afb6e65..80fc0dc 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -93,7 +93,15 @@ {{ pull_request.branch }} - +{%if pull_request.initial_comment %} +

+
+ {%- autoescape false -%} +{{ pull_request.initial_comment | markdown }} + {%- endautoescape -%} +
+
+{%endif%} {% elif form and (repo_admin or remote_git) %}

Create pull request

{% else %} From c609896148585f129b9da0a338e4c467f6c41302 Mon Sep 17 00:00:00 2001 From: ryanlerch Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 9/13] add check to see if pull_request exsists --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 80fc0dc..c7a3f82 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -93,7 +93,7 @@ {{ pull_request.branch }} -{%if pull_request.initial_comment %} +{%if pull_request and pull_request.initial_comment %}
{%- autoescape false -%} From 0b4a6f4ec01b7c0095abb1b4318afa0c3f4edf94 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:23 +0000 Subject: [PATCH 10/13] Drop un-used class and block JS in the markdown syntax of the initial comment --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index c7a3f82..1e40138 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -94,11 +94,9 @@ {%if pull_request and pull_request.initial_comment %} -
+
- {%- autoescape false -%} -{{ pull_request.initial_comment | markdown }} - {%- endautoescape -%} +{{ pull_request.initial_comment | markdown | noJS | safe }}
{%endif%} From 27224e1ec7d82bffa7de16cdc877606d44111ddd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:24 +0000 Subject: [PATCH 11/13] Prevent more JS in the comments field while still marking them as safe --- diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index 82e63e0..633ccc3 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -124,13 +124,11 @@ }}"> - {%- autoescape false %} {%- if id == 0 -%} -{{ comment.content | markdown }} +{{ comment.content | markdown | noJS | safe }} {%- else -%} -{{ comment.comment | markdown }} +{{ comment.comment | markdown | noJS | safe }} {%- endif -%} - {% endautoescape -%}
@@ -173,9 +171,7 @@
- {%- autoescape false -%} -{{ comment.content | markdown }} - {%- endautoescape -%} +{{ comment.content | markdown | noJS | safe }}
From a0fed4242024e2c7bddc1121714cd8ceaa47558c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:24 +0000 Subject: [PATCH 12/13] Include the initial_comment in the JSON representation of a PR --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index ec9654a..c51170f 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -932,6 +932,7 @@ class PullRequest(BASE): 'commit_stop': self.commit_stop, 'closed_by': self.closed_by.to_json( public=public) if self.closed_by else None, + 'initial_comment': self.initial_comment, } comments = [] From 10ca8a3e8cdaa8681cac9e357cd823bf61e1565c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 10:36:24 +0000 Subject: [PATCH 13/13] Adjust the unit-tests for the change in the JSON representation of a PR --- diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index d4cee86..c175ae4 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -112,6 +112,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "commit_stop": None, "date_created": "1431414800", "id": 1, + "initial_comment": None, "project": { "date_created": "1431414800", "description": "test project #1", @@ -235,6 +236,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "commit_stop": None, "date_created": "1431414800", "id": 1, + "initial_comment": None, "project": { "date_created": "1431414800", "description": "test project #1", diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 38c026b..d29890d 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -691,7 +691,7 @@ new file mode 100644 index 0000000..60f7480 --- /dev/null +++ b/456 -@@ -0,0 +1,80 @@ +@@ -0,0 +1,81 @@ +{ + "assignee": null, + "branch": "master", @@ -703,6 +703,7 @@ index 0000000..60f7480 + "commit_stop": null, + "date_created": null, + "id": 1, ++ "initial_comment": null, + "project": { + "date_created": null, + "description": "test project for ticket",