#2681 Print out the URL to existing PR(s) or to create one in the default hook
Merged 4 years ago by pingou. Opened 4 years ago by pingou.

@@ -92,6 +92,39 @@ 

              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:

you can skip creating variable seen and use for .. else .. construction. which also eliminates need for doing len() =)

for...else doesn't seem to do exactly what I want:

>>> for el in [1,2]:
...     print el
... else:
...     print None
...     
... 
1
2
None

+                 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)

  

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

  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 @@ 

              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:

@@ -1884,7 +1884,6 @@ 

  +        "date_modified": null,

  +        "description": "test project for ticket",

  +        "fullname": "test_ticket_repo",

- +        "url_path": "test_ticket_repo",

  +        "id": 1,

  +        "milestones": {},

  +        "name": "test_ticket_repo",
@@ -1937,7 +1936,6 @@ 

  +        "date_modified": null,

  +        "description": "test project for ticket",

  +        "fullname": "test_ticket_repo",

- +        "url_path": "test_ticket_repo",

  +        "id": 1,

  +        "milestones": {},

  +        "name": "test_ticket_repo",

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 pingou@pingoured.fr

rebased onto e30f9b8

4 years ago

1 new commit added

  • Fix the unit-tests
4 years ago

Was looking for this functionality long time ago =)

you can skip creating variable seen and use for .. else .. construction. which also eliminates need for doing len() =)

for...else doesn't seem to do exactly what I want:

>>> for el in [1,2]:
...     print el
... else:
...     print None
...     
... 
1
2
None

hmmmm... then do it your way =)

Thanks for the review ! :)

Pull-Request has been merged by pingou

4 years ago