Skip to content

Commit 9732f91

Browse files
committed
create separate method to retrieve compliance alert
Signed-off-by: NucleonGodX <racerpro41@gmail.com>
1 parent f205c7c commit 9732f91

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

docs/policies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ REST API
136136
--------
137137

138138
For more details on retrieving compliance data through the REST API, see the
139-
:ref:`rest_api_compliance` section and :ref:`rest_api_clarity_compliance` section
139+
:ref:`rest_api_compliance` section and :ref:`rest_api_clarity_compliance` section.
140140

141141
Command Line Interface
142142
----------------------

scanpipe/management/commands/check-compliance.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ def check_compliance(self, fail_level):
7474
len(issues) for model in alerts.values() for issues in model.values()
7575
)
7676

77-
extra_data = self.project.extra_data or {}
78-
clarity_alert = extra_data.get("clarity_compliance_alert")
79-
80-
# Count clarity issue only if alert is not 'ok' or None
81-
clarity_issue_count = 1 if clarity_alert and clarity_alert != "ok" else 0
77+
clarity_alert = self.get_clarity_compliance_alert()
78+
has_clarity_issue = clarity_alert not in (None, "ok")
8279

83-
total_issues = count + clarity_issue_count
80+
total_issues = count + (1 if has_clarity_issue else 0)
8481

8582
if total_issues and self.verbosity > 0:
8683
self.stderr.write(f"{total_issues} compliance issues detected.")
@@ -91,12 +88,20 @@ def check_compliance(self, fail_level):
9188
if self.verbosity > 1:
9289
self.stderr.write(" " + "\n ".join(entries))
9390

94-
if clarity_issue_count:
91+
if has_clarity_issue:
9592
self.stderr.write("[License Clarity Compliance]")
9693
self.stderr.write(f" > Alert Level: {clarity_alert}")
9794

9895
return total_issues > 0
9996

97+
def get_clarity_compliance_alert(self):
98+
"""
99+
Return the clarity compliance alert value for the project,
100+
or None if not set.
101+
"""
102+
extra_data = self.project.extra_data or {}
103+
return extra_data.get("clarity_compliance_alert")
104+
100105
def check_vulnerabilities(self):
101106
packages = self.project.discoveredpackages.vulnerable_ordered()
102107
dependencies = self.project.discovereddependencies.vulnerable_ordered()

0 commit comments

Comments
 (0)