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

Use backreferences in variables #16

Open
HarHarLinks opened this issue Feb 23, 2024 · 2 comments
Open

Use backreferences in variables #16

HarHarLinks opened this issue Feb 23, 2024 · 2 comments

Comments

@HarHarLinks
Copy link

Building on the nitter sample, it would be pretty neat if we could do this:

templates:
    issue:
        type: m.room.message
        content:
            msgtype: m.text
            body: ${{URL}}

default_flags:
- ignorecase

rules:
    github:
        matches:
        - \#(\d+)
        template: issue
        variables:
            URL: https://github.com/my/project/issue/${{1}}
    jira:
        matches:
        - [^#](\d+)
        template: issue
        variables:
            URL: https://jira.atlassian.com/browse/ABC-${{1}}
@tulir
Copy link
Member

tulir commented Feb 23, 2024

Rule variables are meant to be static. Just rename the rule variable to url_prefix and move the reference from the variable to the template. You could even have the variable itself be a primitive template which is evaluated inside the template (you can have jinja2 in template variables or as the template content, e.g. https://github.com/maubot/reactbot/blob/master/samples/random-reaction.yaml#L6)

@HarHarLinks
Copy link
Author

Just rename the rule variable to url_prefix

right, that works for the given case. my example does not cover this, but as you have more complex cases (e.g. URLs aren't just prefixes anymore) or are made up of multiple parts, I'm back to code/yaml duplication, no?

@HarHarLinks HarHarLinks changed the title Usebackreferences in variables Use backreferences in variables Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants