@gnost-cli/darwin-arm64 0.5.3 → 0.6.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/_internal/base_library.zip +0 -0
- package/bundle/_internal/certifi/cacert.pem +3885 -0
- package/bundle/_internal/gnost/__init__.py +1 -1
- package/bundle/_internal/gnost/analysis/analyzers/readability_analyzer.py +4 -1
- package/bundle/_internal/gnost/analysis/utils/tool_command.py +8 -0
- package/bundle/_internal/gnost/changes/__init__.py +1 -0
- package/bundle/_internal/gnost/changes/analyzer.py +215 -0
- package/bundle/_internal/gnost/changes/findings.py +55 -0
- package/bundle/_internal/gnost/changes/impact.py +59 -0
- package/bundle/_internal/gnost/changes/refs.py +105 -0
- package/bundle/_internal/gnost/changes/render.py +172 -0
- package/bundle/_internal/gnost/changes/report.py +124 -0
- package/bundle/_internal/gnost/changes/snapshot.py +109 -0
- package/bundle/_internal/gnost/ci/__init__.py +1 -0
- package/bundle/_internal/gnost/ci/baseline.py +88 -0
- package/bundle/_internal/gnost/ci/exit_codes.py +19 -0
- package/bundle/_internal/gnost/ci/fingerprint.py +44 -0
- package/bundle/_internal/gnost/ci/gate.py +42 -0
- package/bundle/_internal/gnost/ci/paths.py +57 -0
- package/bundle/_internal/gnost/ci/run.py +135 -0
- package/bundle/_internal/gnost/ci/sarif.py +149 -0
- package/bundle/_internal/gnost/ci/scorecard.py +95 -0
- package/bundle/_internal/gnost/cli/app.py +406 -155
- package/bundle/_internal/gnost/cli/commands/changes.py +144 -0
- package/bundle/_internal/gnost/cli/commands/init.py +192 -0
- package/bundle/_internal/gnost/cli/commands/onboard.py +83 -27
- package/bundle/_internal/gnost/cli/commands/remote.py +53 -0
- package/bundle/_internal/gnost/cli/commands/show.py +15 -14
- package/bundle/_internal/gnost/config/languages.py +19 -4
- package/bundle/_internal/gnost/config/settings.py +127 -2
- package/bundle/_internal/gnost/core/flow.py +27 -0
- package/bundle/_internal/gnost/core/insight_builder.py +3 -1
- package/bundle/_internal/gnost/core/risk.py +115 -0
- package/bundle/_internal/gnost/reporters/insights_json.py +65 -1
- package/bundle/_internal/gnost/reporters/loc_summary.py +3 -3
- package/bundle/_internal/gnost/reporters/markdown.py +89 -10
- package/bundle/_internal/gnost/reporters/mermaid.py +7 -0
- package/bundle/_internal/gnost/reporters/readme.py +11 -6
- package/bundle/_internal/gnost/reporters/stats.py +3 -3
- package/bundle/_internal/gnost/reporters/summary.py +48 -1
- package/bundle/_internal/gnost/scanner/filters.py +45 -12
- package/bundle/_internal/gnost/scanner/loc.py +5 -0
- package/bundle/_internal/gnost/schemas/insights.schema.json +153 -0
- package/bundle/_internal/gnost/utils/footer.py +36 -0
- package/bundle/_internal/gnost/utils/integrations.py +346 -0
- package/bundle/_internal/gnost/utils/layout.py +111 -0
- package/bundle/_internal/gnost/utils/progress.py +6 -3
- package/bundle/_internal/gnost/utils/update_check.py +253 -0
- package/bundle/_internal/gnost/vcs/__init__.py +1 -0
- package/bundle/_internal/gnost/vcs/git.py +181 -0
- package/bundle/_internal/gnost/vcs/history.py +404 -0
- package/bundle/_internal/gnost/vcs/remote.py +204 -0
- package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/METADATA +7 -4
- package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/RECORD +88 -30
- package/bundle/_internal/gnost-0.6.0rc1.dist-info/REQUESTED +0 -0
- package/bundle/_internal/yaml/_yaml.cpython-312-darwin.so +0 -0
- package/bundle/gnost +0 -0
- package/package.json +1 -1
- /package/bundle/_internal/{gnost-0.5.3.dist-info/REQUESTED → certifi/py.typed} +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/INSTALLER +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/WHEEL +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/direct_url.json +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/entry_points.txt +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/licenses/LICENSE +0 -0
- /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""SARIF 2.1.0 output, the format GitHub code scanning (and many other tools) reads.
|
|
2
|
+
|
|
3
|
+
`SarifWriter` turns findings into one run with a rule per kind of finding and a result per
|
|
4
|
+
finding. Locations are repository-relative; each result carries the GNOST fingerprint so
|
|
5
|
+
tools can match the same problem across runs instead of reopening it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
from typing import Any, Dict, List, Sequence
|
|
14
|
+
|
|
15
|
+
from gnost import __version__
|
|
16
|
+
from gnost.analysis.core.models import SeverityLevel, UnifiedFinding
|
|
17
|
+
from gnost.ci.fingerprint import FindingFingerprint
|
|
18
|
+
from gnost.ci.paths import PathResolver
|
|
19
|
+
|
|
20
|
+
SCHEMA_URL = "https://json.schemastore.org/sarif-2.1.0.json"
|
|
21
|
+
INFO_URL = "https://gnost.readthedocs.io"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SarifWriter:
|
|
25
|
+
"""Builds and writes a SARIF log for a list of findings."""
|
|
26
|
+
|
|
27
|
+
# Change a level here to change how a severity is reported.
|
|
28
|
+
LEVELS: Dict[SeverityLevel, str] = {
|
|
29
|
+
SeverityLevel.CRITICAL: "error",
|
|
30
|
+
SeverityLevel.HIGH: "error",
|
|
31
|
+
SeverityLevel.MEDIUM: "warning",
|
|
32
|
+
SeverityLevel.LOW: "note",
|
|
33
|
+
SeverityLevel.INFO: "note",
|
|
34
|
+
}
|
|
35
|
+
MESSAGE_LIMIT = 500
|
|
36
|
+
|
|
37
|
+
def __init__(self, resolver: PathResolver, fingerprint: FindingFingerprint) -> None:
|
|
38
|
+
self.resolver = resolver
|
|
39
|
+
self.fingerprint = fingerprint
|
|
40
|
+
|
|
41
|
+
def build(self, findings: Sequence[UnifiedFinding]) -> Dict[str, Any]:
|
|
42
|
+
"""The SARIF log as a dict."""
|
|
43
|
+
rules: Dict[str, Dict[str, Any]] = {}
|
|
44
|
+
results = []
|
|
45
|
+
for finding in sorted(findings, key=self._sort_key):
|
|
46
|
+
rule_id = self.rule_id(finding)
|
|
47
|
+
rules.setdefault(rule_id, self._rule(rule_id, finding))
|
|
48
|
+
results.append(self._result(rule_id, list(rules).index(rule_id), finding))
|
|
49
|
+
return {
|
|
50
|
+
"$schema": SCHEMA_URL,
|
|
51
|
+
"version": "2.1.0",
|
|
52
|
+
"runs": [
|
|
53
|
+
{
|
|
54
|
+
"tool": {
|
|
55
|
+
"driver": {
|
|
56
|
+
"name": "GNOST",
|
|
57
|
+
"version": __version__,
|
|
58
|
+
"informationUri": INFO_URL,
|
|
59
|
+
"rules": list(rules.values()),
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"results": results,
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
def write(self, path: str, findings: Sequence[UnifiedFinding]) -> None:
|
|
68
|
+
"""Write the SARIF log to path (creating its folder)."""
|
|
69
|
+
os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True)
|
|
70
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
71
|
+
json.dump(self.build(findings), f, indent=2)
|
|
72
|
+
f.write("\n")
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def rule_id(finding: UnifiedFinding) -> str:
|
|
76
|
+
"""analyzer/rule, or analyzer/title-slug for findings without a rule id."""
|
|
77
|
+
name = finding.rule_id or re.sub(
|
|
78
|
+
r"[^a-z0-9]+", "-", finding.title.lower()
|
|
79
|
+
).strip("-")
|
|
80
|
+
return f"{finding.source_analyzer or 'gnost'}/{name or 'finding'}"
|
|
81
|
+
|
|
82
|
+
def _level(self, finding: UnifiedFinding) -> str:
|
|
83
|
+
return self.LEVELS.get(finding.severity, "warning")
|
|
84
|
+
|
|
85
|
+
def _rule(self, rule_id: str, finding: UnifiedFinding) -> Dict[str, Any]:
|
|
86
|
+
rule: Dict[str, Any] = {
|
|
87
|
+
"id": rule_id,
|
|
88
|
+
"name": finding.title or rule_id,
|
|
89
|
+
"shortDescription": {"text": finding.title or rule_id},
|
|
90
|
+
"defaultConfiguration": {"level": self._level(finding)},
|
|
91
|
+
"properties": {
|
|
92
|
+
"tags": sorted({finding.category.value, finding.source_analyzer} - {""})
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
if finding.description:
|
|
96
|
+
rule["fullDescription"] = {
|
|
97
|
+
"text": finding.description[: self.MESSAGE_LIMIT]
|
|
98
|
+
}
|
|
99
|
+
if finding.remediation_guidance:
|
|
100
|
+
rule["help"] = {"text": finding.remediation_guidance[: self.MESSAGE_LIMIT]}
|
|
101
|
+
return rule
|
|
102
|
+
|
|
103
|
+
def _result(
|
|
104
|
+
self, rule_id: str, index: int, finding: UnifiedFinding
|
|
105
|
+
) -> Dict[str, Any]:
|
|
106
|
+
text = finding.title
|
|
107
|
+
if finding.description and finding.description != finding.title:
|
|
108
|
+
text = f"{finding.title}: {finding.description}"
|
|
109
|
+
result: Dict[str, Any] = {
|
|
110
|
+
"ruleId": rule_id,
|
|
111
|
+
"ruleIndex": index,
|
|
112
|
+
"level": self._level(finding),
|
|
113
|
+
"message": {"text": text[: self.MESSAGE_LIMIT]},
|
|
114
|
+
"partialFingerprints": {
|
|
115
|
+
f"gnostFingerprint/{FindingFingerprint.VERSION}": self.fingerprint.of(
|
|
116
|
+
finding
|
|
117
|
+
)
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
location = self._location(finding)
|
|
121
|
+
if location:
|
|
122
|
+
result["locations"] = [location]
|
|
123
|
+
return result
|
|
124
|
+
|
|
125
|
+
def _location(self, finding: UnifiedFinding) -> Dict[str, Any]:
|
|
126
|
+
"""The physical location, or {} when the path is not a file in the repository."""
|
|
127
|
+
path = self.resolver.resolve(finding.location.file_path)
|
|
128
|
+
if not path or not self.resolver.exists(path):
|
|
129
|
+
return {}
|
|
130
|
+
region: Dict[str, int] = {
|
|
131
|
+
"startLine": max(1, finding.location.line_number or 1)
|
|
132
|
+
}
|
|
133
|
+
if finding.location.end_line_number:
|
|
134
|
+
region["endLine"] = max(
|
|
135
|
+
region["startLine"], finding.location.end_line_number
|
|
136
|
+
)
|
|
137
|
+
return {
|
|
138
|
+
"physicalLocation": {
|
|
139
|
+
"artifactLocation": {"uri": path, "uriBaseId": "%SRCROOT%"},
|
|
140
|
+
"region": region,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
def _sort_key(self, finding: UnifiedFinding) -> List[Any]:
|
|
145
|
+
return [
|
|
146
|
+
self.resolver.resolve(finding.location.file_path),
|
|
147
|
+
finding.location.line_number or 0,
|
|
148
|
+
self.rule_id(finding),
|
|
149
|
+
]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""The scores `gnost analyze` prints: one per analyzer and the final score out of 10.
|
|
2
|
+
|
|
3
|
+
`ScoreCard` is built from a finished report. The gate and the terminal table both read it,
|
|
4
|
+
so the number you see is the number a CI threshold compares against.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import Any, Dict, List
|
|
11
|
+
|
|
12
|
+
from gnost.analysis.core.models import ConsolidatedReport, SeverityLevel, UnifiedFinding
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class AnalyzerScore:
|
|
17
|
+
"""One analyzer's score (0 to 10, higher is better) with its finding counts."""
|
|
18
|
+
|
|
19
|
+
name: str
|
|
20
|
+
score: float
|
|
21
|
+
findings: int
|
|
22
|
+
high: int
|
|
23
|
+
medium: int
|
|
24
|
+
low: int
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ScoreCard:
|
|
28
|
+
"""Per-analyzer scores plus the final score of a report."""
|
|
29
|
+
|
|
30
|
+
SEVERITY_WEIGHTS: Dict[SeverityLevel, float] = {
|
|
31
|
+
SeverityLevel.CRITICAL: 1.0,
|
|
32
|
+
SeverityLevel.HIGH: 0.6,
|
|
33
|
+
SeverityLevel.MEDIUM: 0.3,
|
|
34
|
+
SeverityLevel.LOW: 0.1,
|
|
35
|
+
SeverityLevel.INFO: 0.05,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def __init__(self, analyzers: List[AnalyzerScore], final_score: float) -> None:
|
|
39
|
+
self.analyzers = analyzers
|
|
40
|
+
self.final_score = final_score
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_report(cls, report: ConsolidatedReport) -> "ScoreCard":
|
|
44
|
+
"""Score every analyzer that ran, and take the final score from the report summary."""
|
|
45
|
+
by_analyzer: Dict[str, List[UnifiedFinding]] = {}
|
|
46
|
+
for finding in report.findings:
|
|
47
|
+
by_analyzer.setdefault(finding.source_analyzer, []).append(finding)
|
|
48
|
+
analyzers = []
|
|
49
|
+
for metric in sorted(report.analysis_metrics, key=lambda m: m.analyzer_name):
|
|
50
|
+
found = by_analyzer.get(metric.analyzer_name, [])
|
|
51
|
+
counts = cls.severity_counts(found)
|
|
52
|
+
analyzers.append(
|
|
53
|
+
AnalyzerScore(
|
|
54
|
+
name=metric.analyzer_name,
|
|
55
|
+
score=cls.risk_to_score(cls.analyzer_risk(found)),
|
|
56
|
+
findings=len(found),
|
|
57
|
+
high=counts["high"],
|
|
58
|
+
medium=counts["medium"],
|
|
59
|
+
low=counts["low"],
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
summary: Any = report.summary
|
|
63
|
+
risk = summary.get("risk_score", 0.0) if isinstance(summary, dict) else 0.0
|
|
64
|
+
return cls(analyzers, cls.risk_to_score(risk))
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def risk_to_score(risk_score: float) -> float:
|
|
68
|
+
"""Turn a risk percentage (0 to 100, lower is better) into a score out of 10."""
|
|
69
|
+
clamped = max(0.0, min(100.0, risk_score))
|
|
70
|
+
return round(10.0 * (1.0 - clamped / 100.0), 2)
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def analyzer_risk(cls, findings: List[UnifiedFinding]) -> float:
|
|
74
|
+
"""Risk percentage of one analyzer's findings, weighted by severity."""
|
|
75
|
+
if not findings:
|
|
76
|
+
return 0.0
|
|
77
|
+
total = sum(cls.SEVERITY_WEIGHTS.get(f.severity, 0.2) for f in findings)
|
|
78
|
+
worst = max(cls.SEVERITY_WEIGHTS.values())
|
|
79
|
+
return round((total / (len(findings) * worst)) * 100.0, 2)
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def severity_counts(findings: List[UnifiedFinding]) -> Dict[str, int]:
|
|
83
|
+
"""Counts of high (critical included), medium, low and info findings."""
|
|
84
|
+
counts = {"high": 0, "medium": 0, "low": 0, "info": 0}
|
|
85
|
+
for finding in findings:
|
|
86
|
+
name = str(finding.severity).split(".")[-1].lower()
|
|
87
|
+
counts[
|
|
88
|
+
"high" if name == "critical" else name if name in counts else "info"
|
|
89
|
+
] += 1
|
|
90
|
+
return counts
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def style(score: float) -> str:
|
|
94
|
+
"""The terminal colour for a score: green from 8, yellow from 6, else red."""
|
|
95
|
+
return "green" if score >= 8.0 else "yellow" if score >= 6.0 else "red"
|