|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | exports.archiveContributorsLeaderboard = archiveContributorsLeaderboard |
| 7 | +exports.getAllContributors = getAllContributors; |
| 8 | +exports.getRepoContributors = getRepoContributors; |
7 | 9 |
|
8 | 10 | const https = require('https'); |
| 11 | +const path = require('path'); |
9 | 12 |
|
10 | 13 | // Configurations (Optional) |
11 | 14 | // Repo owner that you want to analyze |
@@ -73,7 +76,7 @@ async function getAllRepos(owner=REPO_OWNER, options) { |
73 | 76 | /** |
74 | 77 | * Get contributors for a Github repo |
75 | 78 | * @param {string} fullRepoName e.g. myorghandle/myreponame |
76 | | - * @param {number} pageNo |
| 79 | + * @param {number} pageNo |
77 | 80 | * @returns Promise<Array<Object> | String> |
78 | 81 | * @example getRepoContributors('myorghandle/myreponame').then((contributors) => console.log(contributors)).catch((err) => console.log(err)) |
79 | 82 | */ |
@@ -194,15 +197,23 @@ function sortReposByContributionsCount(repoContributionMappingArray){ |
194 | 197 |
|
195 | 198 | /** |
196 | 199 | * 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 |
198 | 204 | */ |
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'); |
200 | 211 | const fs = require('fs'); |
201 | 212 | let ghContributorLeaderboard = contributors.map((contributor) => { |
202 | 213 | return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join(); |
203 | 214 | }).join("\n"); |
204 | 215 | 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) { |
206 | 217 | if (err) { |
207 | 218 | return console.log(err); |
208 | 219 | } |
|
0 commit comments