-
Notifications
You must be signed in to change notification settings - Fork 4
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
Sast rescoring update #270
base: master
Are you sure you want to change the base?
Conversation
79f7529
to
5106da9
Compare
5106da9
to
a3c0361
Compare
a3c0361
to
2f3b3ba
Compare
return None | ||
|
||
|
||
def rescore_sast_severity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function should work for all types of rescoring-rule no?
can we merge / factor out with existing bdba rescoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems you decided against my suggestion, which of course is fine, but could you please elaborate what lead to this decision?
looking only at the PR I do not see a good reason against 🤔
2f3b3ba
to
9895c5f
Compare
9895c5f
to
13f4f76
Compare
13f4f76
to
2bf0120
Compare
@TuanAnh17N : I assume test-errors stem from dependency against (unreleased) changes in cc-utils? If so, then I suggest to first merge and release change for cc-utils + rerun tests here to be sure. |
2bf0120
to
4ca5d08
Compare
sast_config: config.SASTConfig, | ||
component_descriptor_lookup: cnudie.retrieve.ComponentDescriptorLookupById, | ||
) -> list[str]: | ||
if sast_config.component_version: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mv to caller, this function should only get versions from time range -> SoC
also, can we please use a more meaningful function name, e.g. version_from_time_range
?
if sast_config.component_version: | ||
return [sast_config.component_version] | ||
|
||
version_lookup = lookups.init_version_lookup() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather pass in version-lookup (dependency injection)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also: consistency (why pass-in component-descriptor-lookup, but not version-lookup)
if not (pv := versionutil.parse_to_semver( | ||
version=v, | ||
invalid_semver_ok=False, | ||
)).prerelease and not pv.build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version filtering is good, but I suggest to at least make it configurable via function parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have a util-function for that in cc-util's version.py
(at least is_final
comes to my mind)
|
||
versions = [ | ||
version for version | ||
in filter_by_date_range(versions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather use built-in filter function
prune_unique=True, | ||
): | ||
if not cnode.component.sources: | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a brief comment explaining why this case is skipped to help our future selves x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also: why not simply use note_filter.cnudie.iter.Filter.sources?`
all_findings_for_rescoring = [] | ||
|
||
source_node = cnudie.iter.SourceNode( | ||
path=(cnudie.iter.NodePathEntry(cnode.component),), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather directly iter source nodes (node_filter in cnudie.iter.iter
)
also, if constructing source_node manually, make sure to give the full path and not only the parent component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this context, if is not a good idea to manually construct sourcenodes.
), | ||
time_now=time_now, | ||
) | ||
new_metadata.extend(rescored_metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: list.extend resolves a generator :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure - it accepts any iterable (which includes generators)
return None | ||
|
||
|
||
def rescore_sast_severity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems you decided against my suggestion, which of course is fine, but could you please elaborate what lead to this decision?
looking only at the PR I do not see a good reason against 🤔
if sast_config.component_version: | ||
return [sast_config.component_version] | ||
|
||
version_lookup = lookups.init_version_lookup() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also: consistency (why pass-in component-descriptor-lookup, but not version-lookup)
if not (pv := versionutil.parse_to_semver( | ||
version=v, | ||
invalid_semver_ok=False, | ||
)).prerelease and not pv.build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have a util-function for that in cc-util's version.py
(at least is_final
comes to my mind)
prune_unique=True, | ||
): | ||
if not cnode.component.sources: | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also: why not simply use note_filter.cnudie.iter.Filter.sources?`
all_findings_for_rescoring = [] | ||
|
||
source_node = cnudie.iter.SourceNode( | ||
path=(cnudie.iter.NodePathEntry(cnode.component),), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this context, if is not a good idea to manually construct sourcenodes.
), | ||
time_now=time_now, | ||
) | ||
new_metadata.extend(rescored_metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure - it accepts any iterable (which includes generators)
elif rescoring_rule.rescore is rescore.model.Rescore.TO_NONE: | ||
return github.compliance.model.Severity.NONE.name | ||
|
||
raise NotImplementedError(rescoring_rule.rescore) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: while we do use NIE for that in our "heritage" codebase, it is actually not intended to be used for this purpose (python-documentation states NIE is intended for being raised by (abstract) methods that were not implemented). rather use ValueError
time_now: datetime.datetime | ||
) -> typing.Generator[dso.model.ArtefactMetadata, None, None]: | ||
for finding in findings: | ||
matching_rule = next( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really do not like this pattern. how about rather doing sth. like
try:
mr = next(...)
except StopIteration:
continue
In my opinion, this makes it a lot more obvious what is being done.
) -> typing.Generator[dso.model.ArtefactMetadata, None, None]: | ||
for finding in findings: | ||
matching_rule = next( | ||
matching_sast_rescore_rule( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw: is this function intended to yield more than one rule (judging from the name, I would assume: no)? if not, why not have the function either return a rule or None. This would make it less messy to use.
new_severity = rescore_sast_severity( | ||
rescoring_rule=matching_rule, | ||
) | ||
if finding.data.severity == new_severity: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if severity is an enum (did not check), use is
for comparison.
severity=new_severity, | ||
user=user, | ||
matching_rules=[matching_rule.name], | ||
comment='Automatically rescored based on rules.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include rulename(s) (+ ruleset-name) in comment?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Release note: