How to order GitHub forks by stars, watchers, commits using the GitHub API?

Viewed 593

For a given repository, we can view its forks by replacing 'username' and 'repo' in the following URL:

https://github.com/username/repo/network/members

Example: https://github.com/veracrypt/VeraCrypt/network/members

Question

Using the GitHub API, how can we order a repository's forks by

  1. stars
  2. watchers
  3. commits (since forking)

Note: accessible wrappers are fine (e.g. using python library for GitHub API)

What I know so far

We could write a script to individually retrieve the metrics for each of the ~500 forks. This may be the best/simplest solution, although I do know GitHub has a lot of built in (hidden) features, so I do wonder if collecting the most active forks may have been considered and built into the API by GitHub. Iterating through hundreds/thousands of forks could also invoke the GitHub API's rate limiting, so please be mindful if using this approach.

2 Answers

Not a full answer, but it is possible to order by stargazers using GraphQL API (try GitHub GraphQL API Explorer for quick start!):

{
  repository(owner: "vuejs", name: "vue") {
    forks(orderBy: {field: STARGAZERS, direction: DESC}, first: 3) {
      nodes {
        nameWithOwner
        stargazerCount
      }
    }
  }
}

Result:

{
  "data": {
    "repository": {
      "forks": {
        "nodes": [
          {
            "nameWithOwner": "SmallComfort/react-vue",
            "stargazerCount": 1198
          },
          {
            "nameWithOwner": "supergaojian/vue",
            "stargazerCount": 20
          },
          {
            "nameWithOwner": "developedbyed/vue",
            "stargazerCount": 13
          }
        ]
      }
    }
  }
}

Possible fields are:

enum RepositoryOrderField {
  """
  Order repositories by creation time
  """
  CREATED_AT

  """
  Order repositories by name
  """
  NAME

  """
  Order repositories by push time
  """
  PUSHED_AT

  """
  Order repositories by number of stargazers
  """
  STARGAZERS

  """
  Order repositories by update time
  """
  UPDATED_AT
}

I found a project for that: Useful Forks.
I have tried it and it works perfect as long as the fork didn't change its original name.

Related