#4070 Make links act like links in the commit message
Merged 5 years ago by pingou. Opened 5 years ago by ryanlerch.
ryanlerch/pagure issue3242  into  master

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

          {% if splitted_message|length > 1 %}

          <pre class="commit_message_body">

              {% for message in splitted_message %}

-     {{ message }}

+     {{ message | linkify | safe}}

              {% endfor %}

          </pre>

          {% endif %}

file modified
+12
@@ -20,6 +20,7 @@ 

  import arrow

  import flask

  import six

+ import bleach

  

  from six.moves.urllib.parse import urlparse, parse_qsl

  from jinja2 import escape
@@ -74,6 +75,17 @@ 

      return arr.strftime("%Y-%m-%d %H:%M:%S %Z")

  

  

+ @UI_NS.app_template_filter("linkify")

+ def linkify_text(text):

+     """ escape all html tags with bleach, then use bleach to linkify

+     """

+     if text:

+         cleaned = bleach.clean(text, tags=[], attributes=[])

+         return bleach.linkify(cleaned)

+     else:

+         return ""

+ 

+ 

  @UI_NS.app_template_filter("format_loc")

  def format_loc(

      loc,

file modified
+4 -2
@@ -926,7 +926,8 @@ 

  

  

  def add_content_to_git(

-         folder, branch='master', filename='sources', content='foo'):

+         folder, branch='master', filename='sources', content='foo',

+         message=None):

      """ Create some more commits for the specified git repo. """

      repo, newfolder, branch_ref_obj = _clone_and_top_commits(

          folder, branch, branch_ref=True)
@@ -956,11 +957,12 @@ 

      committer = pygit2.Signature(

          'Cecil Committer', 'cecil@committers.tld')

      branch_ref = "refs/heads/%s" % branch

+     message = message or 'Add content to file %s' % (filename)

      repo.create_commit(

          branch_ref,  # the name of the reference to update

          author,

          committer,

-         'Add content to file %s' % (filename),

+         message,

          # binary string representing the tree object ID

          tree,

          # list of binary strings representing parents of the new commit

@@ -2878,6 +2878,83 @@ 

              'text-muted fa-fw" data-glyph="spreadsheet"></i>&nbsp;Commits'

              '\n    </a>', output_text)

  

+     def test_view_commit_with_full_link(self):

+         """ Test the view_commit endpoint when the commit message includes

+         an url. """

+ 

+         tests.create_projects(self.session)

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

+ 

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

+ 

+         # Add a README to the git repo - First commit

+         tests.add_readme_git_repo(folder)

+         tests.create_projects_git(folder, bare=True)

+         # Add a commit with an url in the commit message

+         tests.add_content_to_git(

+             folder, branch='master', filename='sources', content='foo',

+             message='Test commit message\n\n'

+             'Fixes http://example.com/pagure/issue/2'

+         )

+ 

+         # Add a README to the git repo - First commit

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

+         commit = repo.revparse_single('HEAD')

+ 

+         # View first commit

+         output = self.app.get('/test/c/%s' % commit.oid.hex)

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             '#commit-overview-collapse',

+             output_text)

+         self.assertIn(

+             '<pre class="commit_message_body">\n    '

+             'Test commit message\n    \n    '

+             'Fixes <a href="http://example.com/pagure/issue/2" '

+             'rel="nofollow">http://example.com/pagure/issue/2</a>\n        '

+             '</pre>', output_text)

+         self.assertIn(

+             '<div class="btn btn-outline-success disabled opacity-100 '

+             'border-0 font-weight-bold">file added</div>', output_text)

+ 

+     def test_view_commit_with_short_link(self):

+         """ Test the view_commit endpoint when the commit message includes

+         an url. """

+ 

+         tests.create_projects(self.session)

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

+ 

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

+ 

+         # Add a README to the git repo - First commit

+         tests.add_readme_git_repo(folder)

+         tests.create_projects_git(folder, bare=True)

+         # Add a commit with an url in the commit message

+         tests.add_content_to_git(

+             folder, branch='master', filename='sources', content='foo',

+             message='Test commit message\n\nFixes #2'

+         )

+ 

+         # Add a README to the git repo - First commit

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

+         commit = repo.revparse_single('HEAD')

+ 

+         # View first commit

+         output = self.app.get('/test/c/%s' % commit.oid.hex)

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             '#commit-overview-collapse',

+             output_text)

+         self.assertIn(

+             '<pre class="commit_message_body">\n    '

+             'Test commit message\n    \n    '

+             'Fixes #2\n        </pre>', output_text)

+         self.assertIn(

+             '<div class="btn btn-outline-success disabled opacity-100 '

+             'border-0 font-weight-bold">file added</div>', output_text)

+ 

      def test_view_commit_patch(self):

          """ Test the view_commit_patch endpoint. """

  

Previously, links in the commit messages on the commit
detail page were just plain text. This makes them <a>'s
that are clickable.

Fixes #3242

Could we add some tests for this?

hmmm, do we actaully test the commit message view at the moment?

I cant seem to find the test where we do that (if we do). Thought this would be the logical place to test this new functionalty.

We may need a new test for this, but I'd think we test view_commit somewhere

rebased onto 3ec4255

5 years ago

I have rebased and added tests to this PR.

If Jenkins passes, let's get this in :)

Pull-Request has been merged by pingou

5 years ago