linkDetect only applies the first rule

This issue has been tracked since 2022-09-16.

Hi,

When i set up multiple linkDetect rules, only the first one works. In the example below, only the first rule creates links. If I comment out the first rule, then the second works fine.

Using v0.108

silences:
  comments:
    linkDetect:
      rules:
        - regex: "#([0-9]{2,5})"
          uriTemplate: https://gitlab.example.com/issues/$1
        - regex: "#([0-9]{6,})"
          uriTemplate: https://helpdesk.example.com/ticket.html?id=$1
prymitive wrote this answer on 2022-09-18

Those rules are used to turn part of a comment into a clickable link if it matches given pattern.
What would you expect to happen with multiple matches? You can't really have a link that points to multiple URLs.

heapdavid wrote this answer on 2022-09-18

Yep I'm trying to create links to different ticket/issue tracking systems depending on the format.

For example:

  • #1234 would match the first rule and create a link to gitlab.
  • #123456 would match the second rule and create a link to helpdesk.

I would expect the regex for each rule in the list to checked in order, and then create the link and stop progressing through the list on first match.

prymitive wrote this answer on 2022-09-18

Isn't #([0-9]{2,5}) going to match both #1234 and #123456?
It's matching part of a string but still, it's a match.
Try reordering your rules.

heapdavid wrote this answer on 2022-09-18

Ah ok, that works now, so sorry to waste your time!

More Details About Repo
Owner Name prymitive
Repo Name karma
Full Name prymitive/karma
Language TypeScript
Created Date 2018-09-09
Updated Date 2023-03-17
Star Count 1921
Watcher Count 33
Fork Count 166
Issue Count 2

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date