Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update logic for most used languages to match contributor profile #3205

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading