Skip to content

Commit

Permalink
Fix NaN and undefined for empty profiles (anuraghazra#1965)
Browse files Browse the repository at this point in the history
* totalCommits: don't return NaN

* rank: B+ should cover everyone

Empty profile used to show "undefined" as the rank. Now empty profile shows "A+"... is B+ possible?
  • Loading branch information
adil192 authored and SousaPedro11 committed Aug 29, 2022
1 parent 75e0304 commit 6268344
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/calculateRank.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function calculateRank({

const level = (() => {
if (normalizedScore < RANK_S_VALUE) return "S+";
if (normalizedScore >= RANK_S_VALUE && normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
if (normalizedScore >= RANK_DOUBLE_A_VALUE && normalizedScore < RANK_A2_VALUE) return "A++";
if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) return "A+"
if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) return "B+"
if (normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
if (normalizedScore < RANK_A2_VALUE) return "A++";
if (normalizedScore < RANK_A3_VALUE) return "A+"
return "B+";
})()

return { level, score: normalizedScore };
Expand Down
9 changes: 5 additions & 4 deletions src/fetchers/stats-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ const totalCommitsFetcher = async (username) => {

try {
let res = await retryer(fetchTotalCommits, { login: username });
if (res.data.total_count) {
let total_count = res.data.total_count;
if (!!total_count && !isNaN(total_count)) {
return res.data.total_count;
}
} catch (err) {
logger.log(err);
// just return 0 if there is something wrong so that
// we don't break the whole app
return 0;
}
// just return 0 if there is something wrong so that
// we don't break the whole app
return 0;
};

/**
Expand Down

0 comments on commit 6268344

Please sign in to comment.