Skip to content

Commit 713ef19

Browse files
Merge pull request #9 from gitcommitshow/chore-test
chore: add tests
2 parents 4ae95c9 + 87ea342 commit 713ef19

File tree

6 files changed

+3028
-8
lines changed

6 files changed

+3028
-8
lines changed

contributors.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*/
55

66
exports.archiveContributorsLeaderboard = archiveContributorsLeaderboard
7+
exports.getAllContributors = getAllContributors;
8+
exports.getRepoContributors = getRepoContributors;
79

810
const https = require('https');
11+
const path = require('path');
912

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

195198
/**
196199
* Writes all contributors data to a file
197-
* @param {Array} contributors
200+
* @param {Array} contributors List of contributors details with their contributions metrics
201+
* @param {Object} options
202+
* @param {string} options.archiveFolder where to save the final content
203+
* @param {string} options.archiveFileName the name of the archive file, the content will be appended if it exists already
198204
*/
199-
function writeContributorLeaderboardToFile(contributors) {
205+
function writeContributorLeaderboardToFile(contributors, options={}) {
206+
if(!contributors || contributors.length<1){
207+
return;
208+
}
209+
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
210+
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
200211
const fs = require('fs');
201212
let ghContributorLeaderboard = contributors.map((contributor) => {
202213
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
203214
}).join("\n");
204215
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
205-
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
216+
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
206217
if (err) {
207218
return console.log(err);
208219
}

0 commit comments

Comments
 (0)