Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comits/ahead/behind/status #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
.black {
color: #292b2c;
}
.card {
display: table;
}
</style>
</head>

Expand Down
71 changes: 46 additions & 25 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<a href="https://github.com/${fork.full_name}">Link</a>`;
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 = `<a href="https://github.com/${fork.full_name}">Link</a>`;
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() {
Expand All @@ -67,6 +81,10 @@ function initDT() {
['Open Issues', 'open_issues_count'],
['Size', 'size'],
['Last Push', 'pushed_at'],
['Status', 'status'],
['Ahead by', 'ahead_by'],
['Behind by', 'behind_by'],
['Commits', 'total_commits'],
];

// Sort by stars:
Expand All @@ -84,11 +102,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,
};
}),
Expand All @@ -109,19 +127,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';

Expand Down