-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,412 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
severityLevels: { | ||
NA: 0, | ||
GOOD: 1, | ||
FINE: 2, | ||
WARNING: 3, | ||
BAD: 4 | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
const mongoose = require("mongoose"); | ||
const URL = "mongodb://skoosh:skoosh2002@ds223509.mlab.com:23509/deps-client"; | ||
|
||
// const URL = | ||
// "mongodb://skoosh:skoosh2002@ds127362.mlab.com:27362/newsbie-sandbox"; | ||
|
||
mongoose.connect( | ||
URL, | ||
{ useNewUrlParser: true } | ||
); | ||
mongoose.connect(process.env.DB_URL, { useNewUrlParser: true }); | ||
mongoose.Promise = global.Promise; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { GitHub } = require("../../services"); | ||
|
||
/** | ||
* POST /read_package_json | ||
* Read a json file and return object | ||
*/ | ||
module.exports = async function(req, res) { | ||
if (req.files) { | ||
res.json(JSON.parse(req.files.file.data)); | ||
} else { | ||
let url = req.repoURL; | ||
const packageJSON = await GitHub.getPackageJSONFromRepoUrl(url); | ||
res.json(packageJSON); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { fork } = require("child_process"); | ||
|
||
module.exports = function(socket, packageJson) { | ||
const analyze = fork("./services/analyze"); | ||
analyze.send(packageJson); | ||
analyze.on("message", msg => { | ||
socket.emit(`basic/${msg.type}`, msg.data); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { fork } = require("child_process"); | ||
const { GitHub } = require("../../services"); | ||
|
||
async function analyzeRepoUrl(socket, url) { | ||
const packageJSON = await GitHub.getPackageJSONFromRepoUrl(url); | ||
socket.emit("basic/packageJSON", packageJSON); | ||
|
||
const analyze = fork("./services/analyze"); | ||
analyze.send(packageJSON); | ||
analyze.on("message", msg => { | ||
socket.emit(`basic/${msg.type}`, msg.data); | ||
}); | ||
} | ||
|
||
module.exports = analyzeRepoUrl; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,108 @@ | ||
const moment = require("moment"); | ||
const _ = require("lodash"); | ||
const { severityLevels } = require("../../constants"); | ||
|
||
module.exports = data => { | ||
// 0 = good | ||
// 1 = fine | ||
// 2 = warning | ||
// 3 = bad | ||
// -1 = N/A | ||
const { NA, GOOD, FINE, WARNING, BAD } = severityLevels; | ||
|
||
function calculateLevels(data) { | ||
const levels = { | ||
versionsBehind: -1, | ||
lastPublish: -1, | ||
weeklyDownloads: -1, | ||
stars: -1, | ||
license: -1 | ||
versionsBehind: NA, | ||
lastPublish: NA, | ||
weeklyDownloads: NA, | ||
stars: NA, | ||
license: NA | ||
}; | ||
|
||
levels.versionsBehind = levelMethods.versionsBehind(data.versionsBehind); | ||
levels.lastPublish = levelMethods.lastPublish(data.time); | ||
levels.lastPublish = levelMethods.lastPublish(data.time && data.time.latest); | ||
levels.weeklyDownloads = levelMethods.weeklyDownloads(data.weeklyDownloads); | ||
levels.stars = levelMethods.stars(data.stars); | ||
levels.license = levelMethods.license(data.license); | ||
|
||
return levels; | ||
}; | ||
} | ||
|
||
const levelMethods = { | ||
versionsBehind: data => { | ||
if (!data) return -1; | ||
if (!data || _.isEmpty(data)) return NA; | ||
|
||
if (data.major > 0) { | ||
return 3; | ||
return BAD; | ||
} else if (data.minor > 0) { | ||
return 2; | ||
return WARNING; | ||
} else if (data.patch > 0) { | ||
return 1; | ||
return FINE; | ||
} else if (data.patch === 0) { | ||
return GOOD; | ||
} | ||
return 0; | ||
|
||
return NA; | ||
}, | ||
lastPublish: data => { | ||
if (!data.latest) return null; | ||
const date = moment(data.latest); | ||
|
||
lastPublish: lastPublishISOString => { | ||
if (!lastPublishISOString) return null; | ||
const date = moment(lastPublishISOString); | ||
|
||
if (Math.abs(date.diff(moment(), "years")) > 0) { | ||
return 3; | ||
return BAD; | ||
} else if (Math.abs(date.diff(moment(), "months")) > 6) { | ||
return 2; | ||
return WARNING; | ||
} else if (Math.abs(date.diff(moment(), "months")) > 2) { | ||
return 1; | ||
return FINE; | ||
} else if (Math.abs(date.diff(moment(), "second")) > 1) { | ||
return GOOD; | ||
} | ||
return 0; | ||
|
||
return NA; | ||
}, | ||
|
||
weeklyDownloads: downloads => { | ||
if (!downloads || isNaN(downloads)) return NA; | ||
|
||
if (downloads < 1000) { | ||
return 3; | ||
return BAD; | ||
} else if (downloads < 10000) { | ||
return 2; | ||
return WARNING; | ||
} else if (downloads < 100000) { | ||
return 1; | ||
return FINE; | ||
} | ||
return 0; | ||
return GOOD; | ||
}, | ||
|
||
stars: stars => { | ||
if (!stars || isNaN(stars)) return NA; | ||
|
||
if (stars < 50) { | ||
return 3; | ||
return BAD; | ||
} else if (stars < 300) { | ||
return 2; | ||
return WARNING; | ||
} else if (stars < 1000) { | ||
return 1; | ||
return FINE; | ||
} | ||
|
||
return 0; | ||
return GOOD; | ||
}, | ||
|
||
license: license => { | ||
if (!license) return -1; | ||
if (!license || _.isEmpty(license)) return NA; | ||
|
||
if (typeof license === "object" && "conditions" in license) { | ||
if (typeof license === "object" && "key" in license) { | ||
if (license.key === "mit") { | ||
return 0; | ||
} else if (license.name.includes("GNU")) { | ||
return 3; | ||
return GOOD; | ||
} else if (license.name && license.name.includes("GNU")) { | ||
return BAD; | ||
} else { | ||
return 1; | ||
return FINE; | ||
} | ||
} else { | ||
if (license === "MIT") { | ||
return 0; | ||
return GOOD; | ||
} | ||
} | ||
|
||
return 4; | ||
return BAD; | ||
} | ||
}; | ||
|
||
exports.calculateLevels = calculateLevels; | ||
exports.levelMethods = levelMethods; |
Oops, something went wrong.