yashsehgal / use-github-react

React hook for fetching activities and information via GitHub API
https://use-github-react.vercel.app
MIT License
1 stars 4 forks source link

Language distribution for pinned repos failing #3

Open yashsehgal opened 1 month ago

yashsehgal commented 1 month ago

The language distribution calculation for pinned repositories is not working as expected. When trying to get the language distribution for pinned repos, the result is an empty array.

Example of the issue:

const { getRepositories } = useGitHub({ username: 'octocat' });

// Works correctly
console.log(getRepositories().all().languageDistribution());
// Output: [{ language: 'javascript', percentage: 0.5 }, { language: 'python', percentage: 0.5 }]

// Returns an empty array
console.log(getRepositories().pinned().languageDistribution());
// Output: []

Possible cause: The GraphQL query for pinned repos only fetches primaryLanguage, but the calculateLanguageDistribution function expects a language property.

Possible fix can be something like,

const pinnedRepos = response.data.data.user.pinnedItems.nodes.map(
  (repo: any) => ({
    // ... other properties ...
    language: repo.primaryLanguage
      ? repo.primaryLanguage.name.toLowerCase()
      : null,
  }),
);

This change should make the pinned repos data structure compatible with the language distribution function.

akshatvirmani commented 1 month ago

@yashsehgal maybe I can work on this

yashsehgal commented 1 month ago

Hi @akshatvirmani - For sure, would love to assign you this one. If sounds good, we can discuss this one in our weekly issue discussion meeting on the upcoming Wednesday. Let's try to debug and find the issue on-call and then we can raise a fix for the same.

akshatvirmani commented 1 month ago

Hello, Great! See you tomorrow then!