can can do github orgs, progbar

This commit is contained in:
wassname
2017-11-29 11:02:22 +08:00
parent ef4c16b96d
commit 2eb1119c44
5 changed files with 122 additions and 55 deletions
+2 -1
View File
@@ -14,6 +14,7 @@
"gh.js": "^3.0.8",
"jquery": "^3.1.1",
"lodash": "^4.17.4",
"moment": "^2.17.1"
"moment": "^2.17.1",
"nanobar": "^0.4.2"
}
}
+2 -1
View File
@@ -12,7 +12,7 @@
<div>
<label><a href="https://github.com/settings/tokens">Github api token: </a></label>
<input id="token" placeholder="token" />
<input id="token" placeholder="token" value="1996bd63f4c524b4cd36499e3db39d321f0b39a7"/>
</div>
<button id="refresh">Refresh</button>
@@ -33,6 +33,7 @@
<script src="https://cdn.datatables.net/colreorder/1.3.2/js/dataTables.colReorder.min.js" charset="utf-8"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/colreorder/1.3.2/css/colReorder.dataTables.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/nanobar/0.4.2/nanobar.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gh.js/3.0.8/gh.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js" charset="utf-8"></script>
File diff suppressed because one or more lines are too long
+35 -2
View File
@@ -3,8 +3,8 @@
*/
let gh = new GitHub(localStorage['gh_token'] || '')
$(document).ready(function() {
$(document).ready(function() {
// cache and save github api token
$('#token').val(localStorage['gh_token'])
$('#token').on('change', function() {
@@ -14,6 +14,16 @@ $(document).ready(function() {
})
var MergeBySumingNumbers = objects =>
objects.reduce((s,r)=>{
Object.keys(r).map(key=>{
v = r[key]
if (typeof(v)==="number") s[key]=(s[key]||0)+v
else s[key] = v
})
return s
},{})
function promiseGitHubRepoStats(url) {
@@ -80,9 +90,32 @@ function promiseGitHubRepoStats(url) {
})
return Promise.all([promiseStats, promiseContributors, promiseChanges, promiseCommits, promiseReleases]).then(data => _.merge(...data))
}
function promiseGitHubRepoStatsMulti(repos){
return Promise.all(
repos.map(promiseGitHubRepoStats)
)
.then(MergeBySumingNumbers)
}
function promiseGitHubOrgStats(org){
var apiUrl = "orgs/" + org.replace('https://github.com/', '') + '/repos'
return new Promise(function(resolve, reject) {
gh.get(apiUrl, {opts:{per_page:100}}, (err, response) => {
if (err)
reject(err)
else
resolve(response)
})
})
.then(data => data.map(row=>row.full_name))
.then(promiseGitHubRepoStatsMulti)
}
function promiseBitbucketRepoStats(url) {
url = url.replace('https://bitbucket.org/', 'https://api.bitbucket.org/2.0/repositories/')
+78 -3
View File
@@ -11,6 +11,56 @@ TODO:
function renderUrl(data){return '<a href="'+data+'">'+data+'</a>'}
function renderDate(data){return data?moment(data).format('YYYY/MM/DD'):data}
// ideally I want the input to bea list of github users or repos
var coins = {
"Bitcoin": 'https://github.com/bitcoin/bitcoin',
"Ethereum": 'https://github.com/ethereum/go-ethereum',
"Ripple": 'https://github.com/ripple/rippled',
"Litecoin": 'https://github.com/litecoin-project/litecoin',
"Monero": 'https://github.com/monero-project/monero',
'Dash': 'https://github.com/dashpay/dash',
"Augur": "https://github.com/AugurProject/augur-core",
"Maidsafe": "https://github.com/maidsafe/safe_client_libs",
"Steem": "https://github.com/steemit/steem",
"NEM": "https://github.com/NemProject/nem.core",
//'Iconomi':'',
"Factom": 'https://github.com/FactomProject/factomd',
'Dogecoin': 'https://github.com/dogecoin/dogecoin',
'Waves': 'https://github.com/wavesplatform/Waves',
'ZCash': 'https://github.com/zcash/zcash',
'DigixDAO': 'https://github.com/DigixGlobal/digixdao-contracts',
'Stellar Lumens': 'https://github.com/stellar/stellar-core',
'Lisk': 'https://github.com/LiskHQ/lisk',
'Tether': 'https://bitbucket.org/tetherto/tether-api-client-ruby',
// 'E-Dinar Coin': 'https://github.com/edincoin/EDINARCOIN',
//'ARDOR':'',
'GameCredits': 'https://github.com/gamecredits-project/GameCredits',
'Swiscoin': 'https://github.com/SCNPay/swiscoin',
'Bitshares': 'https://github.com/bitshares/bitshares-2',
/** Notable below top 25 **/
"Golem": "https://github.com/golemfactory/golem",
"PIVX":"https://github.com/PIVX-Project/PIVX",
"Nxt": 'https://bitbucket.org/JeanLucPicard/nxt', // bitbucket
"Iota": "https://github.com/iotaledger/iri",
"IotaOrg": "https://github.com/iotaledger",
"Vertcoin": 'https://github.com/vertcoin/vertcoin',
'Stratis': 'https://github.com/stratisproject/stratisX',
'VCash': 'https://github.com/openvcash/vcash',
"BitcoinUnlimited": "https://github.com/BitcoinUnlimited/BitcoinUnlimited",
"Bitcoinclassic": "https://github.com/bitcoinclassic/bitcoinclassic",
"Burstcoin": "https://github.com/BurstProject/burstcoin",
"Blocknet": "https://github.com/atcsecure/blocknet",
"Syscoin": "https://github.com/syscoin/syscoin2",
"Gnosis":"https://github.com/gnosis/gnosis-contracts",
// "":"https://github.com/voxelus"
"Qora": "https://github.com/Qoracoin/Qora",
"Storj": "https://github.com/Storj/core",
"Sia": "https://github.com/NebulousLabs/Sia",
"Bitcore": "https://github.com/dgbholdings/bitcore",
'Tittiecoin': 'https://github.com/tittiecoin/tittiecoin', // example shitcoin
}
var columns = [
{
"data": "coin",
@@ -166,7 +216,10 @@ function makeMarkDownTable(data) {
/** fill missing attribtes so datatables stops complaining **/
function fillAll(data, columns){
return data.map(row=>{
// TODO log undefine and NaN rows
return data
.filter(_.isObject)
.map(row=>{
for (var i = 0; i < columns.length; i++) {
var key = columns[i].data
if (row[key]===undefined) row[key] = ''
@@ -183,24 +236,46 @@ $(document).ready(function() {
// Collect data
let promises
var nanobar = new Nanobar({});
let total = Object.keys(coins).length
let finished_count = 0
if (!localStorage['gh-data'])
promises = Promise.all(Object.keys(coins).map(coin => {
var url = coins[coin]
// TODO(mjc) if its a user, list repos
// TODO(mjc) if url is a list, do promiseGitHubRepoStatsMulti
if (url.includes('github.com')) {
if (url.replace('https://github.com/','').includes('/')){
return promiseGitHubRepoStats(url).then(data => {
data.coin = coin
data.url = url
return data
})
} else {
return promiseBitbucketRepoStats(url).then(data => {
return promiseGitHubOrgStats(url).then(data => {
data.coin = coin
data.url = url
return data
})
}
} else {
return promiseBitbucketRepoStats(url).then(data => {
data.coin = coin
data.url = url
return data
}).catch(err => {console.error(err)})
}
}))
}).map(promise=>promise
.then(value => {
// progressbar
finished_count+=1
nanobar.go(finished_count/total*100)
return value
})
// .catch(err => {console.error(err)})
)
)
.then((data) => {
// cache
localStorage['gh-data'] = JSON.stringify(data)