From ed829c15c790f3ccd3d837a42a4803622fb9006a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas?= Date: Tue, 1 Oct 2019 20:20:51 +0300 Subject: [PATCH 1/2] comits/ahead/behind/status --- index.html | 3 +++ js/main.js | 72 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 6537424..ac6517d 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,9 @@ .black { color: #292b2c; } + .card { + display: table; + } diff --git a/js/main.js b/js/main.js index e19aae8..44567c0 100644 --- a/js/main.js +++ b/js/main.js @@ -34,24 +34,38 @@ function fetchData() { } } -function updateDT(data) { +function updateDT(data, repo) { // Remove any alerts, if any: if ($('.alert')) $('.alert').remove(); // Format dataset and redraw DataTable. Use second index for key name const forks = []; - for (let fork of data) { - fork.repoLink = `Link`; - fork.ownerName = fork.owner.login; - forks.push(fork); - } - const dataSet = forks.map(fork => - window.columnNamesMap.map(colNM => fork[colNM[1]]) - ); - window.forkTable - .clear() - .rows.add(dataSet) - .draw(); + + Promise.all(data.map(fork => + fetch(`https://api.github.com/repos/${repo}/compare/master...${fork.owner.login}:master`) + .then(resp => resp.json()) + .then(data => { + fork.repoLink = `Link`; + fork.ownerName = fork.owner.login; + fork.status = data.status; + fork.ahead_by = data.ahead_by; + fork.behind_by = data.behind_by; + fork.total_commits = data.total_commits; + forks.push(fork); + }) + )) + .then(_ => { + const dataSet = forks.map(fork => + window.columnNamesMap.map(colNM => fork[colNM[1]]) + ); + window.forkTable + .clear() + .rows.add(dataSet) + .draw(); + }) + .catch(error => { + handleError(error); + }); } function initDT() { @@ -67,6 +81,11 @@ function initDT() { ['Open Issues', 'open_issues_count'], ['Size', 'size'], ['Last Push', 'pushed_at'], + ['Status', 'status'], + ['Status', 'status'], + ['Ahead by', 'ahead_by'], + ['Behind by', 'behind_by'], + ['Commits', 'total_commits'], ]; // Sort by stars: @@ -84,11 +103,11 @@ function initDT() { render: colNM[1] === 'pushed_at' ? (data, type, _row) => { - if (type === 'display') { - return moment(data).fromNow(); - } - return data; + if (type === 'display') { + return moment(data).fromNow(); } + return data; + } : null, }; }), @@ -109,19 +128,22 @@ function fetchAndShow(repo) { return response.json(); }) .then(data => { - console.log(data); - updateDT(data); + updateDT(data, repo); }) .catch(error => { - const msg = - error.toString().indexOf('Forbidden') >= 0 - ? 'Error: API Rate Limit Exceeded' - : error; - showMsg(`${msg}. Additional info in console`, 'danger'); - console.error(error); + handleError(error); }); } +function handleError(error) { + const msg = + error.toString().indexOf('Forbidden') >= 0 + ? 'Error: API Rate Limit Exceeded' + : error; + showMsg(`${msg}. Additional info in console`, 'danger'); + console.error(error); +} + function showMsg(msg, type) { let alert_type = 'alert-info'; From fa662c563ca2fd46c1ddcbf18cf1116670af0665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas?= Date: Sat, 5 Oct 2019 09:31:33 +0300 Subject: [PATCH 2/2] removed duplicate status column --- js/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/main.js b/js/main.js index 44567c0..44c59eb 100644 --- a/js/main.js +++ b/js/main.js @@ -82,7 +82,6 @@ function initDT() { ['Size', 'size'], ['Last Push', 'pushed_at'], ['Status', 'status'], - ['Status', 'status'], ['Ahead by', 'ahead_by'], ['Behind by', 'behind_by'], ['Commits', 'total_commits'],