gitkraken / vscode-gitlens

Supercharge Git inside VS Code and unlock untapped knowledge within each repository — Visualize code authorship at a glance via Git blame annotations and CodeLens, seamlessly navigate and explore Git repositories, gain valuable insights via rich visualizations and powerful comparison commands, and so much more
http://gitkraken.com/gitlens
Other
8.91k stars 1.26k forks source link

Regular expressions in autolinks #1314

Open jameswilson opened 3 years ago

jameswilson commented 3 years ago

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>" }
 ]

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

eamodio commented 3 years ago

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.

jameswilson commented 3 years ago

Where to get started? Is this the right file?

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

eamodio commented 3 years ago

@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 commented 2 years ago

@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 commented 1 year ago

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 commented 1 year ago

Would love to see this happen

alexander-williamson commented 6 months ago

Any resurrection of this?

handonam commented 5 months ago

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

ferlix commented 5 months ago

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 commented 2 months ago