useblocks / sphinx-needs-enterprise

Sphinx-Needs Functions for enterprise users
http://useblocks.com/sphinx-needs-enterprise/
Other
5 stars 0 forks source link

Service Config: Concatenation of values in mappings #56

Closed Rubyfi closed 1 year ago

Rubyfi commented 2 years ago

I'm currently working on a tool that exports Needs from a codebeamer instance. I'd like to store the link to the codebeamer issue a need was generated from in a separate field (instead of the description like in the example). My config currently looks something like this:

cb_server = "https://example.org"
cb_content = f"Codebeamer Link: {{{{data.id}}}} <{cb_server}/issue/{{{{data.id}}}}>`_"""
cb_link = f'{cb_server}/issue/{{{{data.id}}}}'

needs_services = {
    "codebeamer": {
        "url": cb_server,
        "user": "sphinx-needs",
        "password": "sphinx-needs4pace",
        "content": cb_content,
        "query": "project.name IN ('CODEX')",
        "id_prefix": "REQ_",
        "mappings": {
            "id": ["id"],
            "type": ["typeName"],
            "title": ["name"],
            "docname": ["id"],
            "link": cb_link
        }
    }
}

However, in the mapping, the ID value isn't properly substituted:

"REQ_1": {
  "description": "Codebeamer Link: 1 <https://example.org/issue/1>`_\n\n|",
  "id": "REQ_1",
  "link": "https://example.org/issue/{{data.id}}",
   "title": "...",
 }

While there is a workaround in this use-case, I was wondering whether this is possible in the configuration.

danwos commented 2 years ago

This got solved with #50, which supports jinja in mapping fields. But it is not released yet.

Another solution could be to use needs_string_links: https://sphinxcontrib-needs.readthedocs.io/en/latest/configuration.html#needs-string-links And just add the ID as an option value. need_string_links converts this then to a codebeamer-specific link.

Rubyfi commented 1 year ago

Thank you for the input, I'm using the sne command-line tool to generate a needs.json. I had a look at needs_string_links but sne does not seem to recognise this option. Nevertheless, my current workaround is to use a post-processing script after the export to insert the link. This sufficient for now.