33 * @example To archive contributors leaderboard data in csv file, run `node contributors.js`
44 */
55
6- exports . archiveContributorsLeaderboard = archiveContributorsLeaderboard ;
7- exports . getAllRepos = getAllRepos ;
8- exports . getAllContributors = getAllContributors ;
9- exports . getRepoContributors = getRepoContributors ;
6+ import * as path from 'path' ;
7+ import * as fs from 'fs' ;
108
11- const path = require ( 'path' ) ;
12-
13- const { makeRequest } = require ( './network.js' ) ;
9+ import { makeRequest } from './network.js' ;
1410
1511// Configurations (Optional)
1612// Repo owner that you want to analyze
@@ -37,7 +33,7 @@ if(GITHUB_PERSONAL_TOKEN){
3733 * @returns Promise<Array<Object> | String> JSON array of data on success, error on failure
3834 * @example getAllRepos('myorghandle').then((repos) => console.log(repos)).catch((err) => console.log(err))
3935 */
40- async function getAllRepos ( owner = REPO_OWNER , options ) {
36+ export async function getAllRepos ( owner = REPO_OWNER , options ) {
4137 let pageNo = ( options && options . pageNo ) ? options . pageNo : 1 ;
4238 if ( options && options . GITHUB_PERSONAL_TOKEN ) {
4339 GITHUB_REQUEST_OPTIONS . headers [ "Authorization" ] = "token " + options . GITHUB_PERSONAL_TOKEN ;
@@ -68,7 +64,7 @@ async function getAllRepos(owner=REPO_OWNER, options) {
6864 * @returns Promise<Array<Object> | String>
6965 * @example getRepoContributors('myorghandle/myreponame').then((contributors) => console.log(contributors)).catch((err) => console.log(err))
7066 */
71- async function getRepoContributors ( fullRepoName , pageNo = 1 ) {
67+ export async function getRepoContributors ( fullRepoName , pageNo = 1 ) {
7268 let url = `https://api.github.com/repos/${ fullRepoName } /contributors?per_page=100&page=${ pageNo } ` ;
7369 console . log ( url ) ;
7470 const { res, data } = await makeRequest ( 'GET' , url , Object . assign ( { } , GITHUB_REQUEST_OPTIONS ) ) ;
@@ -93,7 +89,7 @@ async function getRepoContributors(fullRepoName, pageNo = 1) {
9389 * @param {string } owner github user or org handle
9490 * @param {Object } options Additional options
9591 */
96- async function getAllContributors ( owner = REPO_OWNER , options ) {
92+ export async function getAllContributors ( owner = REPO_OWNER , options ) {
9793 let repos = await getAllRepos ( owner , options ) ;
9894 if ( ! repos || repos . length < 1 ) {
9995 console . log ( "Error in getting repos for " + owner )
@@ -182,7 +178,6 @@ function writeContributorLeaderboardToFile(contributors, options={}) {
182178 }
183179 const ARCHIVE_FOLDER = options . archiveFolder || process . cwd ( ) ;
184180 const ARCHIVE_FULL_PATH = path . join ( ARCHIVE_FOLDER , options . archiveFileName || 'archive-gh-contributors-leaderboard.csv' ) ;
185- const fs = require ( 'fs' ) ;
186181 let ghContributorLeaderboard = contributors . map ( ( contributor ) => {
187182 return [ "@" + contributor . login , contributor . contributions , contributor . html_url , contributor . avatar_url , contributor . topContributedRepo , contributor . allContributedRepos ] . join ( ) ;
188183 } ) . join ( "\n" ) ;
@@ -200,7 +195,7 @@ function writeContributorLeaderboardToFile(contributors, options={}) {
200195 * @param {string } owner The organization or user name on GitHub
201196 * @param {Object } options Additional options
202197 */
203- async function archiveContributorsLeaderboard ( owner = REPO_OWNER , options ) {
198+ export async function archiveContributorsLeaderboard ( owner = REPO_OWNER , options ) {
204199 let contributors = await getAllContributors ( owner , options ) ;
205200 if ( ! contributors || contributors . length < 1 ) {
206201 console . log ( "Failed to get contributors for " + owner ) ;
0 commit comments