Skip to content

Commit

Permalink
Merge pull request #63 from melexis/remap
Browse files Browse the repository at this point in the history
Provide ability to re-link the TRACEABILITY_ITEM_ID
  • Loading branch information
Letme committed Feb 2, 2022
2 parents 273a9eb + d88a5aa commit ac53a48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ feature.
TRACEABILITY_ITEM_ID_REGEX = r"([A-Z_]+-[A-Z0-9_]+)"
Alter links to traceability items
=================================

If the item ID matched by *TRACEABILITY_ITEM_ID_REGEX* is incorrect, e.g. it does not exist in the collection of
traceability items, you can configure the plugin to link to the desired item ID instead.
Add the item ID returned by Coverity as a key to the Python dictionary *TRACEABILITY_ITEM_ID_REGEX* and the desired
item ID as value.

.. code-block:: python
TRACEABILITY_ITEM_RELINK = {
"STATIC_DEVIATE-MISRA_RULE_1_0": "STATIC_DEVIATE-MISRA_1_0",
}
Default config
==============

Expand All @@ -132,6 +146,7 @@ The plugin itself holds a default config that can be used for any Coverity proje
}
TRACEABILITY_ITEM_ID_REGEX = r"([A-Z_]+-[A-Z0-9_]+)"
TRACEABILITY_ITEM_RELINK = {}
This default configuration, which is built into the plugin, can be overridden through the *conf.py* of your project.

Expand Down
1 change: 1 addition & 0 deletions example/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,4 @@
}

TRACEABILITY_ITEM_ID_REGEX = r"([A-Z_]+-[A-Z0-9_]+)"
TRACEABILITY_ITEM_RELINK = {}
1 change: 1 addition & 0 deletions mlx/coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def setup(app):
'env')

app.add_config_value('TRACEABILITY_ITEM_ID_REGEX', r"([A-Z_]+-[A-Z0-9_]+)", 'env')
app.add_config_value('TRACEABILITY_ITEM_RELINK', {}, 'env')

app.add_node(CoverityDefect)

Expand Down
6 changes: 4 additions & 2 deletions mlx/coverity_item_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ def link_to_item_ids(contents, text, cid, app, docname):
text_before = remaining_text.split(item)[0]
if text_before:
contents.append(nodes.Text(text_before))
remaining_text = remaining_text.replace(text_before + item, '', 1)

if item in app.config.TRACEABILITY_ITEM_RELINK:
item = app.config.TRACEABILITY_ITEM_RELINK[item]
ref_node = make_internal_item_ref(app, docname, item, cid)
if ref_node is None: # no link could be made
ref_node = nodes.Text(item)
contents.append(ref_node)

remaining_text = remaining_text.replace(text_before + item, '', 1)

if remaining_text:
contents.append(nodes.Text(remaining_text)) # no URL or item ID in this text

Expand Down

0 comments on commit ac53a48

Please sign in to comment.