vscode-gitlens icon indicating copy to clipboard operation
vscode-gitlens copied to clipboard

Adds support for regex in autolinks

Open felipecrs opened this issue 3 years ago • 7 comments

Description

Adds support for autolink references based on regular expression for more advanced use cases, while keeping backwards compatibily with the existing prefix-based cases.

Additionally, it refactors the Gerrit autolinks to leverage the new option:

image

  • Closes #1903
  • Closes #1314
  • Closes #1121
  • Fixes #2251

Checklist

  • [x] I have followed the guidelines in the Contributing document
  • [x] My changes follow the coding style of this project
  • [x] My changes build without any errors or warnings
  • [x] My changes have been formatted and linted
  • [x] My changes include any required corresponding changes to the documentation (including CHANGELOG.md and README.md)
  • [x] My changes have been rebased and squashed to the minimal number (typically 1) of relevant commits
  • [x] My changes have a descriptive commit message with a short title, including a Fixes $XXX - or Closes #XXX - prefix to auto-close the issue that your PR addresses

Extras:

  • [ ] Make changes to the embedded settings browser (help welcome)
  • [ ] Properly handle escaped markdown (and probably HTML) matching

felipecrs avatar Oct 10 '22 04:10 felipecrs

Update: we can probably use regexp-tree to parse the regex and escape it properly for markdown and html.

felipecrs avatar Nov 17 '22 22:11 felipecrs

Ok, this is now working. The implementation may be a little rough though.

You can test with the following repo:

git clone https://review.gerrithub.io/felipecrs/gerrit-jenkins

And the last commit. It comes with a settings.json like:

{
  "gitlens.autolinks": [
    {
      "regex": "(JENKINS-[0-9]+)",
      "url": "https://issues.jenkins.io/browse/<num>"
    }
  ]
}

Demo:

https://user-images.githubusercontent.com/29582865/203101574-d11f2d46-f00b-48e2-aa06-66de52558f65.mp4

felipecrs avatar Nov 21 '22 16:11 felipecrs

This would be awesome and open up matching on JIRA ticket ids in branch names, ex: feat_proj_123

ajmath avatar Dec 14 '22 15:12 ajmath

@eamodio, any chance to get that merged? I just wanted to configure Gitlens once for all Jira projecs as well and was surprised that this was not working. I mentioned you, since you originally suggested to provide a PR here: https://github.com/gitkraken/vscode-gitlens/issues/1314#issuecomment-757370056 which @felipecrs already seems to have solved.

ahochsteger avatar Feb 23 '23 07:02 ahochsteger

Could we clarify what changes must be made to this implementation in order to get it merged (other than resolving conflicts)? Is the added dependency a dealbreaker, or could it be acceptable as an interim solution? Would love to see this functionality hit main!

hongtron avatar Jul 26 '23 15:07 hongtron

Seems like this issue, plus #1903, and #1314 would be solved by implementing this PR. Maybe an easy rebase + conflict resolution could result in hitting multiple bugs with one stone (😅 er... Pull Request).

In the VSCode Extension's current state, it's impossible to get autolinks working for any issue tracker that doesn't follow a simple PREFIX-<num> and URL pattern. That includes linking to issues on GitHub, GitLab, SourceHut, and probably many others. Seems that this feature was initially tied to JIRA and Atlassian products only, rendering autolinks useless for most other platforms.

trinitronx avatar Jun 11 '24 17:06 trinitronx

PS: I can rebase and resolve conflicts upon some maintainer green light.

felipecrs avatar Jun 11 '24 17:06 felipecrs

Will this PR be merged in the future?

ProudRabbit avatar Feb 11 '25 03:02 ProudRabbit