Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expressions in autolinks #1314

Open
jameswilson opened this issue Jan 9, 2021 · 10 comments · May be fixed by #2255
Open

Regular expressions in autolinks #1314

jameswilson opened this issue Jan 9, 2021 · 10 comments · May be fixed by #2255
Labels
area-autolinks Issues or features related to autolinks feature New feature or request help wanted Want community input and/or pull request
Milestone

Comments

@jameswilson
Copy link

jameswilson commented Jan 9, 2021

The use case that describes Autolink usage with JIRA and discussed originally on #897, is not as robust as it could be.

Current example:

 "gitlens.autolinks": [
   { "prefix": "JIRA-", "url": "https://jira.company.com/issue?query=<num>" }
 ]
  • The feature requires a prefix of JIRA-, but in the real world, each project has a different prefix, this means you have to literally configure this setting for every VSCode project. Too much work to maintain.
  • The feature only looks for a <num> which I assume to be a numeric value, but in the real world Jira on Atlassian Cloud needs both the project ID AND the issue number together to navigate you to the issue. The URLs look something like this http://<company>.atlassian.net/browse/JIRA-123 where JIRA is the project id and 123 is the issue number. Again, this could be manually done for each repository but this could be simplified with a regular expression pattern match.

This feature request would be to expand the configuration to support regular expression pattern matching using parentheses to capture the necessary info into a group, and then use backreferences like $1 for each capture group in the URL replacement.

Proposed example:

"gitlens.autolinks": [
  { "regex": "(\b\w+[-]\d+\b)", "url": "https://<company>.atlassian.net/browse/$1" }
]

The feature would need to be able to run multiple times over a commit message, in case multiple issues are referenced, all of them need to be linked.

The feature would need to support multi-line commit messages.

Example of the pattern being used above
https://regex101.com/r/0tABhu/1

@jameswilson jameswilson added feature New feature or request triage Needs to be looked at labels Jan 9, 2021
@eamodio
Copy link
Member

eamodio commented Jan 9, 2021

Sounds like a good idea. Would you mind opening a PR to add it or get it started? I'd be happy to help point in the right direction, etc.

@eamodio eamodio added help wanted Want community input and/or pull request and removed triage Needs to be looked at labels Jan 9, 2021
@eamodio eamodio added this to the Backlog milestone Jan 9, 2021
@jameswilson
Copy link
Author

Where to get started? Is this the right file?

https://github.com/eamodio/vscode-gitlens/blob/main/src/annotations/autolinks.ts

@eamodio
Copy link
Member

eamodio commented Jan 12, 2021

@jameswilson yup, that where they are detected.

Here is the config type that will need to be expanded
https://github.com/eamodio/vscode-gitlens/blob/36913a35522123256fb2d8fb6c5556069702dcb5/src/config.ts#L151-L157

And those get turned into these:
https://github.com/eamodio/vscode-gitlens/blob/4c7366a345b4a66a0d408204657972cdd3675170/src/annotations/autolinks.ts#L12-L16

So you can probably do some parsing here:
https://github.com/eamodio/vscode-gitlens/blob/4c7366a345b4a66a0d408204657972cdd3675170/src/annotations/autolinks.ts#L46

To turn the regex on the config items into messageRegex and/or messageMarkdownRegex, and then I think a lot of the rest of the code will just work (in theory)

@chrisyly
Copy link

@eamodio
Want to following up on this interesting feature.
I have a request to autolink to external source:
some_prefix_string: 123, 456

In above case, I want to enable autolink for 123 and 456 to:
https://someurl.com/#/123 and https://someurl.com/#/456

As jameswilson pointed out, it would be great if we can use regex match to do the job

@armchairdeity
Copy link

Umm... tap tap tap is this thing on? Could someone please merge this? I can't use auto links till they're enhanced a bit. Our JIRA installation has no less than 350 projects listed... I'm not adding 350 config blocks to manually maintain. But until this feature is merged and released there will be NO using auto link for me. Which means any thought of buying GitLens is out, period. Your loss folks... this ticket has been sitting here for 2 months... seriously...

@tappin-kr
Copy link

Would love to see this happen

@alexander-williamson
Copy link

Any resurrection of this?

@handonam
Copy link

plz merge those PRs, don't want to keep making new autolinks every time i see a new board. kills momentum

@ferlix
Copy link

ferlix commented Mar 17, 2024

El caso de uso que describe el uso de Autolink con JIRA y que se analizó originalmente en el n.° 897 no es tan sólido como podría ser.

Ejemplo actual:

 "gitlens.autolinks": [
   { "prefix": "JIRA-", "url": "https://jira.company.com/issue?query=<num>" }
 ]
  • La función requiere un prefijo de JIRA-, pero en el mundo real, cada proyecto tiene un prefijo diferente, esto significa que literalmente debe configurar esta configuración para cada proyecto de VSCode. Demasiado trabajo para mantener.
  • La función solo busca un <num> valor que supongo que es numérico, pero en el mundo real Jira en Atlassian Cloud necesita tanto el ID del proyecto como el número del problema juntos para llegar al problema. Las URL se ven así, http://<company>.atlassian.net/browse/JIRA-123 donde JIRAestá la identificación del proyecto y 123el número de problema. Nuevamente, esto podría hacerse manualmente para cada repositorio, pero podría simplificarse con una coincidencia de patrón de expresión regular.

Esta solicitud de función sería expandir la configuración para admitir la coincidencia de patrones de expresiones regulares usando paréntesis para capturar la información necesaria en un grupo y luego usar referencias retrospectivas como $1para cada grupo de captura en el reemplazo de URL.

Ejemplo propuesto:

"gitlens.autolinks": [
  { "regex": "(\b\w+[-]\d+\b)", "url": "https://<company>.atlassian.net/browse/$1" }
]

La función debería poder ejecutarse varias veces en un mensaje de confirmación; en caso de que se haga referencia a varios problemas, todos deben estar vinculados.

La función debería admitir mensajes de confirmación de varias líneas.

Ejemplo del patrón utilizado anteriormente https://regex101.com/r/0tABhu/1

@xianghongai
Copy link

xianghongai commented Jun 18, 2024

  • Regular Expression: [A-Z]+\-\d+
  • Replacement Expression: https://jira.your-inc.cn/browse/$0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-autolinks Issues or features related to autolinks feature New feature or request help wanted Want community input and/or pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants