Skip to content

Commit d88af7c

Browse files
authored
Merge pull request #197 from KoolTheba/feat/improve-mutable-payloads
Improve API Digestion stability and include discrepancies visualization
2 parents 22af671 + c5f9e1b commit d88af7c

File tree

14 files changed

+252
-50
lines changed

14 files changed

+252
-50
lines changed

.github/other/discrepancies.png

120 KB
Loading

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ The Visualizer is part of the [OpenSSF Scorecard Monitor](https://github.com/Uli
66

77
## Features
88

9-
**Scorecard Data Visualizer:** Display the OpenSSF Scorecard data in a visual format for easy understanding and analysis.
9+
### Scorecard Data Visualizer
10+
11+
Display the OpenSSF Scorecard data in a visual format for easy understanding and analysis.
1012

1113
<br>
1214
<div>
1315
<img src='.github/other/demo1.gif' alt="visualizer-in-action"/>
1416
</div>
1517
</br>
1618

17-
**Scorecard Data Comparator:** Compare between two commits that reported Scorecard data. See how the scores changed and further details.
19+
### Scorecard Data Comparator
20+
21+
Compare between two commits that reported Scorecard data. See how the scores changed and further details.
1822

1923
<br>
2024
<div>
2125
<img src='.github/other/gif_comparator.gif' alt="comparator-in-action"/>
2226
</div>
2327
</br>
2428

25-
**Scorecard Data Comparator Diff:** Makes easier the visualization of the differences in the Scorecard comparator reasoning and details.
29+
### Scorecard Data Comparator Diff
30+
31+
Makes easier the visualization of the differences in the Scorecard comparator reasoning and details.
2632

2733
<br>
2834
<div>
@@ -33,14 +39,25 @@ The Visualizer is part of the [OpenSSF Scorecard Monitor](https://github.com/Uli
3339
</div>
3440
</br>
3541

36-
**Support to GitLab repositories:** The project provides support of visualization and diff comparation for GitLab projects. In the GitLab version, deps.dev and step security links are not included, as those platforms don't support GitLab projects yet.
42+
### Support to GitLab repositories
43+
44+
The project provides support of visualization and diff comparation for GitLab projects. In the GitLab version, deps.dev and step security links are not included, as those platforms don't support GitLab projects yet.
3745

3846
<br>
3947
<div>
4048
<img src='.github/other/gitlab-support.png' alt="visualizer-for-gitlab-repos"/>
4149
</div>
4250
</br>
4351

52+
### Discrepancies management
53+
54+
The Scorecard API can provide discrepancies in the data while comparing between two commits due [technical reasons](https://github.com/ossf/scorecard/issues/3438). The visualizer provides a way to showcase the discrepancies found.
55+
56+
<br>
57+
<div>
58+
<img src='.github/other/discrepancies.png' alt="discrepancies preview"/>
59+
</div>
60+
</br>
4461

4562
## How to use it
4663

cypress/downloads/downloads.html

-30 MB
Binary file not shown.

src/components/ProjectCompartor.tsx renamed to src/components/ProjectComparator.tsx

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ import CommonError from "./CommonError";
88
import Collapsible from "./Collapsable";
99
import Loading from "./Loading";
1010
import { ComparatorDiff } from "./ComparatorDiff";
11-
import { ScoreElement } from "../types";
11+
import { ScoreElement, ConsolidatedScoreElement } from "../types";
12+
import { getRefinedChecks } from "../utils/comparator/getRefinedChecks";
13+
import { areEqualElements } from "../utils/comparator/areEqualElements";
1214

1315
import "../styles/ProjectDetails.css";
1416

1517
function ProjectComparator() {
1618
const params = useParams();
1719
const { platform, org, repo, prevCommitHash, currentCommitHash } = params;
1820

19-
const [state, setState] = useState([]);
21+
const [consolidatedData, setConsolidatedData] = useState<
22+
ConsolidatedScoreElement[]
23+
>([]);
24+
const [discrepancies, setDiscrepancies] = useState<string[]>([]);
2025

2126
const prevCommitQuery = useQuery({
2227
queryKey: ["prevCommit"],
@@ -49,45 +54,37 @@ function ProjectComparator() {
4954

5055
useEffect(() => {
5156
const areEqualDetails = () => {
52-
let consolidatedData;
53-
5457
if (!previousData?.checks || !previousData?.score) {
5558
return;
5659
}
57-
consolidatedData = currentData?.checks?.map(
58-
(e1: ScoreElement, index: number) => {
59-
if (
60-
JSON.stringify(e1.details) !==
61-
JSON.stringify(previousData?.checks[index].details) ||
62-
JSON.stringify(e1.reason) !==
63-
JSON.stringify(previousData?.checks[index].reason)
64-
) {
65-
return {
66-
areEqual: false,
67-
name: previousData.checks[index].name,
68-
details: e1.details,
69-
reason: e1.reason,
70-
score: e1.score,
71-
short: e1.documentation.short,
72-
url: e1.documentation.url,
73-
prevDetails: previousData.checks[index].details,
74-
prevReason: previousData.checks[index].reason,
75-
prevScore: previousData.checks[index].score,
76-
};
77-
} else {
78-
return {
79-
areEqual: true,
80-
name: e1.name,
81-
details: e1.details,
82-
reason: e1.reason,
83-
score: e1.score,
84-
short: e1.documentation.short,
85-
url: e1.documentation.url,
86-
};
87-
}
88-
},
60+
61+
const refinedChecks = getRefinedChecks(
62+
previousData?.checks,
63+
currentData?.checks,
8964
);
90-
setState(consolidatedData);
65+
66+
const data = refinedChecks.common.map((name: string) => {
67+
const previousElement = previousData?.checks?.filter(
68+
(el: ScoreElement) => el.name === name,
69+
)[0];
70+
const currentElement = currentData?.checks?.filter(
71+
(el: ScoreElement) => el.name === name,
72+
)[0];
73+
return {
74+
areEqual: areEqualElements(currentElement, previousElement),
75+
name: previousElement.name,
76+
details: currentElement.details,
77+
reason: currentElement.reason,
78+
score: currentElement.score,
79+
short: currentElement.documentation.short,
80+
url: currentElement.documentation.url,
81+
prevDetails: previousElement.details,
82+
prevReason: previousElement.reason,
83+
prevScore: previousElement.score,
84+
};
85+
});
86+
setConsolidatedData(data);
87+
setDiscrepancies(refinedChecks.discrepancies);
9188
};
9289
areEqualDetails();
9390
}, [currentData, previousData]);
@@ -139,9 +136,21 @@ function ProjectComparator() {
139136
{`(${currentData.scorecard.commit.substring(0, 8)})`}
140137
</a>
141138
</p>
139+
{discrepancies.length > 0 && (
140+
<span className="warning-message" data-testid="discrepancies">
141+
{`Scorecard API missing: ${discrepancies.join(", ")} checks. See `}
142+
<a
143+
href="https://github.com/KoolTheba/openssf-scorecard-api-visualizer/tree/main#discrepancies-management"
144+
target="_blank"
145+
rel="noreferrer"
146+
>
147+
details
148+
</a>
149+
</span>
150+
)}
142151
<hr />
143-
{Array.isArray(state) &&
144-
state.map((element: any) => (
152+
{Array.isArray(consolidatedData) &&
153+
consolidatedData.map((element: ConsolidatedScoreElement) => (
145154
<>
146155
<div key={element.name} className="card__wrapper">
147156
<div data-testid={element.name} className="heading__wrapper">
@@ -157,10 +166,8 @@ function ProjectComparator() {
157166
See documentation
158167
</a>
159168
</p>
160-
{(element.prevDetails || element.prevReason) && (
161-
<h4>Additional details / variations</h4>
162-
)}
163-
{element.prevReason && element.reason ? (
169+
{!element.areEqual && <h4>Additional details / variations</h4>}
170+
{!element.areEqual ? (
164171
<p>
165172
Reasoning:{" "}
166173
<ComparatorDiff

src/components/ProjectDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function ProjectDetails() {
6464
</p>
6565
{platform === GITHUB && (
6666
<>
67-
<p data-testid="deps-dev">
67+
<p data-testid="deps-dev">
6868
Additional info at{" "}
6969
<a
7070
href={`https://deps.dev/project/github/${org}%2F${repo}`}

src/constants/checks.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const CHECKS_LIST_NAMES = [
2+
"Binary-Artifacts",
3+
"Branch-Protection",
4+
"CI-Tests",
5+
"CII-Best-Practices",
6+
"Code-Review",
7+
"Contributors",
8+
"Dangerous-Workflow",
9+
"Dependency-Update-Tool",
10+
"Fuzzing",
11+
"License",
12+
"Maintained",
13+
"Packaging",
14+
"Pinned-Dependencies",
15+
"SAST",
16+
"Security-Policy",
17+
"Signed-Releases",
18+
"Token-Permissions",
19+
"Vulnerabilities",
20+
];

src/constants/platforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const GITHUB = 'github.com'
1+
export const GITHUB = "github.com";

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
77
import NotFound from "./components/NotFound";
88
import CommonError from "./components/CommonError";
99
import ProjectDetails from "./components/ProjectDetails";
10-
import ProjectComparator from "./components/ProjectCompartor";
10+
import ProjectComparator from "./components/ProjectComparator";
1111

1212
import reportWebVitals from "./reportWebVitals";
1313
import "./index.css";

src/styles/ProjectDetails.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@ a:hover {
100100
flex-direction: row;
101101
align-items: center;
102102
}
103+
104+
.warning-message {
105+
width: auto;
106+
padding: 10px;
107+
color: black;
108+
background-color: orange;
109+
border-radius: 5px;
110+
font-size: 1rem;
111+
display: inline-block;
112+
font-weight: 600;
113+
line-height: 1.5rem;
114+
}

src/types/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@ export interface ScoreElement {
88
url: string;
99
};
1010
}
11+
12+
export interface ConsolidatedScoreElement {
13+
areEqual: boolean;
14+
name: string;
15+
details: string[];
16+
reason: string;
17+
score: number;
18+
short: string;
19+
url: string;
20+
prevDetails: string[];
21+
prevReason: string;
22+
prevScore: number;
23+
}

0 commit comments

Comments
 (0)