#4406 Add support for viewing and commiting to a utf-8 branch name
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

file modified
+1 -1
@@ -22,4 +22,4 @@ 

  git --no-pager log -2

  fi

  

- tox -v --sitepackages -e 'py34-flask100-ci' -- --results=results

+ tox -v --sitepackages -e 'py35-flask100-ci' -- --results=results

file modified
+5 -1
@@ -480,10 +480,14 @@ 

      changes = {}

      if from_stdin:

          for line in sys.stdin:

-             (oldrev, newrev, refname) = line.strip().split(" ", 2)

+             (oldrev, newrev, refname) = str(line).strip().split(str(" "), 2)

+             if six.PY2:

+                 refname = refname.decode("utf-8")

              changes[refname] = (oldrev, newrev)

      else:

          (refname, oldrev, newrev) = sys.argv[1:]

+         if six.PY2:

+             refname = refname.decode("utf-8")

          changes[refname] = (oldrev, newrev)

      return changes

  

@@ -7,103 +7,103 @@ 

  {% block repo %}

  <div class="row">

    <div class="col">

-       {% block overviewtabs %}{{ super() }}{% endblock %}

+     {% block overviewtabs %}{{ super() }}{% endblock %}

    </div>

    <div class="col-10">

      <h3 class="font-weight-bold">

-     Branches <span class="badge badge-secondary">{{g.branches|length}}</span>

+       Branches <span class="badge badge-secondary">{{g.branches|length}}</span>

      </h3>

      <div class="list-group">

-         {% if head %}

-         <div id="branch-{{ head }}" class="list-group-item">

-             <div class="row align-items-center">

-                 <div class="col">

-                     <span class="fa fa-random fa-fw text-muted"></span>

-                     <a href="{{ url_for('ui_ns.view_tree',

-                         repo=repo.name,

-                         username=username,

-                         namespace=repo.namespace,

-                         identifier=head) }}"

-                         title="{{ head }}" data-toggle="tooltip"

-                         class="font-weight-bold">

-                         {{ head }}

-                     </a>

-                 </div>

-                 <div class="col-xs-auto pl-2">

-                     <button class="btn btn-outline-light bg-white border-white" title="this is the default branch for this project">

-                     <span class="fa fa-star fa-fw text-warning"></span>

-                     </button>

-                 </div>

-             </div>

+       {% if head %}

+       <div id="branch-{{ head }}" class="list-group-item">

+         <div class="row align-items-center">

+           <div class="col">

+             <span class="fa fa-random fa-fw text-muted"></span>

+             <a href="{{ url_for('ui_ns.view_tree',

+               repo=repo.name,

+               username=username,

+               namespace=repo.namespace,

+               identifier=head) }}"

+               title="{{ head }}" data-toggle="tooltip"

+               class="font-weight-bold">

+               {{ head }}

+             </a>

+           </div>

+           <div class="col-xs-auto pl-2">

+             <button class="btn btn-outline-light bg-white border-white" title="this is the default branch for this project">

+             <span class="fa fa-star fa-fw text-warning"></span>

+             </button>

+           </div>

          </div>

-         {% endif %}

+       </div>

+       {% endif %}

  

-         {% for branch in g.branches if branch != head %}

-         <div id="branch-{{ branch | replace('/', '__')}}" class="list-group-item">

-                 <div class="row align-items-center">

-                     <div class="col">

-                         <span class="fa fa-random fa-fw text-muted"></span>

-                         <a class="font-weight-bold" href="{{ url_for('ui_ns.view_tree',

+       {% for branch in g.branches if branch != head %}

+         <div id="branch-{{ branch | unicode | replace('/', '__')}}" class="list-group-item">

+           <div class="row align-items-center">

+             <div class="col">

+               <span class="fa fa-random fa-fw text-muted"></span>

+               <a class="font-weight-bold" href="{{ url_for('ui_ns.view_tree',

+                 repo=repo.name,

+                 username=username,

+                 namespace=repo.namespace,

+                 identifier=branch) }}"

+                 title="{{ branch | unicode }}" data-toggle="tooltip">{{ branch | unicode }}

+               </a>

+               <small class="text-muted commits_ahead_label"></small>

+             </div>

+             <div class="col-xs-auto pr-2">

+               <div class="branch_del">

+                 <div class="btn-group">

+                     <a class="btn btn-outline-primary" href="{{ url_for('ui_ns.view_tree',

+                       repo=repo.name,

+                       username=username,

+                       namespace=repo.namespace,

+                       identifier=branch) }}"

+                       title="view code tree for this branch">

+                     <i class="fa fa-fw fa-file-code-o"></i>

+                     </a>

+                     <a class="btn btn-outline-primary" href="{{ url_for('ui_ns.view_commits',

+                       repo=repo.name,

+                       username=username,

+                       namespace=repo.namespace,

+                       identifier=branch,

+                       branchname=branch) }}"

+                       title="view commit list for this branch">

+                     <i class="fa fa-fw fa-list-alt"></i>

+                     </a>

+                 </div>

+                 {% if g.repo_committer and branch != head

+                       and (

+                         config.get('ALLOW_DELETE_BRANCH', True)

+                         or repo.is_fork) %}

+                   <form id="delete_branch_form-{{

+                       branch | unicode | replace('/', '__') | replace('+', '___')

+                     }}" action="{{

+                     url_for('ui_ns.delete_branch',

                              repo=repo.name,

                              username=username,

                              namespace=repo.namespace,

-                             identifier=branch) }}"

-                             title="{{ branch }}" data-toggle="tooltip">{{ branch }}

-                         </a>

-                         <small class="text-muted commits_ahead_label"></small>

-                     </div>

-                     <div class="col-xs-auto pr-2">

-                             <div class="branch_del">

-                                 <div class="btn-group">

-                                     <a class="btn btn-outline-primary" href="{{ url_for('ui_ns.view_tree',

-                                         repo=repo.name,

-                                         username=username,

-                                         namespace=repo.namespace,

-                                         identifier=branch) }}"

-                                         title="view code tree for this branch">

-                                     <i class="fa fa-fw fa-file-code-o"></i>

-                                     </a>

-                                     <a class="btn btn-outline-primary" href="{{ url_for('ui_ns.view_commits',

-                                         repo=repo.name,

-                                         username=username,

-                                         namespace=repo.namespace,

-                                         identifier=branch,

-                                         branchname=branch) }}"

-                                         title="view commit list for this branch">

-                                     <i class="fa fa-fw fa-list-alt"></i>

-                                     </a>

-                                 </div>

-                                 {% if g.repo_committer and branch != head

-                                       and (

-                                         config.get('ALLOW_DELETE_BRANCH', True)

-                                         or repo.is_fork) %}

-                                     <form id="delete_branch_form-{{

-                                         branch | replace('/', '__') | replace('+', '___')

-                                         }}" action="{{

-                                         url_for('ui_ns.delete_branch',

-                                                 repo=repo.name,

-                                                 username=username,

-                                                 namespace=repo.namespace,

-                                                 branchname=branch)

-                                         }}" method="post" class="icon d-inline"

-                                         onsubmit="return confirm('Are you sure you want to remove the branch: {{ branch }}?\nThis cannot be un-done!');">

-                                         {{ g.confirmationform.csrf_token }}

-                                         <a title="Remove branch {{ branch }}" href="#"

-                                         class="btn btn-outline-danger"

-                                         onclick="$('#delete_branch_form-{{

-                                             branch | replace('/', '__') | replace('.', '\\\\.')

-                                             | replace('+', '___')

-                                             }}').submit();">

-                                         <i class="fa fa-trash"></i>

-                                         </a>

-                                     </form>

-                                 {% endif %}

-                             </div>

-                     </div>

-                 </div>

+                             branchname=branch)

+                     }}" method="post" class="icon d-inline"

+                     onsubmit="return confirm('Are you sure you want to remove the branch: {{ branch | unicode }}?\nThis cannot be un-done!');">

+                     {{ g.confirmationform.csrf_token }}

+                     <a title="Remove branch {{ branch | unicode }}" href="#"

+                       class="btn btn-outline-danger"

+                       onclick="$('#delete_branch_form-{{

+                         branch | unicode | replace('/', '__') | replace('.', '\\\\.')

+                         | replace('+', '___')

+                         }}').submit();">

+                       <i class="fa fa-trash"></i>

+                     </a>

+                   </form>

+                 {% endif %}

+               </div>

              </div>

-         {% endfor %}

+           </div>

          </div>

+       {% endfor %}

+     </div>

    </div>

  </div>

  {% endblock %}
@@ -130,20 +130,20 @@ 

  

        {% if repo.is_fork %}

        html2 = ' \

-             <a class="btn btn-outline-primary border-white" data-toggle="tooltip" \

-             href="' + url + '" title="' + branch +' contains '

-              + nb_commits + ' commit not in the upstream project '

-              + nb_target + ' branch. Click to create new PR now.'

-              + '"><i class="fa fa-fw fa-arrow-circle-down"></i> Open Pull Request</a> \

-             </div>';

+         <a class="btn btn-outline-primary border-white" data-toggle="tooltip" \

+         href="' + url + '" title="' + branch +' contains '

+          + nb_commits + ' commit not in the upstream project '

+          + nb_target + ' branch. Click to create new PR now.'

+          + '"><i class="fa fa-fw fa-arrow-circle-down"></i> Open Pull Request</a> \

+         </div>';

        {% else %}

        html2 = ' \

-             <a class="btn btn-outline-primary border-white" data-toggle="tooltip" \

-             href="' + url + '" title="' + branch +' contains '

-              + nb_commits + ' commit not in the ' + nb_target

-              + ' branch. Click to create new PR now.'

-              + '"><i class="fa fa-fw fa-arrow-circle-down"></i> Open Pull Request</a> \

-             </div>';

+         <a class="btn btn-outline-primary border-white" data-toggle="tooltip" \

+         href="' + url + '" title="' + branch +' contains '

+          + nb_commits + ' commit not in the ' + nb_target

+          + ' branch. Click to create new PR now.'

+          + '"><i class="fa fa-fw fa-arrow-circle-down"></i> Open Pull Request</a> \

+         </div>';

        {%endif%}

        var _b = branch.replace(/\./g, '\\.').replace('/', '__').replace('\+', '\\+');

        $('#branch-' + _b + ' .branch_del').prepend(html2);
@@ -154,11 +154,11 @@ 

  

      for (branch in res.branch_w_pr){

        var html = ' \

-           <a class="btn btn-outline-success border-white" data-toggle="tooltip" '

-            + 'href="{{ request.url_root }}' + res.branch_w_pr[branch]

-            + '"title="' + branch +' is already in an opened pull-request">'

-            + '<i class="fa fa-fw fa-arrow-circle-down"></i> Pull Request #' + res.branch_w_pr[branch].split('/').slice(-1)[0]  + ' </a> \

-           </div>';

+         <a class="btn btn-outline-success border-white" data-toggle="tooltip" '

+          + 'href="{{ request.url_root }}' + res.branch_w_pr[branch]

+          + '"title="' + branch +' is already in an opened pull-request">'

+          + '<i class="fa fa-fw fa-arrow-circle-down"></i> Pull Request #' + res.branch_w_pr[branch].split('/').slice(-1)[0]  + ' </a> \

+         </div>';

        $('#branch-' + branch.replace(/\./g, '\\.').replace('/', '__')

          + ' .branch_del').prepend(html);

        $('[data-toggle="tooltip"]').tooltip({placement : 'bottom'});

file modified
+3
@@ -2564,6 +2564,9 @@ 

              "this project",

          )

  

+     if six.PY2:

+         branchname = branchname.encode("utf-8")

+ 

      if branchname == "master":

          flask.abort(

              403, description="You are not allowed to delete the master branch"

file modified
+1 -1
@@ -438,7 +438,7 @@ 

                  "pagure/hooks/files/hookrunner"

              ])

              subprocess.check_call([

-                 "sed", "-i", "-e", "s|['alembic',|['alembic-2',|",

+                 "sed", "-i", "-e", "s|\['alembic',|\['alembic-2',|",

                  "tests/test_alembic.py"

              ])

          elif pyvers[0] == 3:

@@ -21,6 +21,7 @@ 

  import os

  

  import pygit2

+ import six

  from mock import ANY, patch, MagicMock

  

  sys.path.insert(0, os.path.join(os.path.dirname(
@@ -5467,6 +5468,42 @@ 

              self.assertNotIn(

                  '<form id="delete_branch_form-feature__foo"', output_text)

  

+     def test_delete_branch_unicode(self):

+         """ Test the delete_branch endpoint with an unicode branch. """

+ 

+         tests.create_projects(self.session)

+         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)

+ 

+         user = tests.FakeUser(username='pingou')

+         with tests.user_set(self.app.application, user):

+ 

+             # Add a branch that we can delete

+             path = os.path.join(self.path, 'repos', 'test.git')

+             tests.add_content_git_repo(path)

+             repo = pygit2.Repository(path)

+             branchname = '☃️'

+             if six.PY2:

+                 branchname = branchname.encode("utf-8")

+             repo.create_branch(branchname, repo.head.peel())

+ 

+             # Check before deletion

+             output = self.app.get('/test')

+             self.assertEqual(output.status_code, 200)

+ 

+             output = self.app.get('/test/branches')

+             output_text = output.get_data(as_text=True)

+             self.assertIn('<form id="delete_branch_form-☃️"', output_text)

+ 

+             # Delete the branch

+             output = self.app.post('/test/b/☃️/delete', follow_redirects=True)

+             self.assertEqual(output.status_code, 200)

+ 

+             # Check after deletion

+             output = self.app.get('/test/branches')

+             output_text = output.get_data(as_text=True)

+             self.assertNotIn(

+                 '<form id="delete_branch_form-☃️"', output_text)

+ 

      @patch.dict('pagure.config.config', {'ALLOW_DELETE_BRANCH': False})

      def test_delete_branch_disabled_in_ui(self):

          """ Test that the delete branch button doesn't show when the feature

file modified
+1 -1
@@ -1,5 +1,5 @@ 

  [tox]

- envlist = py{27,34,35,36,37}-flask{100,01{1,2}}

+ envlist = py{27,35,36,37}-flask{100,01{1,2}}

  skipsdist = True

  

  

no initial comment

:thumbsup:

Looks fine for me ;)

I think I have a fix for the tests :)

5 new commits added

  • Add a test for viewing a branch named ☃️
  • Make the hook mechanism support utf-8 branch names
  • Some more indentation fixes in the HTML of repo_branches
  • Fix showing branches having unicode characters in their names
  • Adjust the indentation in the HTML of the repo_branches template
5 years ago

6 new commits added

  • Fix the sed command to run alembic in the tests in py2
  • Add a test for viewing a branch named ☃️ andensure it passes
  • Make the hook mechanism support utf-8 branch names
  • Some more indentation fixes in the HTML of repo_branches
  • Fix showing branches having unicode characters in their names
  • Adjust the indentation in the HTML of the repo_branches template
5 years ago

rebased onto c36e8b9

5 years ago

pretty please pagure-ci rebuild

5 years ago

pretty please pagure-ci rebuild

5 years ago

1 new commit added

  • Move the pip env from python 3.4 to python 3.5
5 years ago

Ok, I'm going to go ahead and merge this one, I believe the last commit should fix the pip-based environment and the first two environment are passing their tests :)

Thanks for the review! :)

Pull-Request has been merged by pingou

5 years ago