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

Provide ability to re-link the TRACEABILITY_ITEM_ID #63

Merged
merged 3 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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