Skip to content

Commit

Permalink
Reworked github commit system
Browse files Browse the repository at this point in the history
  • Loading branch information
anweisen committed Dec 23, 2020
1 parent 9eb6815 commit 6d7b64e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions assets/js/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ let commitsToday = 0;
async function countEvents(page) {

const events = await fetchEvents(page);
if (!events) return
if (!events) return;

for (let event of events) {

const eventDateString = event.created_at;
const eventDate = new Date(eventDateString);
const eventDate = new Date(event.created_at);
if (!isToday(eventDate)) {
// Leaving loop, the event time line is sorted by the date
// If a event is not from today, the events after that cannot be from today
break;
}

const payload = event.payload.commits;

if (!payload) {
// Leaving loop, payload is undefined
break;
} else if (isToday(eventDate)) {
commitsToday += payload.length;
} else {
// Leaving loop, the event time line is sorted by the date
// If a event is not from today, the events after that cannot be from today
// Leaving loop, there is no payload
break;
}

commitsToday += payload.length;

}

}
async function fetchStats() {

commitsToday = 0;

let page = 1;

while (true) {
let before = commitsToday;
await countEvents(page);
Expand Down Expand Up @@ -73,6 +74,7 @@ async function refreshGit() {
element.innerHTML = message(commitsToday);
element.href = `https://github.com/${user}`;
} else {
// Hiding info if no data about github was given
element.href = "#";
element.parentElement.style.display = "none";
}
Expand All @@ -86,10 +88,10 @@ function message(commits) {
// 1 - 2
return `well, ${commits} ${commitWord(commits)} today`;
} else if (commits <= 5) {
// 2 - 5
// 3 - 5
return `${commits} excellent ${commitWord(commits)} today`;
} else {
// 10 or more
// 6 or more
return `${commits} productive ${commitWord(commits)} today`;
}
}
Expand Down

0 comments on commit 6d7b64e

Please sign in to comment.