Summarize a scan by compiling review items of ambiguous detections.
| 67 | |
| 68 | @post_scan_impl |
| 69 | class AmbiguousDetectionsToDoPlugin(PostScanPlugin): |
| 70 | """ |
| 71 | Summarize a scan by compiling review items of ambiguous detections. |
| 72 | """ |
| 73 | sort_order = 3 |
| 74 | |
| 75 | resource_attributes = dict(for_todo=attr.ib(default=attr.Factory(list))) |
| 76 | codebase_attributes = dict(todo=attr.ib(default=attr.Factory(list))) |
| 77 | |
| 78 | options = [ |
| 79 | PluggableCommandLineOption( |
| 80 | ('--todo',), |
| 81 | is_flag=True, |
| 82 | default=False, |
| 83 | help='Summarize scans by providing all ambiguous ' |
| 84 | 'detections which are todo items and needs manual review.', |
| 85 | help_group=POST_SCAN_GROUP, |
| 86 | ) |
| 87 | ] |
| 88 | |
| 89 | def is_enabled(self, todo, **kwargs): |
| 90 | return todo |
| 91 | |
| 92 | def process_codebase(self, codebase, **kwargs): |
| 93 | |
| 94 | has_packages = False |
| 95 | has_licenses = False |
| 96 | |
| 97 | if hasattr(codebase.root, 'package_data'): |
| 98 | has_packages = True |
| 99 | |
| 100 | if hasattr(codebase.root, 'license_detections'): |
| 101 | has_licenses = True |
| 102 | |
| 103 | license_diagnostics = kwargs.get("license_diagnostics") |
| 104 | license_text = kwargs.get("license_text") |
| 105 | license_text_diagnostics = kwargs.get("license_text_diagnostics") |
| 106 | if not license_diagnostics or not license_text or not license_text_diagnostics: |
| 107 | usage_suggestion_message = ( |
| 108 | "The --todo option, when paired with --license option should be used with the folowing " |
| 109 | "additional CLI options for maximum benifit: [`--license-text`, `--license-text-diagnostics`," |
| 110 | "--license-diagnostics`] as these show additional diagnostic information to help review the issues." |
| 111 | ) |
| 112 | warnings.simplefilter('always', ToDoPluginUsageWarning) |
| 113 | warnings.warn( |
| 114 | usage_suggestion_message, |
| 115 | ToDoPluginUsageWarning, |
| 116 | stacklevel=2, |
| 117 | ) |
| 118 | |
| 119 | if not has_packages and not has_licenses: |
| 120 | usage_suggestion_message = ( |
| 121 | "The --todo option should be used with atleast one of the license [`--license`], " |
| 122 | "or package [`--package`] options." |
| 123 | ) |
| 124 | warnings.simplefilter('always', ToDoPluginUsageWarning) |
| 125 | warnings.warn( |
| 126 | usage_suggestion_message, |
nothing calls this directly
no test coverage detected