From e30f9b8042bb657fd496c8c48fcc8cec29177446 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 13 2017 14:00:47 +0000 Subject: Print out the URL to existing PR(s) or to create one in the default hook With this commit, when you make a push it will print out the URLs you can use to create a new PR or check out the existing/updated one. Fixes https://pagure.io/pagure/issue/2556 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/files/default_hook.py b/pagure/hooks/files/default_hook.py old mode 100755 new mode 100644 index d87a403..79754a1 --- a/pagure/hooks/files/default_hook.py +++ b/pagure/hooks/files/default_hook.py @@ -92,6 +92,39 @@ def run_as_post_receive_hook(): print('/!\ Commit notification emails will not be sent and ' 'commits won\'t be logged') + target_repo = project + if project.is_fork: + target_repo = project.parent + + if commits and refname != default_branch\ + and target_repo.settings.get('pull_requests', True): + print() + prs = pagure.lib.search_pull_requests( + pagure.SESSION, + project_id_from=project.id, + status='Open', + branch_from=refname, + ) + # Link to existing PRs if there are any + seen = len(prs) != 0 + for pr in prs: + print('View pull-request for %s' % refname) + print(' %s/%s/pull-request/%s' % ( + pagure.APP.config['APP_URL'].rstrip('/'), + project.url_path, + pr.id) + ) + # If no existing PRs, provide the link to open one + if not seen: + print('Create a pull-request for %s' % refname) + print(' %s/%s/diff/%s..%s' % ( + pagure.APP.config['APP_URL'].rstrip('/'), + project.url_path, + default_branch, + refname) + ) + print() + # Schedule refresh of all opened PRs pagure.lib.tasks.refresh_pr_cache.delay(project.name, namespace, username) diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index beba1af..9f54136 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2417,7 +2417,7 @@ def get_colored_tag(session, tag, project_id): def search_pull_requests( session, requestid=None, project_id=None, project_id_from=None, status=None, author=None, assignee=None, count=False, - offset=None, limit=None, updated_after=None): + offset=None, limit=None, updated_after=None, branch_from=None): ''' Retrieve the specified issue ''' @@ -2499,6 +2499,11 @@ def search_pull_requests( model.User.user == author ) + if branch_from is not None: + query = query.filter( + model.PullRequest.branch_from == branch_from + ) + if requestid: output = query.first() elif count: