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?
This commit is contained in:
Adil Hanney 2022-08-26 21:28:48 +01:00 committed by GitHub
parent 579cb7d175
commit a481021dab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View file

@ -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 };

View file

@ -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;
};
/**