Changeset - a9bcdc438d69
[Not reviewed]
stable
0 5 0
Anton Schur - 5 years ago 2020-09-26 15:39:33
tonich.sh@gmail.com
Grafted from: fa57a4e0d1fd
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.
5 files changed with 30 insertions and 3 deletions:
0 comments (0 inline, 0 general)
CONTRIBUTORS
Show inline comments
 
@@ -3,6 +3,7 @@ List of contributors to Kallithea projec
 
    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 @@ List of contributors to Kallithea projec
 
    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
kallithea/model/pull_request.py
Show inline comments
 
@@ -139,7 +139,7 @@ class PullRequestModel(object):
 
        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
 

	
kallithea/templates/about.html
Show inline comments
 
@@ -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>
kallithea/tests/functional/test_pullrequests.py
Show inline comments
 
@@ -32,12 +32,25 @@ class TestPullrequestsController(base.Te
 
                                  '_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',
kallithea/tests/functional/test_pullrequests_git.py
Show inline comments
 
@@ -31,11 +31,25 @@ class TestPullrequestsController(base.Te
 
                                  '_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()
0 comments (0 inline, 0 general)