Skip to content

Commit

Permalink
fix: update logic for most used languages to match contributor profile (
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Apr 17, 2024
1 parent 17d1cc5 commit e8f8a75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utils/contributor-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("contributor utilities", () => {
},
}) satisfies DbUser;

expect(getTopContributorLanguages(user)).toEqual(["go", "javascript"]);
expect(getTopContributorLanguages(user)).toEqual(["go", "rust"]);
});

it("should get no languages when there are no languages", () => {
Expand Down
12 changes: 10 additions & 2 deletions lib/utils/contributor-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export function getTopContributorLanguages(contributor: DbUser) {
// Note that it's possible for a user to have no languages
const languages = Object.entries(contributor.languages).map(([language]) => language);
const languages = Object.entries(contributor.languages).map(([language, percentageUsed]) => ({
language,
percentageUsed: percentageUsed,
}));
const langArray = languages.slice().sort((a, b) => b.percentageUsed - a.percentageUsed);
const sortedLangArray = langArray
.sort((a, b) => (a.percentageUsed < b.percentageUsed ? 1 : -1))
.slice(0, 2)
.map((lang) => lang.language);

return languages.sort((a, b) => (a < b ? -1 : 1)).slice(0, 2);
return sortedLangArray;
}
2 changes: 1 addition & 1 deletion next-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ interface DbUser {
readonly discord_url: string;
readonly notification_count: number;
readonly insights_count: number;
readonly languages: { [lang]: number };
readonly languages: { [lang: string]: number };
readonly first_opened_pr_at: string;
readonly followers_count: number;
readonly following_count: number;
Expand Down

0 comments on commit e8f8a75

Please sign in to comment.