From 922e4f9874cd31bc35e6e9a2282f8e2caf7d97f8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 03 2017 10:17:23 +0000 Subject: [PATCH 1/2] When creating the pull-request, save the commit_start and commit_stop If we were able to compute a list of commits differing between the two repo there is no reason not to save that info in the DB from the start. In addition this will be most useful since it will be announced on the fedmsg message about this new PR and consumer will be able to access and use that info. --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 7a68975..42d1c19 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1507,7 +1507,8 @@ def new_pull_request(session, branch_from, requestfolder, initial_comment=None, repo_from=None, remote_git=None, requestuid=None, requestid=None, - status='Open', notify=True): + status='Open', notify=True, + commit_start=None, commit_stop=None): ''' Create a new pull request on the specified repo. ''' if not repo_from and not remote_git: raise pagure.exceptions.PagureException( @@ -1528,6 +1529,8 @@ def new_pull_request(session, branch_from, initial_comment=initial_comment or None, user_id=user_obj.id, status=status, + commit_start=commit_start, + commit_stop=commit_stop, ) request.last_updated = datetime.datetime.utcnow() diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index d8f90e3..c944d03 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -1061,6 +1061,10 @@ def new_request_pull( orig_commit = orig_commit.oid.hex initial_comment = form.initial_comment.data.strip() or None + commit_start = commit_stop = None + if diff_commits: + commit_stop = diff_commits[0].oid.hex + commit_start = diff_commits[-1].oid.hex request = pagure.lib.new_pull_request( SESSION, repo_to=parent, @@ -1071,6 +1075,8 @@ def new_request_pull( initial_comment=initial_comment, user=flask.g.fas_user.username, requestfolder=APP.config['REQUESTS_FOLDER'], + commit_start=commit_start, + commit_stop=commit_stop, ) try: From ede430ec6006974594072937f7d0ba5c04cb8589 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 03 2017 10:17:23 +0000 Subject: [PATCH 2/2] Add unit-tests checking the values of commit_start/stop on a brand new PR --- diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index 63861b1..8aff525 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/tests/test_pagure_flask_ui_fork.py @@ -1452,6 +1452,58 @@ index 0000000..2a552bb self.assertNotIn('
Create new Pull Request for master - test\n - ' + 'Pagure', output.data) + self.assertIn( + '', + output.data) + + 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', + 'initial_comment': 'Test Initial Comment', + } + + output = self.app.post( + '/test/diff/master..feature', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'PR#2: foo bar PR - test\n - Pagure', + output.data) + self.assertIn('

Test Initial Comment

', output.data) + + # Check if commit start and stop have been set for PR#2 + request = pagure.lib.search_pull_requests( + self.session, project_id=1, requestid=2) + self.assertIsNotNone(request.commit_start) + self.assertIsNotNone(request.commit_stop) + + @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. """ send_email.return_value = True