Skip to content

Commit

Permalink
Remove def.ws prefix from aggregate sarifreport
Browse files Browse the repository at this point in the history
This will replace the default workspace prefix
from when creating the aggregate sarif report output.
(def. megalinter-reports.sarif).

In other words, the artifact uri will be

/root/path/of/source/code

instead of as of now:

DEFAULT_WORKSPACE/root/path/of/source/code.

As the DEFAULT_WORKSPACE might only exist during
runtime, it needs to be removed.

Signed-off-by: Josef Andersson <josef.andersson@gmail.com>
  • Loading branch information
janderssonse committed Dec 19, 2022
1 parent 9beb4d0 commit e2e2337
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions megalinter/reporters/SarifReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,22 @@ def fix_sarif(self, linter_sarif_obj, linter: Linter):
# Update run in full list
linter_sarif_obj["runs"][id_run] = run
return linter_sarif_obj

# If DEFAULT_WORKSPACE is set, don't add that to the SARIF-report prefix
def fix_default_workspace_prefix(self, artifactLocation):
default_workspace = config.get("DEFAULT_WORKSPACE", "")
if default_workspace:
if artifactLocation["uri"].startswith(default_workspace):
artifactLocation["uri"] = artifactLocation["uri"].replace(default_workspace,"",1)
return artifactLocation["uri"]

# Replace startLine and endLine in region or contextRegion
def fix_sarif_physical_location(self, physical_location):

for location_key in physical_location.keys():
location_item = physical_location[location_key]
if "uri" in location_item and location_key == "artifactLocation":
location_item["uri"] = self.fix_default_workspace_prefix(location_item)
if "startLine" in location_item and location_item["startLine"] == 0:
location_item["startLine"] = 1
if "endLine" in location_item and location_item["endLine"] == 0:
Expand Down

0 comments on commit e2e2337

Please sign in to comment.