From 458679328c35ef31b9bd4f4588047b0e32d270e1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 06 2016 13:21:31 +0000 Subject: [PATCH 1/3] Fix the HTML indentation --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 4ab71ea..bb1e618 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -110,29 +110,33 @@ repo=repo.name, commitid=commitid, branch_from=branch_from, branch_to=branch_to) }}" method="post"> {% endif %} -
- Pull from - {% - if remote_git -%}{{ remote_git }}{%- - else -%} - {{ repo.fullname }} {%- - endif -%} - - - - {{ branch_from }} - into -{% if repo.is_fork -%}{{ repo.parent.fullname }}{% else %}{{ repo.fullname }}{% endif %} - +
+ Pull from + {% + if remote_git -%}{{ remote_git }}{%- + else -%} + {{ repo.fullname }} {%- + endif -%} + + + + {{ branch_from }} + + into + + {% if repo.is_fork -%}{{ repo.parent.fullname }}{% + else %}{{ repo.fullname }}{% endif %} +   +
- {{ render_bootstrap_field(form.title) }} + {{ render_bootstrap_field(form.title) }}

{{ form.csrf_token }} From 87633ff4ce52a4db9b125623d4448a6b5c7830ed Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 06 2016 13:21:31 +0000 Subject: [PATCH 2/3] Add a way to show a contributing information block when opening a new PR When someone opens a new PR, we'll look into the requests git repo for a file ``templates/contributing.md`` and if present, we will show it on the new PR page to the user. This will allow developers to express what they would like to see in a PR when submitted. fixes https://pagure.io/pagure/issue/587 --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index bb1e618..79a0423 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -136,6 +136,11 @@ {% endfor %}

+ {% if contributing %} +
+ {{ contributing | markdown | noJS | safe}} +
+ {% endif %} {{ render_bootstrap_field(form.title) }}

diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 79a0d39..7519f29 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -21,7 +21,8 @@ import pagure.exceptions import pagure.lib import pagure.lib.git import pagure.forms -from pagure import (APP, SESSION, LOG, login_required, is_repo_admin) +from pagure import (APP, SESSION, LOG, login_required, is_repo_admin, + __get_file_in_tree) # pylint: disable=E1101 @@ -43,6 +44,18 @@ def _get_parent_repo_path(repo): return parentpath +def _get_parent_request_repo_path(repo): + """ Return the path of the parent git repository corresponding to the + provided Repository object from the DB. + """ + if repo.parent: + parentpath = os.path.join(APP.config['REQUESTS_FOLDER'], repo.parent.path) + else: + parentpath = os.path.join(APP.config['REQUESTS_FOLDER'], repo.path) + + return parentpath + + def _get_pr_info(repo_obj, orig_repo, branch_from, branch_to): ''' Return the info needed to see a diff or make a Pull-Request between the two specified repo. @@ -963,6 +976,21 @@ def new_request_pull(repo, branch_to, branch_from, username=None): if len(diff_commits) == 1 and form: form.title.data=diff_commits[0].message.strip().split('\n')[0] + # Get the contributing templates from the requests git repo + contributing = None + requestrepopath = _get_parent_request_repo_path(repo) + if os.path.exists(requestrepopath): + requestepo = pygit2.Repository(requestrepopath) + if not requestepo.is_empty and not requestepo.head_is_unborn: + commit = requestepo[requestepo.head.target] + contributing = __get_file_in_tree( + requestepo, commit.tree, ['templates', 'contributing.md'], + bail_on_tree=True) + if contributing: + contributing, safe = pagure.doc_utils.convert_readme( + contributing.data, 'md') + output_type = 'markup' + return flask.render_template( 'pull_request.html', select='requests', @@ -977,6 +1005,7 @@ def new_request_pull(repo, branch_to, branch_from, username=None): branch_to=branch_to, branch_from=branch_from, repo_admin=repo_admin, + contributing=contributing, ) From 292f52cd0f81a0e88cd674790a9ce61c2c87177c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 06 2016 13:21:31 +0000 Subject: [PATCH 3/3] Fix typo in the variable name, requestepo != requestrepo --- diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 7519f29..b1a15e7 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -980,11 +980,11 @@ def new_request_pull(repo, branch_to, branch_from, username=None): contributing = None requestrepopath = _get_parent_request_repo_path(repo) if os.path.exists(requestrepopath): - requestepo = pygit2.Repository(requestrepopath) - if not requestepo.is_empty and not requestepo.head_is_unborn: - commit = requestepo[requestepo.head.target] + requestrepo = pygit2.Repository(requestrepopath) + if not requestrepo.is_empty and not requestrepo.head_is_unborn: + commit = requestrepo[requestrepo.head.target] contributing = __get_file_in_tree( - requestepo, commit.tree, ['templates', 'contributing.md'], + requestrepo, commit.tree, ['templates', 'contributing.md'], bail_on_tree=True) if contributing: contributing, safe = pagure.doc_utils.convert_readme(