Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests #9

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*/

exports.archiveContributorsLeaderboard = archiveContributorsLeaderboard
exports.getAllContributors = getAllContributors;
exports.getRepoContributors = getRepoContributors;

const https = require('https');
const path = require('path');

// Configurations (Optional)
// Repo owner that you want to analyze
Expand Down Expand Up @@ -73,7 +76,7 @@ async function getAllRepos(owner=REPO_OWNER, options) {
/**
* Get contributors for a Github repo
* @param {string} fullRepoName e.g. myorghandle/myreponame
* @param {number} pageNo
* @param {number} pageNo
* @returns Promise<Array<Object> | String>
* @example getRepoContributors('myorghandle/myreponame').then((contributors) => console.log(contributors)).catch((err) => console.log(err))
*/
Expand Down Expand Up @@ -194,15 +197,23 @@ function sortReposByContributionsCount(repoContributionMappingArray){

/**
* Writes all contributors data to a file
* @param {Array} contributors
* @param {Array} contributors List of contributors details with their contributions metrics
* @param {Object} options
* @param {string} options.archiveFolder where to save the final content
* @param {string} options.archiveFileName the name of the archive file, the content will be appended if it exists already
*/
function writeContributorLeaderboardToFile(contributors) {
function writeContributorLeaderboardToFile(contributors, options={}) {
if(!contributors || contributors.length<1){
return;
}
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
const fs = require('fs');
let ghContributorLeaderboard = contributors.map((contributor) => {
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
}).join("\n");
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
if (err) {
return console.log(err);
}
Expand Down
Loading