Skip to content

Language distribution for pinned repos failing #3

@yashsehgal

Description

@yashsehgal

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions