Skip to content

Commit 384b01d

Browse files
feat(scorecard): add support for GitLab
1 parent c4ed596 commit 384b01d

File tree

15 files changed

+245
-186
lines changed

15 files changed

+245
-186
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Since version 0.6.0 of Node-secure the UI include a brand new searchbar that all
167167
- author (author name/email/url).
168168
- ext (list of available file extensions in the current payload/tree).
169169
- builtin (available Node.js core module name).
170-
- size (see [here](https://github.com/NodeSecure/size-satisfies#usage-example)
170+
- size (see [here](https://github.com/NodeSecure/size-satisfies#usage-example)).
171171

172172
Exemple of query:
173173

@@ -187,7 +187,6 @@ other side will bundle and remove most of the useless files from the tarball (Li
187187
### Why some packages don't have OSSF Scorecard ?
188188
See [Scorecard Public Data](https://github.com/ossf/scorecard#public-data):
189189
> We run a weekly Scorecard scan of the 1 million most critical open source projects judged by their direct dependencies and publish the results in a BigQuery public dataset.
190-
> Currently, this list is derived from projects hosted on GitHub ONLY.
191190
192191
## Contributors guide
193192

bin/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ prog
8383
prog
8484
.command("scorecard [repository]")
8585
.describe(i18n.getTokenSync("cli.commands.scorecard.desc"))
86+
.option("--vcs", "Version control platform (GitHub, GitLab", "github")
8687
.action(commands.scorecard.main);
8788

8889
prog

package.json

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,108 @@
1-
{
2-
"name": "@nodesecure/cli",
3-
"version": "2.2.1",
4-
"description": "Node.js security CLI",
5-
"main": "./bin/index.js",
6-
"bin": {
7-
"node-secure": "./bin/index.js",
8-
"nsecure": "./bin/index.js"
9-
},
10-
"type": "module",
11-
"engines": {
12-
"node": ">=18"
13-
},
14-
"scripts": {
15-
"eslint": "eslint bin src test",
16-
"eslint-fix": "npm run eslint -- --fix",
17-
"prepublishOnly": "rimraf ./dist && npm run build && pkg-ok",
18-
"build": "node ./esbuild.config.js",
19-
"test": "npm run test-only && npm run eslint",
20-
"test-only": "node --loader=esmock --no-warnings --test test/",
21-
"coverage": "c8 --reporter=lcov npm run test"
22-
},
23-
"files": [
24-
"bin",
25-
"dist",
26-
"src",
27-
"views"
28-
],
29-
"workspaces": [
30-
"workspaces/documentation-ui",
31-
"workspaces/vis-network"
32-
],
33-
"repository": {
34-
"type": "git",
35-
"url": "git+https://github.com/NodeSecure/cli.git"
36-
},
37-
"keywords": [
38-
"node",
39-
"nodejs",
40-
"security",
41-
"cli",
42-
"sast",
43-
"scanner",
44-
"static",
45-
"code",
46-
"analysis",
47-
"node_modules",
48-
"tree",
49-
"npm",
50-
"registry",
51-
"graph",
52-
"visualization",
53-
"dependencies"
54-
],
55-
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
56-
"license": "MIT",
57-
"bugs": {
58-
"url": "https://github.com/NodeSecure/cli/issues"
59-
},
60-
"homepage": "https://github.com/NodeSecure/cli#readme",
61-
"devDependencies": {
62-
"@myunisoft/httpie": "^2.0.1",
63-
"@nodesecure/eslint-config": "^1.7.1",
64-
"@nodesecure/size-satisfies": "^1.1.0",
65-
"@nodesecure/vis-network": "^1.4.0",
66-
"@types/node": "^20.5.3",
67-
"c8": "^8.0.1",
68-
"cross-env": "^7.0.3",
69-
"esbuild": "^0.19.2",
70-
"eslint": "^8.47.0",
71-
"esmock": "^2.3.8",
72-
"http-server": "^14.1.1",
73-
"pkg-ok": "^3.0.0",
74-
"pretty-bytes": "^6.1.1",
75-
"rimraf": "^5.0.5",
76-
"strip-ansi": "^7.1.0"
77-
},
78-
"dependencies": {
79-
"@nodesecure/documentation-ui": "^1.3.0",
80-
"@nodesecure/flags": "^2.4.0",
81-
"@nodesecure/i18n": "^3.4.0",
82-
"@nodesecure/licenses-conformance": "^2.1.0",
83-
"@nodesecure/npm-registry-sdk": "^1.6.1",
84-
"@nodesecure/ossf-scorecard-sdk": "^2.0.0",
85-
"@nodesecure/rc": "^1.5.0",
86-
"@nodesecure/scanner": "^5.1.0",
87-
"@nodesecure/utils": "^1.1.0",
88-
"@nodesecure/vuln": "^1.7.0",
89-
"@openally/result": "^1.2.0",
90-
"@polka/send-type": "^0.5.2",
91-
"@topcli/cliui": "^1.1.0",
92-
"@topcli/spinner": "^2.1.2",
93-
"cacache": "^18.0.0",
94-
"dotenv": "^16.3.1",
95-
"filenamify": "^6.0.0",
96-
"ini": "^4.1.1",
97-
"kleur": "^4.1.5",
98-
"ms": "^2.1.3",
99-
"open": "^9.1.0",
100-
"polka": "^0.5.2",
101-
"qoa": "^0.2.0",
102-
"sade": "^1.8.1",
103-
"semver": "^7.5.4",
104-
"server-destroy": "^1.0.1",
105-
"sirv": "^2.0.3",
106-
"zup": "0.0.1"
107-
}
108-
}
1+
{
2+
"name": "@nodesecure/cli",
3+
"version": "2.2.1",
4+
"description": "Node.js security CLI",
5+
"main": "./bin/index.js",
6+
"bin": {
7+
"node-secure": "./bin/index.js",
8+
"nsecure": "./bin/index.js"
9+
},
10+
"type": "module",
11+
"engines": {
12+
"node": ">=18"
13+
},
14+
"scripts": {
15+
"eslint": "eslint bin src test",
16+
"eslint-fix": "npm run eslint -- --fix",
17+
"prepublishOnly": "rimraf ./dist && npm run build && pkg-ok",
18+
"build": "node ./esbuild.config.js",
19+
"test": "npm run test-only && npm run eslint",
20+
"test-only": "node --loader=esmock --no-warnings --test test/",
21+
"coverage": "c8 --reporter=lcov npm run test"
22+
},
23+
"files": [
24+
"bin",
25+
"dist",
26+
"src",
27+
"views"
28+
],
29+
"workspaces": [
30+
"workspaces/documentation-ui",
31+
"workspaces/vis-network"
32+
],
33+
"repository": {
34+
"type": "git",
35+
"url": "git+https://github.com/NodeSecure/cli.git"
36+
},
37+
"keywords": [
38+
"node",
39+
"nodejs",
40+
"security",
41+
"cli",
42+
"sast",
43+
"scanner",
44+
"static",
45+
"code",
46+
"analysis",
47+
"node_modules",
48+
"tree",
49+
"npm",
50+
"registry",
51+
"graph",
52+
"visualization",
53+
"dependencies"
54+
],
55+
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
56+
"license": "MIT",
57+
"bugs": {
58+
"url": "https://github.com/NodeSecure/cli/issues"
59+
},
60+
"homepage": "https://github.com/NodeSecure/cli#readme",
61+
"devDependencies": {
62+
"@myunisoft/httpie": "^2.0.1",
63+
"@nodesecure/eslint-config": "^1.7.1",
64+
"@nodesecure/size-satisfies": "^1.1.0",
65+
"@nodesecure/vis-network": "^1.4.0",
66+
"@types/node": "^20.5.3",
67+
"c8": "^8.0.1",
68+
"cross-env": "^7.0.3",
69+
"esbuild": "^0.19.2",
70+
"eslint": "^8.47.0",
71+
"esmock": "^2.3.8",
72+
"http-server": "^14.1.1",
73+
"pkg-ok": "^3.0.0",
74+
"pretty-bytes": "^6.1.1",
75+
"rimraf": "^5.0.5",
76+
"strip-ansi": "^7.1.0"
77+
},
78+
"dependencies": {
79+
"@nodesecure/documentation-ui": "^1.3.0",
80+
"@nodesecure/flags": "^2.4.0",
81+
"@nodesecure/i18n": "^3.4.0",
82+
"@nodesecure/licenses-conformance": "^2.1.0",
83+
"@nodesecure/npm-registry-sdk": "^1.6.1",
84+
"@nodesecure/ossf-scorecard-sdk": "^3.1.0",
85+
"@nodesecure/rc": "^1.5.0",
86+
"@nodesecure/scanner": "^5.1.0",
87+
"@nodesecure/utils": "^1.1.0",
88+
"@nodesecure/vuln": "^1.7.0",
89+
"@openally/result": "^1.2.0",
90+
"@polka/send-type": "^0.5.2",
91+
"@topcli/cliui": "^1.1.0",
92+
"@topcli/spinner": "^2.1.2",
93+
"cacache": "^18.0.0",
94+
"dotenv": "^16.3.1",
95+
"filenamify": "^6.0.0",
96+
"ini": "^4.1.1",
97+
"kleur": "^4.1.5",
98+
"ms": "^2.1.3",
99+
"open": "^9.1.0",
100+
"polka": "^0.5.2",
101+
"qoa": "^0.2.0",
102+
"sade": "^1.8.1",
103+
"semver": "^7.5.4",
104+
"server-destroy": "^1.0.1",
105+
"sirv": "^2.0.3",
106+
"zup": "0.0.1"
107+
}
108+
}

public/js/components/home.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,24 @@ export class HomeView {
2424
}
2525

2626
generateScorecard() {
27-
const { repository } = this.secureDataSet.linker.get(0);
28-
const repoName = utils.getGithubRepositoryPath(
29-
utils.parseRepositoryUrl(repository)
30-
)
27+
const { name } = this.secureDataSet.linker.get(0);
28+
const pkg = this.secureDataSet.data.dependencies[name];
29+
const repoName = utils.getRepositoryName(pkg);
30+
const platform = utils.getRepositoryPlatform(pkg);
31+
3132
if (repoName === null) {
3233
return;
3334
}
3435

35-
fetchScorecardData(repoName).then((data) => {
36+
fetchScorecardData(repoName, platform).then((data) => {
3637
if (data !== null) {
3738
document
3839
.querySelector(".home--header--scorecard .score")
3940
.classList.add(getScoreColor(data.score));
4041
document.getElementById("home-scorecard-score").innerHTML = data.score;
4142
const scorescardElement = document.querySelector(".home--header--scorecard");
4243
scorescardElement.addEventListener("click", () => {
43-
window.open(getScorecardLink(repoName), "_blank");
44+
window.open(getScorecardLink(repoName, platform), "_blank");
4445
});
4546
scorescardElement.style.display = "flex";
4647
}
@@ -209,7 +210,7 @@ export class HomeView {
209210
const maxAuthors = 8;
210211
const hideItems = authors.length > maxAuthors;
211212

212-
for (let id = 0; id<authors.length; id++) {
213+
for (let id = 0; id < authors.length; id++) {
213214
const [name, data] = authors[id];
214215
const { count, email, url = null } = data;
215216

public/js/components/package/package.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class PackageInfo {
1111
if (domElement.classList.contains("slide-in")) {
1212
domElement.setAttribute("class", "slide-out");
1313
}
14+
15+
// window.dispatchEvent(new CustomEvent("package-info-closed", { detail: null }));
1416
}
1517

1618
/**

public/js/components/package/pannels/scorecard.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,23 @@ export class Scorecard {
1818
* @param {!HTMLTemplateElement} clone
1919
*/
2020
generate(clone) {
21-
const githubURL = this.package.links.github;
22-
if (!githubURL.href) {
23-
return this.hide();
24-
}
21+
const repoName = utils.getRepositoryName(this.package);
2522

26-
const repoName = utils.getGithubRepositoryPath(githubURL.href);
27-
if (repoName === null) {
28-
return;
29-
}
3023
const pannel = clone.getElementById("pan-scorecard");
31-
fetchScorecardData(repoName).then((data) => {
24+
const isGitlab = this.package.links.gitlab || utils.isGitLabHost(this.package.links.homepage?.href);
25+
const platform = isGitlab ? "gitlab.com" : "github.com";
26+
27+
fetchScorecardData(repoName, platform).then((data) => {
3228
if (!data) {
3329
return this.hide();
3430
}
3531

36-
pannel.appendChild(this.renderScorecard(data, repoName));
32+
pannel.appendChild(this.renderScorecard(data, repoName, platform));
3733
document.getElementById('scorecard-menu').style.display = 'flex';
3834
});
3935
}
4036

41-
renderScorecard(data, repoName) {
37+
renderScorecard(data, repoName, platform) {
4238
const { score, checks } = data;
4339

4440
const container = utils.createDOMElement('div', {
@@ -56,7 +52,7 @@ export class Scorecard {
5652
document.getElementById('head-score').innerText = score;
5753
document
5854
.querySelector(".score-header .visualizer a")
59-
.setAttribute('href', getScorecardLink(repoName));
55+
.setAttribute('href', getScorecardLink(repoName, platform));
6056

6157
container.childNodes.forEach((check, checkKey) => {
6258
check.addEventListener('click', () => {

0 commit comments

Comments
 (0)