Skip to content

Commit a481021

Browse files
authored
Fix NaN and undefined for empty profiles (#1965)
* 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?
1 parent 579cb7d commit a481021

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/calculateRank.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ function calculateRank({
6565

6666
const level = (() => {
6767
if (normalizedScore < RANK_S_VALUE) return "S+";
68-
if (normalizedScore >= RANK_S_VALUE && normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
69-
if (normalizedScore >= RANK_DOUBLE_A_VALUE && normalizedScore < RANK_A2_VALUE) return "A++";
70-
if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) return "A+"
71-
if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) return "B+"
68+
if (normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
69+
if (normalizedScore < RANK_A2_VALUE) return "A++";
70+
if (normalizedScore < RANK_A3_VALUE) return "A+"
71+
return "B+";
7272
})()
7373

7474
return { level, score: normalizedScore };

src/fetchers/stats-fetcher.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ const totalCommitsFetcher = async (username) => {
8686

8787
try {
8888
let res = await retryer(fetchTotalCommits, { login: username });
89-
if (res.data.total_count) {
89+
let total_count = res.data.total_count;
90+
if (!!total_count && !isNaN(total_count)) {
9091
return res.data.total_count;
9192
}
9293
} catch (err) {
9394
logger.log(err);
94-
// just return 0 if there is something wrong so that
95-
// we don't break the whole app
96-
return 0;
9795
}
96+
// just return 0 if there is something wrong so that
97+
// we don't break the whole app
98+
return 0;
9899
};
99100

100101
/**

0 commit comments

Comments
 (0)