vscode-gitlens
vscode-gitlens copied to clipboard
Regular expressions in autolinks
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 thishttp://<company>.atlassian.net/browse/JIRA-123
whereJIRA
is the project id and123
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
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.
Where to get started? Is this the right file?
https://github.com/eamodio/vscode-gitlens/blob/main/src/annotations/autolinks.ts
@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)
@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
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...
Would love to see this happen
Any resurrection of this?
plz merge those PRs, don't want to keep making new autolinks every time i see a new board. kills momentum
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
dondeJIRA
está la identificación del proyecto y123
el 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
$1
para 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
- Regular Expression:
[A-Z]+\-\d+
- Replacement Expression:
https://jira.your-inc.cn/browse/$0