github-api icon indicating copy to clipboard operation
github-api copied to clipboard

stargazercount is 0 unless fetched directly

Open maxandersen opened this issue 4 years ago • 3 comments

Describe the bug Using latest 1.128:

ghContent.getOwner().getStarGazersCount() returns 0, but gitHub.getRepository(ghContent.getOwner().getFullName()).getStargazersCount()); returns the proper count.

Probably related to #349 and #1068

Expected behavior stargazer count should be fetched, throw error or return -1 or similar - anything but returning 0.

maxandersen avatar May 09 '21 08:05 maxandersen

Is the GHContent object created above, a result of a code search API call? https://docs.github.com/en/rest/reference/search#search-code.

If so, then the root cause is clear as the GitHub Rest API doesn't provide the field stargazers_count in the response.

{
  "total_count": 7,
  ...
  "items": [
    {
      "name": "classes.js",
      ...
      "repository": {
        "id": 167174,
        ...
        "stargazers_url": "https://api.github.com/repos/jquery/jquery/stargazers",
        ...
      }
    }
  ]
}

whereas the direct query for a repository provides the stargazers_count field as well as the stargazers_url - https://docs.github.com/en/rest/reference/repos#get-a-repository

[
  {
    "id": 1296269,
    ...
    "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers",
    ...
    "stargazers_count": 80,
    ...
  }
]

akashRindhe avatar May 10 '21 05:05 akashRindhe

yes, ghcontent is fetched from search query.

maxandersen avatar May 11 '21 21:05 maxandersen

We should replace int with Integer and check for null. Or we could have the stargazers_count default to -1 in GHRepository and test for that before returning it.
This another example of some endpoints (search endpoints especially) returning incomplete data, which #1138 would help us to address.

bitwiseman avatar May 12 '21 03:05 bitwiseman