Skip to content
Snippets Groups Projects

Fold links to files in GFM

What does this MR do?

Fold all URLs that reference a tree or a blob into a more user friendly format.

Are there points in the code the reviewer needs to double check?

Why was this MR needed?

To show URL references in a nicer way.

Screenshots (if relevant)

Screenshot_from_2016-08-28_18_42_22

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes #14225 (moved)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 14 end
    15
    16 doc
    17 end
    18
    19 protected
    20
    21 def process_link(node)
    22 href = node.attribute('href').value
    23
    24 id = href.match(LINK_PATTERN).captures[2]
    25 target_project = href.match(%r{#{internal_url}/(\S+)/(blob|tree)/(?<!,|\.)}).captures[0]
    26
    27 current_project = context[:project]
    28
    29 @project = Project::find_with_namespace(target_project)
  • Thanks @SvenDub, this looks great! 🎉 I think there are some cases that have been missed, but things are in good shape so far.

  • Added ~164274 label

  • Added 1 commit:

    • 4ce989a1 - Check for the existence of a project
  • Thanks! This is my first MR to GitLab so please let me know if I miss something 🙂

  • @SvenDub do you think you'll be able to work on this any more? If not, let me know and someone can take it over (you'll still get credit). It would be great to have this feature!

  • @smcgivern Certainly! I wasn't sure what to do with this and lost it out of sight for a bit. Should I check for the existence of a project and run the database query as is the case now, or should I generate the link anyway?

  • @SvenDub sorry, I lost track of this again 😞

    I think it would be interesting to treat this like commits, like I mentioned. There are differences, but they aren't insurmountable:

    1. We don't want to actually load the Blob when it's been referred to, because that would be horrific. I think we can assume it exists if extract_ref returns something sensible. We could either add a Blob.from_reference class, or create a special BlobReference class. The latter might be clearer as it would share very little functionality with the 'real' Blob, instead just mixing in and implementing methods from Referable.
    2. We don't want to round-trip these. This can be resolved by making the reference_pattern class method on Blob[Reference] return nil.

    This gives us the reference redaction 'for free' in the case where the project doesn't exist, and we can assume that the existing reference redaction etc. code is reasonably performant. This is all a bit high level, but let me know what you think and I can point you in the right direction 🙂

  • username-removed-128633 added ~874211 ~480950 ~159098 markdown labels

    added ~874211 ~480950 ~159098 markdown labels

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading