Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
fu351 committed Dec 13, 2023
1 parent ce6a668 commit d142b60
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var createCustomLogger = function (labelStr, level) {
transports: [
new winston_1.transports.Console(),
new winston_1.transports.File({
filename: "logile.log"
filename: process.env.LOG_FILE
}),
]
});
Expand Down
14 changes: 14 additions & 0 deletions logile.log
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@
at IncomingMessage.emit (node:domain:489:12)
at endReadableNT (node:internal/streams/readable:1359:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-12-13T06:50:15.294Z [DEBUG] debug: Error: AxiosError: Request failed with status code 401
at settle (/home/shay/a/fu351/Desktop/Team-17-/node_modules/axios/lib/core/settle.js:19:12)
at IncomingMessage.handleStreamEnd (/home/shay/a/fu351/Desktop/Team-17-/node_modules/axios/lib/adapters/http.js:585:11)
at IncomingMessage.emit (node:events:526:35)
at IncomingMessage.emit (node:domain:489:12)
at endReadableNT (node:internal/streams/readable:1359:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-12-13T06:50:33.089Z [DEBUG] debug: Error: AxiosError: Request failed with status code 401
at settle (/home/shay/a/fu351/Desktop/Team-17-/node_modules/axios/lib/core/settle.js:19:12)
at IncomingMessage.handleStreamEnd (/home/shay/a/fu351/Desktop/Team-17-/node_modules/axios/lib/adapters/http.js:585:11)
at IncomingMessage.emit (node:events:526:35)
at IncomingMessage.emit (node:domain:489:12)
at endReadableNT (node:internal/streams/readable:1359:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
18 changes: 14 additions & 4 deletions npm-github-netscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ function extractGitHubInfo(npmPackageUrl) {
case 4:
error_4 = _c.sent();
logBasedOnVerbosity("Error extracting GitHub info: ".concat(error_4.message), 2);
process.exit(1);
return [3 /*break*/, 5];
console.log(error_4);
//process.exit(1);
return [2 /*return*/, null];
case 5: return [2 /*return*/];
}
});
Expand All @@ -307,7 +308,7 @@ function cloneREPO(username, repository) {
case 2:
error_5 = _b.sent();
logBasedOnVerbosity("Error cloning repository: ".concat(error_5.message), 2);
process.exit(1);
console.log(error_5); //process.exit(1);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
Expand Down Expand Up @@ -375,7 +376,8 @@ function countLines(filePath) {
}
catch (error) {
logBasedOnVerbosity("Error reading file: ".concat(filePath), 2);
process.exit(1);
console.log(error); //process.exit(1);
return 0;
}
}
function getDependencyData(getUsername, repositoryName, personalAccessToken) {
Expand Down Expand Up @@ -480,6 +482,7 @@ function fetchGitHubInfo(npmPackageUrl, personalAccessToken) {
case 1: return [4 /*yield*/, extractGitHubInfo(npmPackageUrl)];
case 2:
githubInfo = _b.sent();
console.log("extracted github info", githubInfo);
if (!githubInfo) return [3 /*break*/, 13];
headers = {
Authorization: "Bearer ".concat(personalAccessToken)
Expand All @@ -496,25 +499,31 @@ function fetchGitHubInfo(npmPackageUrl, personalAccessToken) {
case 4:
//gather info
_b.sent();
console.log("cloned repo");
issue_count = response.data.open_issues_count;
console.log("issue count", issue_count);
return [4 /*yield*/, getCommitsPerContributor(githubInfo.username, githubInfo.repository, personalAccessToken)];
case 5:
contributor_commits = _b.sent();
console.log(";emngth", contributor_commits.length);
return [4 /*yield*/, getTimeSinceLastCommit(githubInfo.username, githubInfo.repository)];
case 6:
days_since_last_commit = _b.sent();
console.log("days since last commit", days_since_last_commit);
return [4 /*yield*/, getRepoLicense(response.data.license)];
case 7:
repoLicense = _b.sent();
console.log("repo license", repoLicense);
return [4 /*yield*/, getReviewedLines(githubInfo.username, githubInfo.repository, personalAccessToken)];
case 8:
code_review_score = _b.sent();
console.log("code review score", code_review_score);
rootDirectory = "./cli_storage/".concat(githubInfo.repository);
return [4 /*yield*/, traverseDirectory(rootDirectory)];
case 9:
totalLines = _b.sent();
total_lines = totalLines[1] - totalLines[0];
console.log("total lines", total_lines);
return [4 /*yield*/, getDependencyData(githubInfo.username, githubInfo.repository, personalAccessToken)];
case 10:
_a = _b.sent(), assigned_dependencies = _a[0], unassigned_dependencies = _a[1];
Expand Down Expand Up @@ -542,6 +551,7 @@ function fetchGitHubInfo(npmPackageUrl, personalAccessToken) {
//fs.writeFileSync(`./cli_storage/${githubInfo.repository}/popularity.json`, JSON.stringify(popularity, null, 2));
//Reverted back to returning as array of variables instead of JSON files, planning to save netscore as attribute instead of saving json file
//Scores also contains the popularity score.
console.log("completed");
return [2 /*return*/, scores];
case 13: return [4 /*yield*/, (0, metrics_1.calculate_net_score)([0], 0, 0, 0, 'unlicense', 0, 0, 0, 0, npmPackageUrl)];
case 14:
Expand Down
19 changes: 15 additions & 4 deletions npm-github-netscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ async function extractGitHubInfo(npmPackageUrl: string): Promise<{ username: str
}
} catch (error) {
logBasedOnVerbosity(`Error extracting GitHub info: ${error.message}`, 2);
process.exit(1);
console.log(error);
//process.exit(1);
return null
}
}
async function cloneREPO(username: string, repository: string) {
Expand All @@ -256,7 +258,7 @@ async function cloneREPO(username: string, repository: string) {

} catch (error) {
logBasedOnVerbosity(`Error cloning repository: ${error.message}`, 2);
process.exit(1);
console.log(error);//process.exit(1);
}
}

Expand Down Expand Up @@ -307,7 +309,8 @@ try {
return lines.length;
} catch (error) {
logBasedOnVerbosity(`Error reading file: ${filePath}`, 2);
process.exit(1);
console.log(error);//process.exit(1);
return 0;
}
}
async function getDependencyData(getUsername: string, repositoryName: string, personalAccessToken: string) {
Expand Down Expand Up @@ -383,6 +386,7 @@ async function fetchGitHubInfo(npmPackageUrl: string, personalAccessToken: strin
}
else {
const githubInfo = await extractGitHubInfo(npmPackageUrl);
console.log("extracted github info", githubInfo);
if (githubInfo) {

//console.log(githubInfo);
Expand All @@ -399,16 +403,22 @@ async function fetchGitHubInfo(npmPackageUrl: string, personalAccessToken: strin
const response = await axios.get(url, axiosConfig);
//gather info
await cloneREPO(githubInfo.username, githubInfo.repository);

console.log("cloned repo")
const issue_count: number = response.data.open_issues_count;
console.log("issue count",issue_count);
const contributor_commits: number[] = await getCommitsPerContributor(githubInfo.username, githubInfo.repository, personalAccessToken) as number[];

console.log(";emngth",contributor_commits.length);
const days_since_last_commit: number = await getTimeSinceLastCommit(githubInfo.username, githubInfo.repository) as number;
console.log("days since last commit",days_since_last_commit);
const repoLicense = await getRepoLicense(response.data.license);
console.log("repo license",repoLicense);
const code_review_score = await getReviewedLines(githubInfo.username, githubInfo.repository, personalAccessToken);
console.log("code review score",code_review_score);
const rootDirectory = `./cli_storage/${githubInfo.repository}`;
const totalLines = await traverseDirectory(rootDirectory);
const total_lines = totalLines[1] - totalLines[0];
console.log("total lines",total_lines);
//console.log(githubInfo);

const [assigned_dependencies, unassigned_dependencies] = await getDependencyData(githubInfo.username, githubInfo.repository, personalAccessToken) as [number,number];
Expand All @@ -434,6 +444,7 @@ async function fetchGitHubInfo(npmPackageUrl: string, personalAccessToken: strin

//Reverted back to returning as array of variables instead of JSON files, planning to save netscore as attribute instead of saving json file
//Scores also contains the popularity score.
console.log("completed");
return scores
}
else {
Expand Down

0 comments on commit d142b60

Please sign in to comment.