changeset 8463:a9bcdc438d69 stable

git: fix pull request deletion - don't crash on deleting refs to PR heads The refs name was passed as unicode string, and that would cause failure like: File ".../site-packages/dulwich/repo.py", line 720, in __delitem__ if name.startswith(b"refs/") or name == b"HEAD": TypeError: startswith first arg must be str or a tuple of str, not bytes Fixed by correctly passing the ref name as bytes, as we do when creating the PR refs. Tests added by Mads Kiilerich.
author Anton Schur <tonich.sh@gmail.com>
date Sat, 26 Sep 2020 15:39:33 +0200
parents b27584990c2c
children b2ed5a40094c
files CONTRIBUTORS kallithea/model/pull_request.py kallithea/templates/about.html kallithea/tests/functional/test_pullrequests.py kallithea/tests/functional/test_pullrequests_git.py
diffstat 5 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CONTRIBUTORS	Sat Sep 26 17:33:18 2020 +0200
+++ b/CONTRIBUTORS	Sat Sep 26 15:39:33 2020 +0200
@@ -3,6 +3,7 @@
     Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> 2014-2020
     Mads Kiilerich <mads@kiilerich.com> 2016-2020
     Asterios Dimitriou <steve@pci.gr> 2016-2017 2020
+    Anton Schur <tonich.sh@gmail.com> 2017 2020
     Private <adamantine.sword@gmail.com> 2019-2020
     David Ignjić <ignjic@gmail.com> 2020
     Dennis Fink <dennis.fink@c3l.lu> 2020
@@ -41,7 +42,6 @@
     Søren Løvborg <sorenl@unity3d.com> 2015-2017
     Sam Jaques <sam.jaques@me.com> 2015 2017
     Alessandro Molina <alessandro.molina@axant.it> 2017
-    Anton Schur <tonich.sh@gmail.com> 2017
     Ching-Chen Mao <mao@lins.fju.edu.tw> 2017
     Eivind Tagseth <eivindt@gmail.com> 2017
     FUJIWARA Katsunori <foozy@lares.dti.ne.jp> 2017
--- a/kallithea/model/pull_request.py	Sat Sep 26 17:33:18 2020 +0200
+++ b/kallithea/model/pull_request.py	Sat Sep 26 15:39:33 2020 +0200
@@ -139,7 +139,7 @@
         if pull_request.org_repo.scm_instance.alias == 'git':
             # remove a ref under refs/pull/ so that commits can be garbage-collected
             try:
-                del pull_request.org_repo.scm_instance._repo["refs/pull/%d/head" % pull_request.pull_request_id]
+                del pull_request.org_repo.scm_instance._repo[b"refs/pull/%d/head" % pull_request.pull_request_id]
             except KeyError:
                 pass
 
--- a/kallithea/templates/about.html	Sat Sep 26 17:33:18 2020 +0200
+++ b/kallithea/templates/about.html	Sat Sep 26 15:39:33 2020 +0200
@@ -28,6 +28,7 @@
   <li>Copyright &copy; 2014&ndash;2020, Thomas De Schampheleire</li>
   <li>Copyright &copy; 2015&ndash;2017, 2019&ndash;2020, Étienne Gilli</li>
   <li>Copyright &copy; 2016&ndash;2017, 2020, Asterios Dimitriou</li>
+  <li>Copyright &copy; 2017, 2020, Anton Schur</li>
   <li>Copyright &copy; 2019&ndash;2020, Private</li>
   <li>Copyright &copy; 2020, David Ignjić</li>
   <li>Copyright &copy; 2020, Dennis Fink</li>
@@ -63,7 +64,6 @@
   <li>Copyright &copy; 2015&ndash;2017, Søren Løvborg</li>
   <li>Copyright &copy; 2015, 2017, Sam Jaques</li>
   <li>Copyright &copy; 2017, Alessandro Molina</li>
-  <li>Copyright &copy; 2017, Anton Schur</li>
   <li>Copyright &copy; 2017, Ching-Chen Mao</li>
   <li>Copyright &copy; 2017, Eivind Tagseth</li>
   <li>Copyright &copy; 2017, FUJIWARA Katsunori</li>
--- a/kallithea/tests/functional/test_pullrequests.py	Sat Sep 26 17:33:18 2020 +0200
+++ b/kallithea/tests/functional/test_pullrequests.py	Sat Sep 26 15:39:33 2020 +0200
@@ -32,12 +32,25 @@
                                   '_session_csrf_secret_token': self.session_csrf_secret_token(),
                                  },
                                  status=302)
+        # will redirect to URL like http://localhost/vcs_test_hg/pull-request/1/_/stable
+        pull_request_id = int(response.location.split('/')[5])
+
         response = response.follow()
         assert response.status == '200 OK'
         response.mustcontain('Successfully opened new pull request')
         response.mustcontain('No additional changesets found for iterating on this pull request')
         response.mustcontain('href="/vcs_test_hg/changeset/4f7e2131323e0749a740c0a56ab68ae9269c562a"')
 
+        response = self.app.post(base.url('pullrequest_delete',
+                                 repo_name=base.HG_REPO, pull_request_id=pull_request_id),
+                                 {
+                                  '_session_csrf_secret_token': self.session_csrf_secret_token(),
+                                 },
+                                 status=302)
+        response = response.follow()
+        assert response.status == '200 OK'
+        response.mustcontain('Successfully deleted pull request')
+
     def test_available(self):
         self.log_user()
         response = self.app.post(base.url(controller='pullrequests', action='create',
--- a/kallithea/tests/functional/test_pullrequests_git.py	Sat Sep 26 17:33:18 2020 +0200
+++ b/kallithea/tests/functional/test_pullrequests_git.py	Sat Sep 26 15:39:33 2020 +0200
@@ -31,11 +31,25 @@
                                   '_session_csrf_secret_token': self.session_csrf_secret_token(),
                                  },
                                  status=302)
+        # will redirect to URL like http://localhost/vcs_test_git/pull-request/1/_/master
+        pull_request_id = int(response.location.split('/')[5])
+
         response = response.follow()
         assert response.status == '200 OK'
         response.mustcontain('Successfully opened new pull request')
         response.mustcontain('Git pull requests don&#39;t support iterating yet.')
 
+        response = self.app.post(base.url('pullrequest_delete',
+                                 repo_name=base.GIT_REPO, pull_request_id=pull_request_id),
+                                 {
+                                  '_session_csrf_secret_token': self.session_csrf_secret_token(),
+                                 },
+                                 status=302)
+        response = response.follow()
+        assert response.status == '200 OK'
+        response.mustcontain('Successfully deleted pull request')
+
+
     def test_edit_with_invalid_reviewer(self):
         invalid_user_id = 99999
         self.log_user()