From c28dedb69b554bc2a1a8339a3e464018b8c95c1b Mon Sep 17 00:00:00 2001 From: mastal88 Date: Sat, 28 Sep 2019 06:56:33 +0200 Subject: [PATCH] Remove redundant function from community-toolbox.js #218 (#268) --- dist/community-toolbox.js | 3085 +++++++++++++++--------------- src/scripts/community-toolbox.js | 13 +- 2 files changed, 1539 insertions(+), 1559 deletions(-) diff --git a/dist/community-toolbox.js b/dist/community-toolbox.js index f441cfae..f51f1a3c 100644 --- a/dist/community-toolbox.js +++ b/dist/community-toolbox.js @@ -26696,7 +26696,7 @@ module.exports={ "_args": [ [ "elliptic@6.4.1", - "/home/rishabh570/community-toolbox" + "C:\\Projects\\OSS\\community-toolbox" ] ], "_development": true, @@ -26722,7 +26722,7 @@ module.exports={ ], "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", "_spec": "6.4.1", - "_where": "/home/rishabh570/community-toolbox", + "_where": "C:\\Projects\\OSS\\community-toolbox", "author": { "name": "Fedor Indutny", "email": "fedor@indutny.com" @@ -27566,7 +27566,7 @@ module.exports={ "_args": [ [ "git://github.com/jywarren/github-api-simple.git#patch-2", - "/home/rishabh570/community-toolbox" + "C:\\Projects\\OSS\\community-toolbox" ] ], "_development": true, @@ -27589,7 +27589,7 @@ module.exports={ ], "_resolved": "git://github.com/jywarren/github-api-simple.git#cb5b7f778ea9c8b65641b64b8c02f43cedf6672e", "_spec": "git://github.com/jywarren/github-api-simple.git#patch-2", - "_where": "/home/rishabh570/community-toolbox", + "_where": "C:\\Projects\\OSS\\community-toolbox", "author": { "name": "Michiel van der Velde", "email": "michiel@michielvdvelde.nl" @@ -77488,7 +77488,7 @@ module.exports={ "_args": [ [ "tough-cookie@2.4.3", - "/home/rishabh570/community-toolbox" + "C:\\Projects\\OSS\\community-toolbox" ] ], "_development": true, @@ -77509,11 +77509,13 @@ module.exports={ "fetchSpec": "2.4.3" }, "_requiredBy": [ - "/request" + "/jsdom", + "/request", + "/request-promise-native" ], "_resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "_spec": "2.4.3", - "_where": "/home/rishabh570/community-toolbox", + "_where": "C:\\Projects\\OSS\\community-toolbox", "author": { "name": "Jeremy Stashewsky", "email": "jstash@gmail.com" @@ -81616,1601 +81618,1590 @@ function extend() { } },{}],399:[function(require,module,exports){ -var insertContributorsExec = false; - - -function insertContributors(AllContributors){ - // This removes the spinner icon as soon as contributors list is loaded - document.getElementById("spinner-icon").style.display = "none"; - - let totalContributors = 0; - var usernames = AllContributors.map(function getContributorUsername(c) { - return `@${c.login}`; - }); - var avatars = AllContributors.map(function getContributorAvatarURL(c) { - return ``; - }); - totalContributors += AllContributors.length; - if(insertContributorsExec) $('.contributors > .usernames').append(', '); - $('.contributors-head').html('Contributors ('+totalContributors+'+)'); - $('.contributors > .usernames').append(usernames.join(', ')); - $('.contributors > .avatars').append(avatars.join('')); - insertContributorsExec=true; - } - - -module.exports = { - insertContributors: insertContributors, +var insertContributorsExec = false; + + +function insertContributors(AllContributors){ + // This removes the spinner icon as soon as contributors list is loaded + document.getElementById("spinner-icon").style.display = "none"; + + let totalContributors = 0; + var usernames = AllContributors.map(function getContributorUsername(c) { + return `@${c.login}`; + }); + var avatars = AllContributors.map(function getContributorAvatarURL(c) { + return ``; + }); + totalContributors += AllContributors.length; + if(insertContributorsExec) $('.contributors > .usernames').append(', '); + $('.contributors-head').html('Contributors ('+totalContributors+'+)'); + $('.contributors > .usernames').append(usernames.join(', ')); + $('.contributors > .avatars').append(avatars.join('')); + insertContributorsExec=true; + } + + +module.exports = { + insertContributors: insertContributors, }; },{}],400:[function(require,module,exports){ -function insertFtoIssueAuthor(issueSet) { - let avatars=[]; - for(let [key, value] of Object.entries(issueSet)) { - avatars.push(``); - } - $('.fto-authors').append(avatars.join(' ')); - } - - -module.exports = { - insertFtoIssueAuthor: insertFtoIssueAuthor +function insertFtoIssueAuthor(issueSet) { + let avatars=[]; + for(let [key, value] of Object.entries(issueSet)) { + avatars.push(``); + } + $('.fto-authors').append(avatars.join(' ')); + } + + +module.exports = { + insertFtoIssueAuthor: insertFtoIssueAuthor } },{}],401:[function(require,module,exports){ -var moment = require('moment'); - - - -function generateIssueHtml(title, body, githubUrl, repo) { - var repoName = githubUrl.split('/')[4], - repoUrl = githubUrl.split('/').slice(0, 5).join('/'), - html = '
\ - \ -
\ - ' + body + '\ -
\ -
'; - return html; - } - -function insertIssue(issue, el) { - var body = ""; - body += "
" - issue.labels.forEach(function(label) { - body += "" + label.name + " "; - }); - body += "
"; - body += "#" + issue.number + " opened " + moment(issue.updated_at).fromNow() + " "; - body += "by " + issue.user.login + ""; - body += " " + issue.comments; - $(el).append(generateIssueHtml(issue.title, body, issue.html_url, issue)); -} - - -function insertStale(issues, selector) { - let issuesLen = issues.length; - $('#stale-head').html('Stale Issues ('+issuesLen+'+)'); - issues.forEach(function (issue) { - insertIssue(issue, selector); - }) -} - - - - -module.exports = { - generateIssueHtml: generateIssueHtml, - insertIssue: insertIssue, - insertStale: insertStale +var moment = require('moment'); + + + +function generateIssueHtml(title, body, githubUrl, repo) { + var repoName = githubUrl.split('/')[4], + repoUrl = githubUrl.split('/').slice(0, 5).join('/'), + html = '
\ + \ +
\ + ' + body + '\ +
\ +
'; + return html; + } + +function insertIssue(issue, el) { + var body = ""; + body += "
" + issue.labels.forEach(function(label) { + body += "" + label.name + " "; + }); + body += "
"; + body += "#" + issue.number + " opened " + moment(issue.updated_at).fromNow() + " "; + body += "by " + issue.user.login + ""; + body += " " + issue.comments; + $(el).append(generateIssueHtml(issue.title, body, issue.html_url, issue)); +} + + +function insertStale(issues, selector) { + let issuesLen = issues.length; + $('#stale-head').html('Stale Issues ('+issuesLen+'+)'); + issues.forEach(function (issue) { + insertIssue(issue, selector); + }) +} + + + + +module.exports = { + generateIssueHtml: generateIssueHtml, + insertIssue: insertIssue, + insertStale: insertStale }; },{"moment":271}],402:[function(require,module,exports){ - -var insertRecentContributorsExec = false; -let filterUniqueUtil = require('../utils/filterUniqueContribs') - - -function insertRecentContributors(AllContributors){ - let usernames, avatars; - let recentContributors = 0; - - if(AllContributors instanceof Map) { - AllContributors = [ ...AllContributors.entries() ]; - - usernames = AllContributors.map((userArray, i) => { - return `@${userArray[0]}`; - }) - avatars = AllContributors.map((userArray, i) => { - return ``; - }) - } - else { - // Removes duplicate data in the recent contributors list - AllContributors = filterUniqueUtil.filterUniqueContribs(AllContributors); - - usernames = AllContributors.map((commit, i) => { - return `@${commit.author.login}`; - }) - avatars = AllContributors.map((commit, i) => { - return ``; - }) - } - - recentContributors += AllContributors.length; - - if(insertRecentContributorsExec) $('.recent-contributors > .usernames').append(', '); - $('.recent-contributors-head').html('Recent Contributors ('+recentContributors+'+)'); - $('.recent-contributors-body > .recent-contrib-content-box > .usernames').html(usernames.join(', ')); - $('.recent-contributors-body > .recent-contrib-content-box > .avatars').html(avatars.join('')); - insertRecentContributorsExec=true; - } - - -module.exports = { - insertRecentContributors: insertRecentContributors, + +var insertRecentContributorsExec = false; +let filterUniqueUtil = require('../utils/filterUniqueContribs') + + +function insertRecentContributors(AllContributors){ + let usernames, avatars; + let recentContributors = 0; + + if(AllContributors instanceof Map) { + AllContributors = [ ...AllContributors.entries() ]; + + usernames = AllContributors.map((userArray, i) => { + return `@${userArray[0]}`; + }) + avatars = AllContributors.map((userArray, i) => { + return ``; + }) + } + else { + // Removes duplicate data in the recent contributors list + AllContributors = filterUniqueUtil.filterUniqueContribs(AllContributors); + + usernames = AllContributors.map((commit, i) => { + return `@${commit.author.login}`; + }) + avatars = AllContributors.map((commit, i) => { + return ``; + }) + } + + recentContributors += AllContributors.length; + + if(insertRecentContributorsExec) $('.recent-contributors > .usernames').append(', '); + $('.recent-contributors-head').html('Recent Contributors ('+recentContributors+'+)'); + $('.recent-contributors-body > .recent-contrib-content-box > .usernames').html(usernames.join(', ')); + $('.recent-contributors-body > .recent-contrib-content-box > .avatars').html(avatars.join('')); + insertRecentContributorsExec=true; + } + + +module.exports = { + insertRecentContributors: insertRecentContributors, }; },{"../utils/filterUniqueContribs":413}],403:[function(require,module,exports){ -let db; -let init = require('../models/initialize') - -function populateDb() { - return init.dbInit().then((response) => { - db = response; - return; - }); -} - - -// Stores items to the database -function saveContentToDb(queryKey, queryContent) { - // Start a database transaction and get the toolbox object store - let tx = db.transaction(["toolbox"], 'readwrite'); - let store = tx.objectStore('toolbox'); - - // Put the data into the object store - let temp = { keys: queryKey, content: queryContent }; - store.add(temp); - - // Wait for the database transaction to complete - tx.oncomplete = function() { - console.log("Entry added to store successfully!"); - return; - } - tx.onerror = function(event) { - console.log('error storing content'); - return; - } -} - - -// Fetches items from the database -function getContentFromDb(query) { - let tx = db.transaction(["toolbox"], 'readonly'); - let store = tx.objectStore("toolbox"); - let index = store.index("keys"); - - return new Promise((resolve, reject) => { - - let request = index.openCursor(IDBKeyRange.only(query)); - - request.onsuccess = function(e) { - let cursor = e.target.result; - if (cursor) { - // Called for each matching record. - resolve(cursor.value.content); - } else { - // This null is very important, because we have a check for null - // in the functions of community-toolbox.js - resolve(null); - } - } - }) -} - - -// Deletes items from the database -function deleteItemFromDb(query) { - let tx = db.transaction(["toolbox"], 'readwrite'); - let store = tx.objectStore("toolbox"); - let index = store.index("keys"); - - return new Promise((resolve, reject) => { - - let request = index.openCursor(IDBKeyRange.only(query)); - - request.onsuccess = function(e) { - let cursor = e.target.result; - if (cursor) { - // Called for each matching record. - store.delete(cursor.key); - - // Wait for the database transaction to complete - tx.oncomplete = function() { - console.log("Entry deleted from store successfully!"); - resolve(true); - } - tx.onerror = function(event) { - console.log('error deleting content: ' + event.target); - reject(false); - } - } else { - // No more matching records. - console.log("No matching entry found to be deleted :("); - resolve(null); - } - } - }) -} - - - - - - - -// EXPORTS -module.exports.saveContentToDb = saveContentToDb; -module.exports.getContentFromDb = getContentFromDb; -module.exports.deleteItemFromDb = deleteItemFromDb; -module.exports.populateDb = populateDb; +let db; +let init = require('../models/initialize') + +function populateDb() { + return init.dbInit().then((response) => { + db = response; + return; + }); +} + + +// Stores items to the database +function saveContentToDb(queryKey, queryContent) { + // Start a database transaction and get the toolbox object store + let tx = db.transaction(["toolbox"], 'readwrite'); + let store = tx.objectStore('toolbox'); + + // Put the data into the object store + let temp = { keys: queryKey, content: queryContent }; + store.add(temp); + + // Wait for the database transaction to complete + tx.oncomplete = function() { + console.log("Entry added to store successfully!"); + return; + } + tx.onerror = function(event) { + console.log('error storing content'); + return; + } +} + + +// Fetches items from the database +function getContentFromDb(query) { + let tx = db.transaction(["toolbox"], 'readonly'); + let store = tx.objectStore("toolbox"); + let index = store.index("keys"); + + return new Promise((resolve, reject) => { + + let request = index.openCursor(IDBKeyRange.only(query)); + + request.onsuccess = function(e) { + let cursor = e.target.result; + if (cursor) { + // Called for each matching record. + resolve(cursor.value.content); + } else { + // This null is very important, because we have a check for null + // in the functions of community-toolbox.js + resolve(null); + } + } + }) +} + + +// Deletes items from the database +function deleteItemFromDb(query) { + let tx = db.transaction(["toolbox"], 'readwrite'); + let store = tx.objectStore("toolbox"); + let index = store.index("keys"); + + return new Promise((resolve, reject) => { + + let request = index.openCursor(IDBKeyRange.only(query)); + + request.onsuccess = function(e) { + let cursor = e.target.result; + if (cursor) { + // Called for each matching record. + store.delete(cursor.key); + + // Wait for the database transaction to complete + tx.oncomplete = function() { + console.log("Entry deleted from store successfully!"); + resolve(true); + } + tx.onerror = function(event) { + console.log('error deleting content: ' + event.target); + reject(false); + } + } else { + // No more matching records. + console.log("No matching entry found to be deleted :("); + resolve(null); + } + } + }) +} + + + + + + + +// EXPORTS +module.exports.saveContentToDb = saveContentToDb; +module.exports.getContentFromDb = getContentFromDb; +module.exports.deleteItemFromDb = deleteItemFromDb; +module.exports.populateDb = populateDb; },{"../models/initialize":404}],404:[function(require,module,exports){ -// This function is responsible for setting up the database -function dbInit() { - let db; - let dbReq = indexedDB.open('publiclabDB'); - return new Promise((resolve, reject) => { - // Fires when upgrade needed - dbReq.onupgradeneeded = function(event) { - // Set the db variable to our database so we can use it - db = event.target.result; - - // Create an object store named toolbox, or retrieve it if it already exists. - // Object stores in databases are where data are stored. - let toolbox; - if (!db.objectStoreNames.contains('toolbox')) { - toolbox = db.createObjectStore('toolbox', {autoIncrement: true, keyPath: "keys"}); - } else { - toolbox = db.transaction("toolbox", "readwrite").objectStore("toolbox"); - } - - // If there isn't already a KEY index, make one so we can query toolbox - // by their KEY - if (!toolbox.indexNames.contains('keys')) { - toolbox.createIndex('keys', 'keys', { unique: true }); - }else { - console.log("KEY index is already created"); - } - - // If there isn't already a CONTENT index, make one so we can query toolbox - // by their CONTENT - if (!toolbox.indexNames.contains('content')) { - toolbox.createIndex('content', 'content', { unique: false }); - } else { - console.log("content index is already created"); - } - - } - - // Fires once the database is opened (and onupgradeneeded completes, if - // onupgradeneeded was called) - dbReq.onsuccess = function(event) { - // Set the db variable to our database so we can use it - db = event.target.result; - resolve(db); - } - - // Fires when we can't open the database - dbReq.onerror = function(event) { - console.log('error opening database'); - resolve(null); - } - - }) - - -} - - -module.exports = { - dbInit: dbInit, -} - +// This function is responsible for setting up the database +function dbInit() { + let db; + let dbReq = indexedDB.open('publiclabDB'); + return new Promise((resolve, reject) => { + // Fires when upgrade needed + dbReq.onupgradeneeded = function(event) { + // Set the db variable to our database so we can use it + db = event.target.result; + + // Create an object store named toolbox, or retrieve it if it already exists. + // Object stores in databases are where data are stored. + let toolbox; + if (!db.objectStoreNames.contains('toolbox')) { + toolbox = db.createObjectStore('toolbox', {autoIncrement: true, keyPath: "keys"}); + } else { + toolbox = db.transaction("toolbox", "readwrite").objectStore("toolbox"); + } + + // If there isn't already a KEY index, make one so we can query toolbox + // by their KEY + if (!toolbox.indexNames.contains('keys')) { + toolbox.createIndex('keys', 'keys', { unique: true }); + }else { + console.log("KEY index is already created"); + } + + // If there isn't already a CONTENT index, make one so we can query toolbox + // by their CONTENT + if (!toolbox.indexNames.contains('content')) { + toolbox.createIndex('content', 'content', { unique: false }); + } else { + console.log("content index is already created"); + } + + } + + // Fires once the database is opened (and onupgradeneeded completes, if + // onupgradeneeded was called) + dbReq.onsuccess = function(event) { + // Set the db variable to our database so we can use it + db = event.target.result; + resolve(db); + } + + // Fires when we can't open the database + dbReq.onerror = function(event) { + console.log('error opening database'); + resolve(null); + } + + }) + + +} + + +module.exports = { + dbInit: dbInit, +} + },{}],405:[function(require,module,exports){ -var model = require('./crud'); - - -function setItem(queryKey, queryContent) { - model.saveContentToDb(queryKey, queryContent); - return; -} - -function getItem(query) { - return model.getContentFromDb(query).then((result) => { - return result; - }); -} - -function deleteItem(query) { - return model.deleteItemFromDb(query).then(() => { - return; - }) - -} - - - -// EXPORTS -module.exports.setItem = setItem; -module.exports.getItem = getItem; -module.exports.deleteItem = deleteItem; +var model = require('./crud'); + + +function setItem(queryKey, queryContent) { + model.saveContentToDb(queryKey, queryContent); + return; +} + +function getItem(query) { + return model.getContentFromDb(query).then((result) => { + return result; + }); +} + +function deleteItem(query) { + return model.deleteItemFromDb(query).then(() => { + return; + }) + +} + + + +// EXPORTS +module.exports.setItem = setItem; +module.exports.getItem = getItem; +module.exports.deleteItem = deleteItem; },{"./crud":403}],406:[function(require,module,exports){ -// view-source:http://www.chartjs.org/samples/latest/charts/bar/vertical.html -function generateChart(args) { - - args = args || {}; - args.data = args.data || []; - args.label = args.label || ""; - args.title = args.title || ""; - - var colors = { - "blue": "rgb(54, 162, 235)", - "red": "rgb(255, 99, 132)", - "green": "rgb(75, 192, 192)", - "grey": "rgb(201, 203, 207)", - "orange": "rgb(255, 159, 64)", - "purple": "rgb(153, 102, 255)", - "yellow": "rgb(255, 205, 86)" - } - var colorNames = Object.keys(colors); - - var barChartData = { - // labels: ["January", "February", "March", "April", "May", "June", "July"], - datasets: [{ - label: args.label, - backgroundColor: colors['red'], - borderColor: colors['red'], - borderWidth: 1, - data: args.data - }] - } - - var ctx = document.getElementById("canvas").getContext("2d"); - var chart = new Chart(ctx, { - type: 'bar', - data: barChartData, - options: { - responsive: true, - legend: { - position: 'top', - }, - title: { - display: true, - text: args.title - } - } - }); - - return chart; - -} - -module.exports = generateChart; +// view-source:http://www.chartjs.org/samples/latest/charts/bar/vertical.html +function generateChart(args) { + + args = args || {}; + args.data = args.data || []; + args.label = args.label || ""; + args.title = args.title || ""; + + var colors = { + "blue": "rgb(54, 162, 235)", + "red": "rgb(255, 99, 132)", + "green": "rgb(75, 192, 192)", + "grey": "rgb(201, 203, 207)", + "orange": "rgb(255, 159, 64)", + "purple": "rgb(153, 102, 255)", + "yellow": "rgb(255, 205, 86)" + } + var colorNames = Object.keys(colors); + + var barChartData = { + // labels: ["January", "February", "March", "April", "May", "June", "July"], + datasets: [{ + label: args.label, + backgroundColor: colors['red'], + borderColor: colors['red'], + borderWidth: 1, + data: args.data + }] + } + + var ctx = document.getElementById("canvas").getContext("2d"); + var chart = new Chart(ctx, { + type: 'bar', + data: barChartData, + options: { + responsive: true, + legend: { + position: 'top', + }, + title: { + display: true, + text: args.title + } + } + }); + + return chart; + +} + +module.exports = generateChart; },{}],407:[function(require,module,exports){ - -CommunityToolbox = function CommunityToolbox(org, repo) { - - - var SimpleApi = require('github-api-simple') - var api = new SimpleApi(); - - var crud = require('../models/crud') - var issuesUI = require('../UI/issuesUI') - var model_utils = require('../models/utils') - var fetchReposUtil = require('../utils/repoUtil/fetchRepoUtil') - var contributorsUI = require('../UI/contributorsUI') - var contributorsUtil = require('../utils/contribsUtil/main') - var recentContributorsUI = require('../UI/recentContributorsUI') - var navDropdownUtil = require('../utils/navDropdown.js') - var ftoAuthorsUI = require('../UI/ftoAuthorsUI') - var issuesUtil = require('../utils/staleIssuesUtil') - var recentContribsUtil = require('../utils/recentContribsUtil/main') - var filterUtil = require('../utils/filterUtil') - - - const requestP = require('request-promise') - var parse = require('parse-link-header') - var chart = require('./chart'); - - var options = { - 'qs': { - 'sort': 'pushed', - 'direction': 'desc', // optional, GitHub API uses 'desc' by default for 'pushed' - 'per_page': 100 - } - } - - // these are essentially examples for now; we could wrap them - // in externally available methods for convenience but at the - // moment they're not quite complex enough to merit it. - - function getIssuesForRepo(callback, _options) { - _options = _options || options; - api.Issues - .getIssuesForRepo(org, repo, _options) - .then(callback); - } - - function getIssuesForOrg(_org, _options) { - _options = _options || options; - var _url = "https://api.github.com/search/issues?q=is%3Aopen+org%3A" + _org + "+label%3A" + _options.qs.labels; - return requestP({ uri: _url }); - } - - function getCommitsForRepo(callback, _options) { - _options = _options || options; - api.Repositories - .getRepoCommits(org, repo, _options) - .then(callback); - } - - - function initialize(org, repo) { - return new Promise((resolve, reject) => { - return crud.populateDb() - .then((res) => { - return true; - }) - .then((dummy) => { - return model_utils.getItem('repos').then((response) => { - if(response==null || response==undefined) { - // Fetches and stores the list of repositories when the page loads - return fetchReposUtil.getAllRepos(org) - .then((resp) => { - resolve(true); - }) - .catch((err) => { - Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); - }) - } - resolve(true); - }); - }) - }); - } - - - function dropdownInit() { - return model_utils.getItem('repos') - .then((res) => { - if(res!=null && res!=undefined) { - navDropdownUtil.populateNavDropdown(res); - }else { - console.log("not working"); - } - }) - } - - - // This function is responsible for showing contributors - // on a multi-repository view - function showAllContributors(org) { - return contributorsUtil.fetchAllContribsInDb(org) - .then((allContributors) => { - // If the stored data is not undefined or null, execution goes here - if(allContributors!=null && allContributors!=undefined && allContributors.length>0) { - // Flushes contributors list from the database after every single day - let timeNow = (new Date).getTime(); - model_utils.getItem('allContributorsExpiry') - .then((allContributorsExpiry) => { - if (allContributorsExpiry!=null && ((timeNow-allContributorsExpiry)/1000) >= 86400) { - return Promise.all([model_utils.deleteItem('allContributors'), model_utils.deleteItem('allContributorsExpiry')]) - .then(()=> { - return true; - }) - } - }) - .then(()=> { - // Looking for contributors list in the database - model_utils.getItem('allContributors').then((AllContributors) => { - // If the data is not in the database, it gets fetched from storeAllContributorsInDatabase function - if(AllContributors == null || AllContributors == undefined || AllContributors.length==0) { - - contributorsUtil.fetchAllContribsInDb(org) - .then(function gotAllContributors(AllContributors) { - // Provides fetched contributors list to UI function for rendering it - // to the user - contributorsUI.insertContributors(AllContributors); - }) - .catch((err) => { - throw err; - }) - } - // If stored data is not null and undefined, process it - else { - contributorsUI.insertContributors(AllContributors); - } - }) - }) - } - // If execution goes here, it means that there's probably something wrong - // in the storeAllContributorsInDatabase function - else { - console.log("Something went wrong while fetching all contributors :("); - } - }) - .catch((err) => { - Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); - }) - } - - - // This function is responsible for showing all the contributors for a particular repository - function showRepoContributors(org, repo) { - return contributorsUtil.fetchAllContribsInDb(org) - .then((allContributors) => { - // If the stored data is not undefined or null, execution goes here - if(allContributors != null && allContributors!=undefined && allContributors.length>0) { - // Flushes repoContributors from the database after every single day - let timeNow = (new Date).getTime(); - model_utils.getItem(`${repo}Expiry`) - .then((lifespan) => { - if (lifespan!=null && ((timeNow-lifespan)/1000) >= 86400) { - return Promise.all([model_utils.deleteItem(`${repo}`), model_utils.deleteItem(`${repo}Expiry`)]) - .then(()=>{ - return true; - }) - } - }) - .then(()=>{ - // Looking for repo Contributors list in the database - model_utils.getItem(repo).then((repoContributors) => { - // If we don't have repoContributors in the database, we fetch them from Github - if (repoContributors == null || repoContributors == undefined) { - contributorsUtil.repoContribsUtil(org, repo) - .then(function gotRepoContributorsInStorage (contributors) { - contributorsUI.insertContributors(contributors); - return; - }) - .catch((err) => { - throw err; - }) - } - // If we have repoContributors in the database, we save a network call :) - else { - contributorsUI.insertContributors(repoContributors); - return; - } - }) - }) - } else { - // Execution goes here, it means that data for this repo is not available - // in the database - console.log(`Something went wrong while getting ${repo} contributors :(`); - } - }) - .catch((err) => { - Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); - }) - } - - - // Function for fetching and showing recent contributors - function showRecentContributors(org, repo, recencyLabel, forMonths=6) { - return recentContribsUtil.fetchAllRecentContribsInDb(org, repo).then((result)=>{ - if(recencyLabel==="month") { - return recentContribsUtil.fetchContribsLastMonth(org, repo, forMonths) - .then(function gotMonthlyContribs(monthContribs) { - // Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter - model_utils.deleteItem('recent-contribs-data').then((res)=> { - model_utils.setItem('recent-contribs-data', monthContribs); - }) - // Push data to UI - recentContributorsUI.insertRecentContributors(monthContribs); - return; - }) - .catch((err) => { - throw err; - }) - } else { - return recentContribsUtil.fetchContribsLastWeek(org, repo) - .then((weekly_contribs) => { - // Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter - model_utils.deleteItem('recent-contribs-data').then((res)=> { - model_utils.setItem('recent-contribs-data', weekly_contribs); - }) - // Push data to UI - recentContributorsUI.insertRecentContributors(weekly_contribs); - return; - }) - .catch((err) => { - throw err; - }) - } - }) - .catch((err) => { - Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); - }) - } - - - function filter(org, type) { - model_utils.getItem('recent-contribs-data') - .then(function gotData(response) { - if(response!=null && response!=undefined) { - newResponse = filterUtil.showFilteredData(org, type, response); - recentContributorsUI.insertRecentContributors(newResponse); - }else { - console.log("recent-contribs-data not present in DB! Nothing is filtered!!!"); - } - }) - } - - - function displayIssuesForRepo(org, repo, label, selector) { - toolbox.api.Issues - .getIssuesForRepo(org, repo, { qs: { labels: label } }) - .then(function onGotIssues(issues) { - issues.forEach(function(issue) { - toolbox.issuesUI.insertIssue(issue, selector); - }); - }) - } - - - function showStaleIssues(org, repo) { - return issuesUtil.getStaleIssues(org, repo) - .then((data) => { - if(data!=null && data!=undefined) { - issuesUI.insertStale(data, '.stale'); - } - }) - .catch((err) => { - Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); - }) - } - - - - - // externally available API - return { - api: api, - issuesUI: issuesUI, - contributorsUI: contributorsUI, - recentContributorsUI: recentContributorsUI, - parse: parse, - chart: chart, - options: options, - getIssuesForRepo: getIssuesForRepo, - getIssuesForOrg: getIssuesForOrg, - showRecentContributors: showRecentContributors, - getCommitsForRepo: getCommitsForRepo, - showAllContributors: showAllContributors, - showRepoContributors: showRepoContributors, - displayIssuesForRepo: displayIssuesForRepo, - initialize: initialize, - dropdownInit: dropdownInit, - ftoAuthorsUI: ftoAuthorsUI, - showStaleIssues: showStaleIssues, - filter: filter - } - -} - -module.exports = CommunityToolbox; + +CommunityToolbox = function CommunityToolbox(org, repo) { + + + var SimpleApi = require('github-api-simple') + var api = new SimpleApi(); + + var crud = require('../models/crud') + var issuesUI = require('../UI/issuesUI') + var model_utils = require('../models/utils') + var fetchReposUtil = require('../utils/repoUtil/fetchRepoUtil') + var contributorsUI = require('../UI/contributorsUI') + var contributorsUtil = require('../utils/contribsUtil/main') + var recentContributorsUI = require('../UI/recentContributorsUI') + var navDropdownUtil = require('../utils/navDropdown.js') + var ftoAuthorsUI = require('../UI/ftoAuthorsUI') + var issuesUtil = require('../utils/staleIssuesUtil') + var recentContribsUtil = require('../utils/recentContribsUtil/main') + var filterUtil = require('../utils/filterUtil') + + + const requestP = require('request-promise') + var parse = require('parse-link-header') + var chart = require('./chart'); + + var options = { + 'qs': { + 'sort': 'pushed', + 'direction': 'desc', // optional, GitHub API uses 'desc' by default for 'pushed' + 'per_page': 100 + } + } + + // these are essentially examples for now; we could wrap them + // in externally available methods for convenience but at the + // moment they're not quite complex enough to merit it. + + function getIssuesForRepo(callback, _options) { + _options = _options || options; + api.Issues + .getIssuesForRepo(org, repo, _options) + .then(callback); + } + + function getIssuesForOrg(_org, _options) { + _options = _options || options; + var _url = "https://api.github.com/search/issues?q=is%3Aopen+org%3A" + _org + "+label%3A" + _options.qs.labels; + return requestP({ uri: _url }); + } + + function getCommitsForRepo(callback, _options) { + _options = _options || options; + api.Repositories + .getRepoCommits(org, repo, _options) + .then(callback); + } + + + function initialize(org, repo) { + return new Promise((resolve, reject) => { + return crud.populateDb() + .then((res) => { + return true; + }) + .then((dummy) => { + return model_utils.getItem('repos').then((response) => { + if(response==null || response==undefined) { + // Fetches and stores the list of repositories when the page loads + return fetchReposUtil.getAllRepos(org) + .then((resp) => { + resolve(true); + }) + .catch((err) => { + Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); + }) + } + resolve(true); + }); + }) + }); + } + + + function dropdownInit() { + return model_utils.getItem('repos') + .then((res) => { + if(res!=null && res!=undefined) { + navDropdownUtil.populateNavDropdown(res); + }else { + console.log("not working"); + } + }) + } + + + // This function is responsible for showing contributors + // on a multi-repository view + function showAllContributors(org) { + return contributorsUtil.fetchAllContribsInDb(org) + .then((allContributors) => { + // If the stored data is not undefined or null, execution goes here + if(allContributors!=null && allContributors!=undefined && allContributors.length>0) { + // Flushes contributors list from the database after every single day + let timeNow = (new Date).getTime(); + model_utils.getItem('allContributorsExpiry') + .then((allContributorsExpiry) => { + if (allContributorsExpiry!=null && ((timeNow-allContributorsExpiry)/1000) >= 86400) { + return Promise.all([model_utils.deleteItem('allContributors'), model_utils.deleteItem('allContributorsExpiry')]) + .then(()=> { + return true; + }) + } + }) + .then(()=> { + // Looking for contributors list in the database + model_utils.getItem('allContributors').then((AllContributors) => { + // If the data is not in the database, it gets fetched from storeAllContributorsInDatabase function + if(AllContributors == null || AllContributors == undefined || AllContributors.length==0) { + + contributorsUtil.fetchAllContribsInDb(org) + .then(function gotAllContributors(AllContributors) { + // Provides fetched contributors list to UI function for rendering it + // to the user + contributorsUI.insertContributors(AllContributors); + }) + .catch((err) => { + throw err; + }) + } + // If stored data is not null and undefined, process it + else { + contributorsUI.insertContributors(AllContributors); + } + }) + }) + } + // If execution goes here, it means that there's probably something wrong + // in the storeAllContributorsInDatabase function + else { + console.log("Something went wrong while fetching all contributors :("); + } + }) + .catch((err) => { + Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); + }) + } + + + // This function is responsible for showing all the contributors for a particular repository + function showRepoContributors(org, repo) { + return contributorsUtil.fetchAllContribsInDb(org) + .then((allContributors) => { + // If the stored data is not undefined or null, execution goes here + if(allContributors != null && allContributors!=undefined && allContributors.length>0) { + // Flushes repoContributors from the database after every single day + let timeNow = (new Date).getTime(); + model_utils.getItem(`${repo}Expiry`) + .then((lifespan) => { + if (lifespan!=null && ((timeNow-lifespan)/1000) >= 86400) { + return Promise.all([model_utils.deleteItem(`${repo}`), model_utils.deleteItem(`${repo}Expiry`)]) + .then(()=>{ + return true; + }) + } + }) + .then(()=>{ + // Looking for repo Contributors list in the database + model_utils.getItem(repo).then((repoContributors) => { + // If we don't have repoContributors in the database, we fetch them from Github + if (repoContributors == null || repoContributors == undefined) { + contributorsUtil.repoContribsUtil(org, repo) + .then(function gotRepoContributorsInStorage (contributors) { + contributorsUI.insertContributors(contributors); + return; + }) + .catch((err) => { + throw err; + }) + } + // If we have repoContributors in the database, we save a network call :) + else { + contributorsUI.insertContributors(repoContributors); + return; + } + }) + }) + } else { + // Execution goes here, it means that data for this repo is not available + // in the database + console.log(`Something went wrong while getting ${repo} contributors :(`); + } + }) + .catch((err) => { + Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); + }) + } + + + // Function for fetching and showing recent contributors + function showRecentContributors(org, repo, recencyLabel, forMonths=6) { + return recentContribsUtil.fetchAllRecentContribsInDb(org, repo).then((result)=>{ + if(recencyLabel==="month") { + return recentContribsUtil.fetchContribsLastMonth(org, repo, forMonths) + .then(function gotMonthlyContribs(monthContribs) { + // Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter + model_utils.deleteItem('recent-contribs-data').then((res)=> { + model_utils.setItem('recent-contribs-data', monthContribs); + }) + // Push data to UI + recentContributorsUI.insertRecentContributors(monthContribs); + return; + }) + .catch((err) => { + throw err; + }) + } else { + return recentContribsUtil.fetchContribsLastWeek(org, repo) + .then((weekly_contribs) => { + // Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter + model_utils.deleteItem('recent-contribs-data').then((res)=> { + model_utils.setItem('recent-contribs-data', weekly_contribs); + }) + // Push data to UI + recentContributorsUI.insertRecentContributors(weekly_contribs); + return; + }) + .catch((err) => { + throw err; + }) + } + }) + .catch((err) => { + Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); + }) + } + + + function filter(org, type) { + model_utils.getItem('recent-contribs-data') + .then(function gotData(response) { + if(response!=null && response!=undefined) { + newResponse = filterUtil.showFilteredData(org, type, response); + recentContributorsUI.insertRecentContributors(newResponse); + }else { + console.log("recent-contribs-data not present in DB! Nothing is filtered!!!"); + } + }) + } + + + function showStaleIssues(org, repo) { + return issuesUtil.getStaleIssues(org, repo) + .then((data) => { + if(data!=null && data!=undefined) { + issuesUI.insertStale(data, '.stale'); + } + }) + .catch((err) => { + Snackbar.show({pos: 'top-right', text: err, textColor: "red" , showAction: false}); + }) + } + + + + + // externally available API + return { + api: api, + issuesUI: issuesUI, + contributorsUI: contributorsUI, + recentContributorsUI: recentContributorsUI, + parse: parse, + chart: chart, + options: options, + getIssuesForRepo: getIssuesForRepo, + getIssuesForOrg: getIssuesForOrg, + showRecentContributors: showRecentContributors, + getCommitsForRepo: getCommitsForRepo, + showAllContributors: showAllContributors, + showRepoContributors: showRepoContributors, + displayIssuesForRepo: displayIssuesForRepo, + initialize: initialize, + dropdownInit: dropdownInit, + ftoAuthorsUI: ftoAuthorsUI, + showStaleIssues: showStaleIssues, + filter: filter + } + +} + +module.exports = CommunityToolbox; },{"../UI/contributorsUI":399,"../UI/ftoAuthorsUI":400,"../UI/issuesUI":401,"../UI/recentContributorsUI":402,"../models/crud":403,"../models/utils":405,"../utils/contribsUtil/main":411,"../utils/filterUtil":414,"../utils/navDropdown.js":415,"../utils/recentContribsUtil/main":421,"../utils/repoUtil/fetchRepoUtil":426,"../utils/staleIssuesUtil":427,"./chart":406,"github-api-simple":151,"parse-link-header":278,"request-promise":323}],408:[function(require,module,exports){ -let SimpleApi = require("github-api-simple") -let api = new SimpleApi() -let model_utils = require('../../models/utils') -let parse = require('parse-link-header') - -// This utility helps us in getting all the contributors for a particular repository -function fetchAllRepoContribs(org, repo) { - // This array is used to store the contributors from all of the repositories - let contributorsArray = []; - - return api.Repositories - .getRepoContributors(org, repo, {method: "HEAD", qs: { sort: 'pushed', direction: 'desc', per_page: 100 } }) - .then(function gotContribData(contribData) { - var headers = contribData; - if (headers.hasOwnProperty("link")) { - var parsed = parse(headers['link']); - if(parsed.last.page!=undefined) { - totalPages = parseInt(parsed.last.page); - } - } else { - totalPages = 1; - } - return totalPages; - }) - .then(function gotTotalPages(totalPages) { - // This array is used to store all of the promises - let promises = []; - - for(let i = 1; i <= totalPages; i++) { - var currentPromise = api.Repositories - .getRepoContributors(org, repo, { method:"GET", qs: { sort: 'pushed', direction: 'desc', per_page: 100, page:i } }) - .then(function gotRepoContributors(contributors) { - if (contributors!=undefined && (contributors != null || contributors.length > 0)) { - contributors.map((contributor, i) => contributorsArray.push(contributor)); - } - }) - .catch((err) => { - throw err; - }); - // Push currentPromise to promises array - promises.push(currentPromise); - } - - // Waits for all of the promises to resolve first, sets localStorage after that... - return Promise.all(promises) - .then(()=> { - let now = (new Date).getTime(); - model_utils.setItem(repo, contributorsArray); - model_utils.setItem(`${repo}Expiry`, now); - return contributorsArray; - }); - }) - .catch((err) => { - throw err; - }) -} - - - - -// EXPORTS -module.exports = { - fetchAllRepoContribs: fetchAllRepoContribs +let SimpleApi = require("github-api-simple") +let api = new SimpleApi() +let model_utils = require('../../models/utils') +let parse = require('parse-link-header') + +// This utility helps us in getting all the contributors for a particular repository +function fetchAllRepoContribs(org, repo) { + // This array is used to store the contributors from all of the repositories + let contributorsArray = []; + + return api.Repositories + .getRepoContributors(org, repo, {method: "HEAD", qs: { sort: 'pushed', direction: 'desc', per_page: 100 } }) + .then(function gotContribData(contribData) { + var headers = contribData; + if (headers.hasOwnProperty("link")) { + var parsed = parse(headers['link']); + if(parsed.last.page!=undefined) { + totalPages = parseInt(parsed.last.page); + } + } else { + totalPages = 1; + } + return totalPages; + }) + .then(function gotTotalPages(totalPages) { + // This array is used to store all of the promises + let promises = []; + + for(let i = 1; i <= totalPages; i++) { + var currentPromise = api.Repositories + .getRepoContributors(org, repo, { method:"GET", qs: { sort: 'pushed', direction: 'desc', per_page: 100, page:i } }) + .then(function gotRepoContributors(contributors) { + if (contributors!=undefined && (contributors != null || contributors.length > 0)) { + contributors.map((contributor, i) => contributorsArray.push(contributor)); + } + }) + .catch((err) => { + throw err; + }); + // Push currentPromise to promises array + promises.push(currentPromise); + } + + // Waits for all of the promises to resolve first, sets localStorage after that... + return Promise.all(promises) + .then(()=> { + let now = (new Date).getTime(); + model_utils.setItem(repo, contributorsArray); + model_utils.setItem(`${repo}Expiry`, now); + return contributorsArray; + }); + }) + .catch((err) => { + throw err; + }) +} + + + + +// EXPORTS +module.exports = { + fetchAllRepoContribs: fetchAllRepoContribs } },{"../../models/utils":405,"github-api-simple":151,"parse-link-header":278}],409:[function(require,module,exports){ -let SimpleApi = require("github-api-simple") -let api = new SimpleApi() -let model_utils = require('../../models/utils') - - -// This utility helps us in getting CONTRIBUTORS for a particular repository -function fetchRepoContribs(org, repo) { - // This array is used to store the contributors from all of the repositories - let contributorsArray = []; - - return api.Repositories - .getRepoContributors(org, repo, { method:"GET", qs: { sort: 'pushed', direction: 'desc', per_page: 100 }}) - .then(function gotRepoContributors(contributors) { - if (contributors!=undefined && (contributors != null || contributors.length > 0)) { - contributors.map((contributor, i) => contributorsArray.push(contributor)); - } - }) - .then(() => { - let now = (new Date).getTime(); - model_utils.setItem(repo, contributorsArray); - model_utils.setItem(`${repo}Expiry`, now); - return contributorsArray; - }) - .catch((err) => { - throw err; - }) - } - - - - -// EXPORTS -module.exports = { - fetchRepoContribs: fetchRepoContribs +let SimpleApi = require("github-api-simple") +let api = new SimpleApi() +let model_utils = require('../../models/utils') + + +// This utility helps us in getting CONTRIBUTORS for a particular repository +function fetchRepoContribs(org, repo) { + // This array is used to store the contributors from all of the repositories + let contributorsArray = []; + + return api.Repositories + .getRepoContributors(org, repo, { method:"GET", qs: { sort: 'pushed', direction: 'desc', per_page: 100 }}) + .then(function gotRepoContributors(contributors) { + if (contributors!=undefined && (contributors != null || contributors.length > 0)) { + contributors.map((contributor, i) => contributorsArray.push(contributor)); + } + }) + .then(() => { + let now = (new Date).getTime(); + model_utils.setItem(repo, contributorsArray); + model_utils.setItem(`${repo}Expiry`, now); + return contributorsArray; + }) + .catch((err) => { + throw err; + }) + } + + + + +// EXPORTS +module.exports = { + fetchRepoContribs: fetchRepoContribs } },{"../../models/utils":405,"github-api-simple":151}],410:[function(require,module,exports){ -let fetchAllRepoContribs = require('./fetchAllRepoContribs') -let fetchRepoContribs = require('./fetchRepoContribs') - -// This is a utility function which decides whether to make a single request for fetching -// each repository's contributors or multiple ones. -function fetchRepoContributorsUtil(org, repo) { - return new Promise((resolve, reject) => { - if(repo === 'plots2') { - resolve(fetchAllRepoContribs.fetchAllRepoContribs(org, repo)); - }else { - resolve(fetchRepoContribs.fetchRepoContribs(org, repo)); - } - }) -} - - -// EXPORTS -module.exports = { - fetchRepoContributorsUtil: fetchRepoContributorsUtil +let fetchAllRepoContribs = require('./fetchAllRepoContribs') +let fetchRepoContribs = require('./fetchRepoContribs') + +// This is a utility function which decides whether to make a single request for fetching +// each repository's contributors or multiple ones. +function fetchRepoContributorsUtil(org, repo) { + return new Promise((resolve, reject) => { + if(repo === 'plots2') { + resolve(fetchAllRepoContribs.fetchAllRepoContribs(org, repo)); + }else { + resolve(fetchRepoContribs.fetchRepoContribs(org, repo)); + } + }) +} + + +// EXPORTS +module.exports = { + fetchRepoContributorsUtil: fetchRepoContributorsUtil } },{"./fetchAllRepoContribs":408,"./fetchRepoContribs":409}],411:[function(require,module,exports){ -let fetchRepoContribsUtil = require('./fetchRepoContribsUtil') -let storeAllContribsInDb = require('./storeAllContribsInDb') - - -function fetchAllContribsInDb(org) { - return storeAllContribsInDb.storeAllContribsInDb(org) - .then((response) => { - return response; - }) - .catch((err) => { - console.log("err travelling through fetchAllContribsInDb"); - throw err; - }) -} - - -function repoContribsUtil(org, repo) { - return fetchRepoContribsUtil.fetchRepoContributorsUtil(org, repo) - .then((response) => { - return response; - }) - .catch((err) => { - console.log("err travelling through repoContribsUtil"); - throw err; - }) -} - - - - -// EXPORTS -module.exports = { - repoContribsUtil: repoContribsUtil, - fetchAllContribsInDb: fetchAllContribsInDb -} - +let fetchRepoContribsUtil = require('./fetchRepoContribsUtil') +let storeAllContribsInDb = require('./storeAllContribsInDb') + + +function fetchAllContribsInDb(org) { + return storeAllContribsInDb.storeAllContribsInDb(org) + .then((response) => { + return response; + }) + .catch((err) => { + console.log("err travelling through fetchAllContribsInDb"); + throw err; + }) +} + + +function repoContribsUtil(org, repo) { + return fetchRepoContribsUtil.fetchRepoContributorsUtil(org, repo) + .then((response) => { + return response; + }) + .catch((err) => { + console.log("err travelling through repoContribsUtil"); + throw err; + }) +} + + + + +// EXPORTS +module.exports = { + repoContribsUtil: repoContribsUtil, + fetchAllContribsInDb: fetchAllContribsInDb +} + },{"./fetchRepoContribsUtil":410,"./storeAllContribsInDb":412}],412:[function(require,module,exports){ -let fetchRepoContributorsUtil = require('./fetchRepoContribsUtil') -let model_utils = require('../../models/utils') - -// This runs at the very start of page load and stores all the repositories and all the -// contributors in the database on initial page load -function storeAllContribsInDb(org) { - let AllContributors = []; - let promises = []; - var contributorSet = new Set([]); - return new Promise((resolve, reject) => { - model_utils.getItem('allContributors').then((allContributors) => { - // If all contributors list is not in the database, it makes a fresh call to Github API - if(allContributors == null || allContributors == undefined || allContributors.length == 0) { - return model_utils.getItem('repos').then((res) => { - let splicedRepos = res.splice(0, 20); - splicedRepos.map(function mappingToEachRepo(Repo, i) { - let promise = fetchRepoContributorsUtil.fetchRepoContributorsUtil(org, Repo) - .then(function gotRepoContributorsInStorage(contributors) { - if(contributors!=undefined && contributors.length>0) { - contributors.map((contributor, i)=> { - if(!contributorSet.has(contributor.login)) { - contributorSet.add(contributor.login); - AllContributors.push(contributor); - } - }) - } - }) - .catch((err) => { - throw err; - }) - promises.push(promise); - }); - return Promise.all(promises) - .then(()=> { - // Storing array containing all the contributors' list across 20 most active - // repos to database - model_utils.setItem('allContributors', AllContributors); - // Saves current time in epoch, used for flushing out the stored data - // after 24 hours - let currentTime = (new Date).getTime(); - model_utils.setItem('allContributorsExpiry', currentTime); - resolve(AllContributors); - }) - }) - } - // If all contributors list is in the database, it simply returns that as a resolved promise - else { - resolve(allContributors); - } - }) - .catch((err) => { - reject(err); - }) - }); -} - - - - -// EXPORTS -module.exports = { - storeAllContribsInDb: storeAllContribsInDb +let fetchRepoContributorsUtil = require('./fetchRepoContribsUtil') +let model_utils = require('../../models/utils') + +// This runs at the very start of page load and stores all the repositories and all the +// contributors in the database on initial page load +function storeAllContribsInDb(org) { + let AllContributors = []; + let promises = []; + var contributorSet = new Set([]); + return new Promise((resolve, reject) => { + model_utils.getItem('allContributors').then((allContributors) => { + // If all contributors list is not in the database, it makes a fresh call to Github API + if(allContributors == null || allContributors == undefined || allContributors.length == 0) { + return model_utils.getItem('repos').then((res) => { + let splicedRepos = res.splice(0, 20); + splicedRepos.map(function mappingToEachRepo(Repo, i) { + let promise = fetchRepoContributorsUtil.fetchRepoContributorsUtil(org, Repo) + .then(function gotRepoContributorsInStorage(contributors) { + if(contributors!=undefined && contributors.length>0) { + contributors.map((contributor, i)=> { + if(!contributorSet.has(contributor.login)) { + contributorSet.add(contributor.login); + AllContributors.push(contributor); + } + }) + } + }) + .catch((err) => { + throw err; + }) + promises.push(promise); + }); + return Promise.all(promises) + .then(()=> { + // Storing array containing all the contributors' list across 20 most active + // repos to database + model_utils.setItem('allContributors', AllContributors); + // Saves current time in epoch, used for flushing out the stored data + // after 24 hours + let currentTime = (new Date).getTime(); + model_utils.setItem('allContributorsExpiry', currentTime); + resolve(AllContributors); + }) + }) + } + // If all contributors list is in the database, it simply returns that as a resolved promise + else { + resolve(allContributors); + } + }) + .catch((err) => { + reject(err); + }) + }); +} + + + + +// EXPORTS +module.exports = { + storeAllContribsInDb: storeAllContribsInDb } },{"../../models/utils":405,"./fetchRepoContribsUtil":410}],413:[function(require,module,exports){ -// Given a list of commits which contains repeated commiters, this function extracts -// a list of unique commiters and returns that -function filterUniqueContribs(data) { - let commitersSet = new Set([]); - let result = []; - - data.map(function mappingToCommits(commit, i) { - if(commit.author!=null) { - if(!commitersSet.has(commit.author.login)) { - commitersSet.add(commit.author.login); - result.push(commit); - } - } - }); - - return result; -} - - -module.exports = { - filterUniqueContribs: filterUniqueContribs, +// Given a list of commits which contains repeated commiters, this function extracts +// a list of unique commiters and returns that +function filterUniqueContribs(data) { + let commitersSet = new Set([]); + let result = []; + + data.map(function mappingToCommits(commit, i) { + if(commit.author!=null) { + if(!commitersSet.has(commit.author.login)) { + commitersSet.add(commit.author.login); + result.push(commit); + } + } + }); + + return result; +} + + +module.exports = { + filterUniqueContribs: filterUniqueContribs, } },{}],414:[function(require,module,exports){ -function showFilteredData(org, type, response) { - if (type==="alphabetic") { - response.sort(function(x, y) { - if ((x.author.login).toLowerCase() > (y.author.login).toLowerCase()) { - return 1; - }else { - return -1; - } - }); - return response; - } - else if(type==="mostrecentfirst") { - response.sort(function (x,y) { - let a = new Date(x.commit.author.date); - let b = new Date(y.commit.author.date); - if(b>a) { - return 1; - }else { - return -1; - } - }) - return response; - } - else if(type === "leaderboard") { - let leaderMap = new Map([]); - - response.map(function mappingToCommiters(dataItem, i) { - let temp = leaderMap.get(dataItem.author.login); - if (temp < 0 || temp == undefined || temp == null) { - temp = 0; - } - temp += 1; - leaderMap.set(dataItem.author.login, temp); - }) - - let sortedMap = new Map([...leaderMap.entries()].sort((a, b) => b[1] - a[1])); - return sortedMap; - } -} - - - -module.exports = { - showFilteredData: showFilteredData +function showFilteredData(org, type, response) { + if (type==="alphabetic") { + response.sort(function(x, y) { + if ((x.author.login).toLowerCase() > (y.author.login).toLowerCase()) { + return 1; + }else { + return -1; + } + }); + return response; + } + else if(type==="mostrecentfirst") { + response.sort(function (x,y) { + let a = new Date(x.commit.author.date); + let b = new Date(y.commit.author.date); + if(b>a) { + return 1; + }else { + return -1; + } + }) + return response; + } + else if(type === "leaderboard") { + let leaderMap = new Map([]); + + response.map(function mappingToCommiters(dataItem, i) { + let temp = leaderMap.get(dataItem.author.login); + if (temp < 0 || temp == undefined || temp == null) { + temp = 0; + } + temp += 1; + leaderMap.set(dataItem.author.login, temp); + }) + + let sortedMap = new Map([...leaderMap.entries()].sort((a, b) => b[1] - a[1])); + return sortedMap; + } +} + + + +module.exports = { + showFilteredData: showFilteredData } },{}],415:[function(require,module,exports){ -function populateNavDropdown(repos) { - let repoAlreadySelected = urlHash().getUrlHashParameter('r'); - - // populates the current dropdown selected html - if(jQuery.isEmptyObject(repoAlreadySelected)) { - repoAlreadySelected = "plots2"; - }else { - repoAlreadySelected = (repoAlreadySelected.r == undefined) ? repoAlreadySelected : repoAlreadySelected.r; - } - $('#dropdownMenuButton').html(repoAlreadySelected); - - - // populates the dropdown list - repos.map((repo,i) => { - $('

', { - class: 'dropdown-items', - text: repo - }).appendTo('#dropdown-container'); - }); - - - // click handler for dropdown items - $('.dropdown-items').click((e) => { - let repo = e.target.textContent; - urlHash().setUrlHashParameter("r", repo); - $('#dropdownMenuButton').html(repo); - location.reload(); - }) -} - - - -module.exports.populateNavDropdown = populateNavDropdown; +function populateNavDropdown(repos) { + let repoAlreadySelected = urlHash().getUrlHashParameter('r'); + + // populates the current dropdown selected html + if(jQuery.isEmptyObject(repoAlreadySelected)) { + repoAlreadySelected = "plots2"; + }else { + repoAlreadySelected = (repoAlreadySelected.r == undefined) ? repoAlreadySelected : repoAlreadySelected.r; + } + $('#dropdownMenuButton').html(repoAlreadySelected); + + + // populates the dropdown list + repos.map((repo,i) => { + $('

', { + class: 'dropdown-items', + text: repo + }).appendTo('#dropdown-container'); + }); + + + // click handler for dropdown items + $('.dropdown-items').click((e) => { + let repo = e.target.textContent; + urlHash().setUrlHashParameter("r", repo); + $('#dropdownMenuButton').html(repo); + location.reload(); + }) +} + + + +module.exports.populateNavDropdown = populateNavDropdown; },{}],416:[function(require,module,exports){ -let model_utils = require('../../models/utils'); -let monthsQuery = require('./queryTime') -let fetchRecentMonthContribs = require('./fetchRecentMonthContribs') - - -// Fetches recent month commits for top 10 repositories -function fetchAllRecentMonthContribs(org, repos, queryTime) { - let results = []; - let commitersSet = new Set([]); - let timeToday = (new Date).getTime(); - let monthInd = monthsQuery.findMonthInd(queryTime); - - // We take only 10 repos just for API quota reasons - let splicedRepos = repos.splice(0,10); - - let promises = splicedRepos.map(function mapToEachRepo(repo, i) { - return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime) - .then((response) => { - if(response!=null) { - let partialResult = []; - response.map(function mappingToCommits(commit, i) { - if(commit.author!=null) { - if(!commitersSet.has(commit.author.login)) { - commitersSet.add(commit.author.login); - partialResult.push(commit); - results.push(commit); - } - } - return true; - }); - - // Save each repo's commits data to the database - let currTime = (new Date).getTime(); - model_utils.setItem(`recent-${repo}-${monthInd}-month-commits`, partialResult); - model_utils.setItem(`recent-${repo}-${monthInd}-month-expiry`, currTime); - } - }) - .catch((err) => { - throw err; - }) - }) - - return Promise.all(promises) - .then(function promisesResolved() { - // Store recentMonthCommits and recentMonthCommitsExpiry in the database - model_utils.setItem(`recent-all-${monthInd}-month-commits`, results); - model_utils.setItem(`recent-all-${monthInd}-month-expiry`, timeToday); - return results; - }); -} - - - -// EXPORTS -module.exports = { - fetchAllRecentMonthContribs: fetchAllRecentMonthContribs +let model_utils = require('../../models/utils'); +let monthsQuery = require('./queryTime') +let fetchRecentMonthContribs = require('./fetchRecentMonthContribs') + + +// Fetches recent month commits for top 10 repositories +function fetchAllRecentMonthContribs(org, repos, queryTime) { + let results = []; + let commitersSet = new Set([]); + let timeToday = (new Date).getTime(); + let monthInd = monthsQuery.findMonthInd(queryTime); + + // We take only 10 repos just for API quota reasons + let splicedRepos = repos.splice(0,10); + + let promises = splicedRepos.map(function mapToEachRepo(repo, i) { + return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime) + .then((response) => { + if(response!=null) { + let partialResult = []; + response.map(function mappingToCommits(commit, i) { + if(commit.author!=null) { + if(!commitersSet.has(commit.author.login)) { + commitersSet.add(commit.author.login); + partialResult.push(commit); + results.push(commit); + } + } + return true; + }); + + // Save each repo's commits data to the database + let currTime = (new Date).getTime(); + model_utils.setItem(`recent-${repo}-${monthInd}-month-commits`, partialResult); + model_utils.setItem(`recent-${repo}-${monthInd}-month-expiry`, currTime); + } + }) + .catch((err) => { + throw err; + }) + }) + + return Promise.all(promises) + .then(function promisesResolved() { + // Store recentMonthCommits and recentMonthCommitsExpiry in the database + model_utils.setItem(`recent-all-${monthInd}-month-commits`, results); + model_utils.setItem(`recent-all-${monthInd}-month-expiry`, timeToday); + return results; + }); +} + + + +// EXPORTS +module.exports = { + fetchAllRecentMonthContribs: fetchAllRecentMonthContribs } },{"../../models/utils":405,"./fetchRecentMonthContribs":417,"./queryTime":422}],417:[function(require,module,exports){ -let model_utils = require('../../models/utils') -let monthsQuery = require('./queryTime') -let withinMonthsOrNot = require('./withinMonthsOrNot') -let freshFetch = require('./freshFetch') - -// Fetches recent month commits for a particular repository -function fetchRecentMonthContribs(org, repo, queryTime) { - let contribs = []; - let monthsInd = monthsQuery.findMonthInd(queryTime); - - return model_utils.getItem(`recent-${repo}-${monthsInd}-month-commits`) - .then((stored) => { - if(stored!=null && stored!=undefined) { - return stored; - } - else { - return model_utils.getItem(`recent-${repo}-6-month-commits`) - .then((wholeContribsList) => { - if(wholeContribsList!=undefined && wholeContribsList!=null) { - wholeContribsList.map((contributor, index) => { - let commit_date = contributor['commit']['committer']['date']; - let check = withinMonthsOrNot.within_months(commit_date, monthsInd); - if(check) { - contribs.push(contributor); - } - }); - // Store recentWeekCommits and recentWeekCommitsExpiry in the database - let currTime = (new Date).getTime(); - model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, contribs); - model_utils.setItem(`recent-${repo}-${monthsInd}-month-expiry`, currTime); - return contribs; - } - else { - // We don't have any recent month contributors' data for desired repository - // so we need to do all the work now - return freshFetch.freshFetch(org, repo, queryTime) - .then((response) => { - return response; - }) - .catch((err) => { - throw err; - }) - } - }) - .catch((err) => { - throw err; - }) - - } - }) - .catch((err) => { - throw err; - }) - - -} - - - - - -// EXPORTS -module.exports = { - fetchRecentMonthContribs: fetchRecentMonthContribs +let model_utils = require('../../models/utils') +let monthsQuery = require('./queryTime') +let withinMonthsOrNot = require('./withinMonthsOrNot') +let freshFetch = require('./freshFetch') + +// Fetches recent month commits for a particular repository +function fetchRecentMonthContribs(org, repo, queryTime) { + let contribs = []; + let monthsInd = monthsQuery.findMonthInd(queryTime); + + return model_utils.getItem(`recent-${repo}-${monthsInd}-month-commits`) + .then((stored) => { + if(stored!=null && stored!=undefined) { + return stored; + } + else { + return model_utils.getItem(`recent-${repo}-6-month-commits`) + .then((wholeContribsList) => { + if(wholeContribsList!=undefined && wholeContribsList!=null) { + wholeContribsList.map((contributor, index) => { + let commit_date = contributor['commit']['committer']['date']; + let check = withinMonthsOrNot.within_months(commit_date, monthsInd); + if(check) { + contribs.push(contributor); + } + }); + // Store recentWeekCommits and recentWeekCommitsExpiry in the database + let currTime = (new Date).getTime(); + model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, contribs); + model_utils.setItem(`recent-${repo}-${monthsInd}-month-expiry`, currTime); + return contribs; + } + else { + // We don't have any recent month contributors' data for desired repository + // so we need to do all the work now + return freshFetch.freshFetch(org, repo, queryTime) + .then((response) => { + return response; + }) + .catch((err) => { + throw err; + }) + } + }) + .catch((err) => { + throw err; + }) + + } + }) + .catch((err) => { + throw err; + }) + + +} + + + + + +// EXPORTS +module.exports = { + fetchRecentMonthContribs: fetchRecentMonthContribs } },{"../../models/utils":405,"./freshFetch":418,"./queryTime":422,"./withinMonthsOrNot":424}],418:[function(require,module,exports){ -let model_utils = require('../../models/utils') -let monthsQuery = require('./queryTime') - -function freshFetch(org, repo, queryTime) { - let result=[]; - let proms = []; - let monthsInd = monthsQuery.findMonthInd(queryTime); - - for(let i=0;i<2;i++) { - proms.push( - fetch(`https://api.github.com/repos/${org}/${repo}/commits?since=${queryTime}&per_page=100&page=${i}`) - .then(function gotResponse(response) { - if(response.status=="200") { - return response.json(); - }else { - throw `Couldn't fetch commits for ${repo}`; - } - }) - .then(function gotResponseJson(response) { - if(response!=null) { - response.map(function mappingToCommits(commit, i) { - result.push(commit); - }); - } - return result; - }) - ) - } - - return Promise.all(proms) - .then(() => { - // Save each repo's commits data to the database - let currTime = (new Date).getTime(); - model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, result); - model_utils.setItem(`recent-${repo}-${monthsInd}-month-expiry`, currTime); - return result; - }) -} - - - -module.exports = { - freshFetch: freshFetch -} - +let model_utils = require('../../models/utils') +let monthsQuery = require('./queryTime') + +function freshFetch(org, repo, queryTime) { + let result=[]; + let proms = []; + let monthsInd = monthsQuery.findMonthInd(queryTime); + + for(let i=0;i<2;i++) { + proms.push( + fetch(`https://api.github.com/repos/${org}/${repo}/commits?since=${queryTime}&per_page=100&page=${i}`) + .then(function gotResponse(response) { + if(response.status=="200") { + return response.json(); + }else { + throw `Couldn't fetch commits for ${repo}`; + } + }) + .then(function gotResponseJson(response) { + if(response!=null) { + response.map(function mappingToCommits(commit, i) { + result.push(commit); + }); + } + return result; + }) + ) + } + + return Promise.all(proms) + .then(() => { + // Save each repo's commits data to the database + let currTime = (new Date).getTime(); + model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, result); + model_utils.setItem(`recent-${repo}-${monthsInd}-month-expiry`, currTime); + return result; + }) +} + + + +module.exports = { + freshFetch: freshFetch +} + },{"../../models/utils":405,"./queryTime":422}],419:[function(require,module,exports){ -let model_utils = require('../../models/utils'); -let fetchAllRecentMonthContribs = require('./fetchAllRecentMonthContribs') -let fetchRecentMonthContribs = require('./fetchRecentMonthContribs') - - -// Fetches recent month's commits for a particular repo or all of the repos (10 repos) -function getContribsLastMonth(org, repo, forMonths) { - return model_utils.getItem('repos').then((repos) => { - if(repos!=null && repos!=undefined) { - return model_utils.getItem(`recent-${repo}-${forMonths}-month-expiry`) - .then((recentCommitsMonthExpiry) => { - let timeToday = (new Date).getTime(); - // If recentCommits expiry time is 1 day behind the current time, flush them out. - if(recentCommitsMonthExpiry!=null && recentCommitsMonthExpiry!=undefined && ((timeToday-recentCommitsMonthExpiry)/1000)>=86400) { - return Promise.all([model_utils.deleteItem(`recent-${repo}-${forMonths}-month-commits`), model_utils.deleteItem(`recent-${repo}-${forMonths}-month-expiry`)]) - .then(() => { - return true; - }) - } - return true; - }) - .then((boolean) => { - return model_utils.getItem(`recent-${repo}-${forMonths}-month-commits`).then((result) => { - if(result!=null && result!=undefined) { - return result; - } - else { - // We make queryTime 1 month behind the current time, to pass it as query in the request - let d = (new Date); - let temp = forMonths*30; - d.setDate(d.getDate() - temp); - let queryTime = d.toISOString(); - if(repo==='all') { - return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) - .then(function gotRecentCommitsInStorage(month_commits) { - return month_commits; - }) - .catch((err) => { - throw err; - }) - } - else { - return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime) - .then(function gotRecentCommitsInStorage(month_commits) { - return month_commits; - }) - .catch((err) => { - throw err; - }) - } - } - }) - }) - .catch((err) => { - throw err; - }); - } else { - console.log("repos are not there yet!!!"); - } - }) -} - - - - - -// EXPORTS -module.exports = { - getContribsLastMonth: getContribsLastMonth +let model_utils = require('../../models/utils'); +let fetchAllRecentMonthContribs = require('./fetchAllRecentMonthContribs') +let fetchRecentMonthContribs = require('./fetchRecentMonthContribs') + + +// Fetches recent month's commits for a particular repo or all of the repos (10 repos) +function getContribsLastMonth(org, repo, forMonths) { + return model_utils.getItem('repos').then((repos) => { + if(repos!=null && repos!=undefined) { + return model_utils.getItem(`recent-${repo}-${forMonths}-month-expiry`) + .then((recentCommitsMonthExpiry) => { + let timeToday = (new Date).getTime(); + // If recentCommits expiry time is 1 day behind the current time, flush them out. + if(recentCommitsMonthExpiry!=null && recentCommitsMonthExpiry!=undefined && ((timeToday-recentCommitsMonthExpiry)/1000)>=86400) { + return Promise.all([model_utils.deleteItem(`recent-${repo}-${forMonths}-month-commits`), model_utils.deleteItem(`recent-${repo}-${forMonths}-month-expiry`)]) + .then(() => { + return true; + }) + } + return true; + }) + .then((boolean) => { + return model_utils.getItem(`recent-${repo}-${forMonths}-month-commits`).then((result) => { + if(result!=null && result!=undefined) { + return result; + } + else { + // We make queryTime 1 month behind the current time, to pass it as query in the request + let d = (new Date); + let temp = forMonths*30; + d.setDate(d.getDate() - temp); + let queryTime = d.toISOString(); + if(repo==='all') { + return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) + .then(function gotRecentCommitsInStorage(month_commits) { + return month_commits; + }) + .catch((err) => { + throw err; + }) + } + else { + return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime) + .then(function gotRecentCommitsInStorage(month_commits) { + return month_commits; + }) + .catch((err) => { + throw err; + }) + } + } + }) + }) + .catch((err) => { + throw err; + }); + } else { + console.log("repos are not there yet!!!"); + } + }) +} + + + + + +// EXPORTS +module.exports = { + getContribsLastMonth: getContribsLastMonth } },{"../../models/utils":405,"./fetchAllRecentMonthContribs":416,"./fetchRecentMonthContribs":417}],420:[function(require,module,exports){ -let model_utils = require('../../models/utils'); -let getContribsLastMonth = require('./getContribsLastMonth') -let withinThisWeekOrNot = require('./withinThisWeekOrNot') - -// Fetches recent week's commits for a particular repo -function getContribsLastWeek(org, repo) { - let contribs = []; - - return model_utils.getItem(`recent-${repo}-week-expiry`) - .then((recentCommitsWeekExpiry) => { - let timeToday = (new Date).getTime(); - // If recent month's commits expiry time is 1 day behind the current time, flush them out. - if(recentCommitsWeekExpiry!=null && recentCommitsWeekExpiry!=undefined && ((timeToday-recentCommitsWeekExpiry)/1000)>=86400) { - return Promise.all([model_utils.deleteItem(`recent-${repo}-week-expiry`), model_utils.deleteItem(`recent-${repo}-week-commits`)]) - .then(()=> { - return true; - }) - } - }) - .then(() => { - return model_utils.getItem(`recent-${repo}-week-commits`).then((result) => { - if(result!=null && result!=undefined) { - return result; - } - else { - // We save extra request by filtering commits-made-last-week from commits-made-last month - return getContribsLastMonth.getContribsLastMonth(org, repo, 6) - .then((commits_last_month) => { - commits_last_month.map((commit_last_month, index) => { - let commit_date = commit_last_month['commit']['committer']['date']; - let check = withinThisWeekOrNot.within_this_week(commit_date); - if(check) { - contribs.push(commit_last_month); - } - }); - // Store recentWeekCommits and recentWeekCommitsExpiry in the database - let currTime = (new Date).getTime(); - model_utils.setItem(`recent-${repo}-week-commits`, contribs); - model_utils.setItem(`recent-${repo}-week-expiry`, currTime); - return contribs; - }); - } - }); - }); -} - - - - - -// EXPORTS -module.exports = { - getContribsLastWeek: getContribsLastWeek +let model_utils = require('../../models/utils'); +let getContribsLastMonth = require('./getContribsLastMonth') +let withinThisWeekOrNot = require('./withinThisWeekOrNot') + +// Fetches recent week's commits for a particular repo +function getContribsLastWeek(org, repo) { + let contribs = []; + + return model_utils.getItem(`recent-${repo}-week-expiry`) + .then((recentCommitsWeekExpiry) => { + let timeToday = (new Date).getTime(); + // If recent month's commits expiry time is 1 day behind the current time, flush them out. + if(recentCommitsWeekExpiry!=null && recentCommitsWeekExpiry!=undefined && ((timeToday-recentCommitsWeekExpiry)/1000)>=86400) { + return Promise.all([model_utils.deleteItem(`recent-${repo}-week-expiry`), model_utils.deleteItem(`recent-${repo}-week-commits`)]) + .then(()=> { + return true; + }) + } + }) + .then(() => { + return model_utils.getItem(`recent-${repo}-week-commits`).then((result) => { + if(result!=null && result!=undefined) { + return result; + } + else { + // We save extra request by filtering commits-made-last-week from commits-made-last month + return getContribsLastMonth.getContribsLastMonth(org, repo, 6) + .then((commits_last_month) => { + commits_last_month.map((commit_last_month, index) => { + let commit_date = commit_last_month['commit']['committer']['date']; + let check = withinThisWeekOrNot.within_this_week(commit_date); + if(check) { + contribs.push(commit_last_month); + } + }); + // Store recentWeekCommits and recentWeekCommitsExpiry in the database + let currTime = (new Date).getTime(); + model_utils.setItem(`recent-${repo}-week-commits`, contribs); + model_utils.setItem(`recent-${repo}-week-expiry`, currTime); + return contribs; + }); + } + }); + }); +} + + + + + +// EXPORTS +module.exports = { + getContribsLastWeek: getContribsLastWeek } },{"../../models/utils":405,"./getContribsLastMonth":419,"./withinThisWeekOrNot":425}],421:[function(require,module,exports){ -let getContribsLastMonth = require('./getContribsLastMonth') -let getContribsLastWeek = require('./getContribsLastWeek') -let storeAllRecentContribsInDb = require('./storeAllRecentContribsInDb') - - - -function fetchContribsLastMonth(org, repo, forMonths=6) { - return getContribsLastMonth.getContribsLastMonth(org, repo, forMonths) - .then((contribs) => { - return contribs; - }) - .catch((err) => { - console.log("finally throwing"); - throw err; - }) -} - -function fetchContribsLastWeek(org, repo) { - return getContribsLastWeek.getContribsLastWeek(org, repo) - .then((contribs) => { - return contribs; - }) - .catch((err) => { - console.log("finally throwing"); - throw err; - }) -} - -function fetchAllRecentContribsInDb(org, repo) { - return storeAllRecentContribsInDb.storeAllRecentContribsInDb(org, repo) - .then((response) => { - return response; - }) - .catch((err) => { - console.log("finally throwing"); - throw err; - }) -} - - - -// EXPORTS -module.exports = { - fetchContribsLastMonth: fetchContribsLastMonth, - fetchContribsLastWeek: fetchContribsLastWeek, - fetchAllRecentContribsInDb: fetchAllRecentContribsInDb -} +let getContribsLastMonth = require('./getContribsLastMonth') +let getContribsLastWeek = require('./getContribsLastWeek') +let storeAllRecentContribsInDb = require('./storeAllRecentContribsInDb') + + + +function fetchContribsLastMonth(org, repo, forMonths=6) { + return getContribsLastMonth.getContribsLastMonth(org, repo, forMonths) + .then((contribs) => { + return contribs; + }) + .catch((err) => { + console.log("finally throwing"); + throw err; + }) +} + +function fetchContribsLastWeek(org, repo) { + return getContribsLastWeek.getContribsLastWeek(org, repo) + .then((contribs) => { + return contribs; + }) + .catch((err) => { + console.log("finally throwing"); + throw err; + }) +} + +function fetchAllRecentContribsInDb(org, repo) { + return storeAllRecentContribsInDb.storeAllRecentContribsInDb(org, repo) + .then((response) => { + return response; + }) + .catch((err) => { + console.log("finally throwing"); + throw err; + }) +} + + + +// EXPORTS +module.exports = { + fetchContribsLastMonth: fetchContribsLastMonth, + fetchContribsLastWeek: fetchContribsLastWeek, + fetchAllRecentContribsInDb: fetchAllRecentContribsInDb +} },{"./getContribsLastMonth":419,"./getContribsLastWeek":420,"./storeAllRecentContribsInDb":423}],422:[function(require,module,exports){ -function findMonthInd(queryTime) { - let timeNow = new Date(); - let qTime = new Date(`${queryTime}`); - let diff = timeNow - qTime; - let monthsBack; - if (diff > 60e3) { - monthsBack = Math.floor((Math.floor(diff / 60e3))/(60*24*30)); - } - - return monthsBack; -} - - -module.exports = { - findMonthInd: findMonthInd +function findMonthInd(queryTime) { + let timeNow = new Date(); + let qTime = new Date(`${queryTime}`); + let diff = timeNow - qTime; + let monthsBack; + if (diff > 60e3) { + monthsBack = Math.floor((Math.floor(diff / 60e3))/(60*24*30)); + } + + return monthsBack; +} + + +module.exports = { + findMonthInd: findMonthInd } },{}],423:[function(require,module,exports){ -let fetchAllRecentMonthContribs = require('./fetchAllRecentMonthContribs') -let fetchRepoUtil = require('../repoUtil/fetchRepoUtil') -let model_utils = require('../../models/utils') - - -// Stores all the Recent Contributors in the database -function storeAllRecentContribsInDb(org, repo) { - // We make queryTime 1 month behind the current time, to pass it as query in the request - let d = (new Date); - d.setDate(d.getDate() - 180); - let queryTime = d.toISOString(); - return model_utils.getItem('repos') - .then((repos) => { - return model_utils.getItem('recent-present').then((result)=> { - if(result!=null && result!=undefined) { - return result; - } - else { - if(repos!=null || repos!=undefined) { - return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) - .then((result) => { - model_utils.setItem('recent-present', 'true'); - return result; - }) - .catch((err) => { - throw err; - }) - } else { - fetchRepoUtil.getAllRepos(org) - .then((repos) => { - if(repos!=null || repos!=undefined) { - return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) - .then((result) => { - model_utils.setItem('recent-present', 'true'); - return result; - }) - .catch((err) => { - throw err; - }) - } - }); - } - } - }); - }) - .catch((err) => { - throw err; - }) -} - - - -// EXPORTS -module.exports = { - storeAllRecentContribsInDb: storeAllRecentContribsInDb -} +let fetchAllRecentMonthContribs = require('./fetchAllRecentMonthContribs') +let fetchRepoUtil = require('../repoUtil/fetchRepoUtil') +let model_utils = require('../../models/utils') + + +// Stores all the Recent Contributors in the database +function storeAllRecentContribsInDb(org, repo) { + // We make queryTime 1 month behind the current time, to pass it as query in the request + let d = (new Date); + d.setDate(d.getDate() - 180); + let queryTime = d.toISOString(); + return model_utils.getItem('repos') + .then((repos) => { + return model_utils.getItem('recent-present').then((result)=> { + if(result!=null && result!=undefined) { + return result; + } + else { + if(repos!=null || repos!=undefined) { + return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) + .then((result) => { + model_utils.setItem('recent-present', 'true'); + return result; + }) + .catch((err) => { + throw err; + }) + } else { + fetchRepoUtil.getAllRepos(org) + .then((repos) => { + if(repos!=null || repos!=undefined) { + return fetchAllRecentMonthContribs.fetchAllRecentMonthContribs(org, repos, queryTime) + .then((result) => { + model_utils.setItem('recent-present', 'true'); + return result; + }) + .catch((err) => { + throw err; + }) + } + }); + } + } + }); + }) + .catch((err) => { + throw err; + }) +} + + + +// EXPORTS +module.exports = { + storeAllRecentContribsInDb: storeAllRecentContribsInDb +} },{"../../models/utils":405,"../repoUtil/fetchRepoUtil":426,"./fetchAllRecentMonthContribs":416}],424:[function(require,module,exports){ -// Utility function that checks if a given date is behind the current date -// by 7 or less -function within_months(date, months) { - let current = (new Date).getTime(); - let past_date = (new Date(`${date}`)).getTime(); - let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24)); - let lim = 30 * months; - if(measure<=lim) { - return true; - } - return false; -} - - -// EXPORTS -module.exports = { - within_months: within_months +// Utility function that checks if a given date is behind the current date +// by 7 or less +function within_months(date, months) { + let current = (new Date).getTime(); + let past_date = (new Date(`${date}`)).getTime(); + let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24)); + let lim = 30 * months; + if(measure<=lim) { + return true; + } + return false; +} + + +// EXPORTS +module.exports = { + within_months: within_months } },{}],425:[function(require,module,exports){ -// Utility function that checks if a given date is behind the current date -// by 7 or less -function within_this_week(date) { - let current = (new Date).getTime(); - let past_date = (new Date(`${date}`)).getTime(); - let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24)); - if(measure<=7) { - return true; - } - return false; -} - - -// EXPORTS -module.exports = { - within_this_week: within_this_week +// Utility function that checks if a given date is behind the current date +// by 7 or less +function within_this_week(date) { + let current = (new Date).getTime(); + let past_date = (new Date(`${date}`)).getTime(); + let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24)); + if(measure<=7) { + return true; + } + return false; +} + + +// EXPORTS +module.exports = { + within_this_week: within_this_week } },{}],426:[function(require,module,exports){ -let model_utils = require('../../models/utils') - -// Fetches all the publiclab's repositories -function getAllRepos(org) { - - // This array is used to store all the repositories fetched from Github - let repos = []; - - return fetch(`https://api.github.com/users/${org}/repos?sort=pushed&direction=desc&per_page=100`) - .then(function gotRepos(data) { - if(data.status=='200') { - return data.json(); - }else { - throw "Couldn't fetch repositories :("; - } - }) - .then(function mapToEachRepo(results) { - results.map(function mappingToEachRepo(repo, index) { - return repos[index] = repo.name; - }); - return(repos); - }) - .then((repos) => { - // Storing the repos in the database - model_utils.setItem('repos', repos); - return(repos); - }) - .catch((err) => { - throw err; - }) - } - - -// EXPORTS -module.exports.getAllRepos = getAllRepos; +let model_utils = require('../../models/utils') + +// Fetches all the publiclab's repositories +function getAllRepos(org) { + + // This array is used to store all the repositories fetched from Github + let repos = []; + + return fetch(`https://api.github.com/users/${org}/repos?sort=pushed&direction=desc&per_page=100`) + .then(function gotRepos(data) { + if(data.status=='200') { + return data.json(); + }else { + throw "Couldn't fetch repositories :("; + } + }) + .then(function mapToEachRepo(results) { + results.map(function mappingToEachRepo(repo, index) { + return repos[index] = repo.name; + }); + return(repos); + }) + .then((repos) => { + // Storing the repos in the database + model_utils.setItem('repos', repos); + return(repos); + }) + .catch((err) => { + throw err; + }) + } + + +// EXPORTS +module.exports.getAllRepos = getAllRepos; },{"../../models/utils":405}],427:[function(require,module,exports){ -let model_utils = require('../models/utils') - -function getOrgWideIssues(org) { - let totalPromises = []; - let staleIssues = []; - let currentTime = (new Date).getTime(); - return model_utils.getItem("staleIssues-time").then((time) => { - if(time!=undefined && time!=null && (time-currentTime)/1000 >= 86400) { - return Promise.all([model_utils.deleteItem("staleIssues"), model_utils.deleteItem("staleIssues-time")]) - .then(()=> { - return true; - }) - } - }) - .then(() => { - return model_utils.getItem("staleIssues").then((issues) => { - let pages = 5; // we take 5 to stay under API limit - if(issues!=undefined && issues!=null) { - return issues; - } - - for(let i=1;i<=pages;i++) { - let curr = fetch(`https://api.github.com/search/issues?q=is%3Aopen+org%3A${org}+page%3A${i}`) - .then((data) => { - if(data.status=='200') { - return data.json(); - }else { - throw "Couldn't fetch issues"; - } - }) - .then(function (data) { - if(data!=null && data!=undefined) { - data.items.map(function mappingToIssues(issue, index) { - let dateLastUpdated = new Date(`${issue.updated_at}`); - let lastDate = dateLastUpdated.getTime(); - let today = (new Date).getTime(); - if(Math.ceil(Math.abs(today - lastDate) / (1000*3600*24)) > 10 ) { - staleIssues.push(issue); - } - }) - } - }) - .catch((err) => { - throw err; - }) - - - totalPromises.push(curr); - } - - return Promise.all(totalPromises).then(()=> { - let now = (new Date).getTime(); - model_utils.setItem("staleIssues", staleIssues); - model_utils.setItem("staleIssues-time", now); - return staleIssues; - }) - }) - }) - .catch((err) => { - throw err; - }) -} - - - -function getStaleIssues(org, repo) { - return getOrgWideIssues(org, repo) - .then((issues) => { - if(issues!=undefined && issues!=null) { - return issues; - } - }) - .catch((err) => { - throw err; - }) -} - - - - - -module.exports = { - getOrgWideIssues: getOrgWideIssues, - getStaleIssues: getStaleIssues +let model_utils = require('../models/utils') + +function getOrgWideIssues(org) { + let totalPromises = []; + let staleIssues = []; + let currentTime = (new Date).getTime(); + return model_utils.getItem("staleIssues-time").then((time) => { + if(time!=undefined && time!=null && (time-currentTime)/1000 >= 86400) { + return Promise.all([model_utils.deleteItem("staleIssues"), model_utils.deleteItem("staleIssues-time")]) + .then(()=> { + return true; + }) + } + }) + .then(() => { + return model_utils.getItem("staleIssues").then((issues) => { + let pages = 5; // we take 5 to stay under API limit + if(issues!=undefined && issues!=null) { + return issues; + } + + for(let i=1;i<=pages;i++) { + let curr = fetch(`https://api.github.com/search/issues?q=is%3Aopen+org%3A${org}+page%3A${i}`) + .then((data) => { + if(data.status=='200') { + return data.json(); + }else { + throw "Couldn't fetch issues"; + } + }) + .then(function (data) { + if(data!=null && data!=undefined) { + data.items.map(function mappingToIssues(issue, index) { + let dateLastUpdated = new Date(`${issue.updated_at}`); + let lastDate = dateLastUpdated.getTime(); + let today = (new Date).getTime(); + if(Math.ceil(Math.abs(today - lastDate) / (1000*3600*24)) > 10 ) { + staleIssues.push(issue); + } + }) + } + }) + .catch((err) => { + throw err; + }) + + + totalPromises.push(curr); + } + + return Promise.all(totalPromises).then(()=> { + let now = (new Date).getTime(); + model_utils.setItem("staleIssues", staleIssues); + model_utils.setItem("staleIssues-time", now); + return staleIssues; + }) + }) + }) + .catch((err) => { + throw err; + }) +} + + + +function getStaleIssues(org, repo) { + return getOrgWideIssues(org, repo) + .then((issues) => { + if(issues!=undefined && issues!=null) { + return issues; + } + }) + .catch((err) => { + throw err; + }) +} + + + + + +module.exports = { + getOrgWideIssues: getOrgWideIssues, + getStaleIssues: getStaleIssues } },{"../models/utils":405}]},{},[407]); diff --git a/src/scripts/community-toolbox.js b/src/scripts/community-toolbox.js index 86b99b32..63493e4a 100644 --- a/src/scripts/community-toolbox.js +++ b/src/scripts/community-toolbox.js @@ -246,18 +246,7 @@ CommunityToolbox = function CommunityToolbox(org, repo) { } }) } - - - function displayIssuesForRepo(org, repo, label, selector) { - toolbox.api.Issues - .getIssuesForRepo(org, repo, { qs: { labels: label } }) - .then(function onGotIssues(issues) { - issues.forEach(function(issue) { - toolbox.issuesUI.insertIssue(issue, selector); - }); - }) - } - + function showStaleIssues(org, repo) { return issuesUtil.getStaleIssues(org, repo)