Skip to content

Instantly share code, notes, and snippets.

@armsp
Last active February 8, 2020 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armsp/3701b34d9f99bf55e9e81e246ce28c85 to your computer and use it in GitHub Desktop.
Save armsp/3701b34d9f99bf55e9e81e246ce28c85 to your computer and use it in GitHub Desktop.
GraphQL query to get user statistics like total followers, stargazers, watchers, issues, pull requests
query {
  user(login:"<any user name>"){               #Use "viewer" if you want to run it on your profile
    repositories(orderBy: {field: STARGAZERS, direction: DESC}){
      totalCount
    }
    followers{
      totalCount
    }
    issues_sum:issues{
      totalCount
    }
    issues_open:issues(states: OPEN){
      totalCount
    }
    issues_closed:issues(states: CLOSED){
      totalCount
    }
    pr_sum:pullRequests{
      totalCount
    }
    pr_open:pullRequests(states: OPEN){
      totalCount
    }
    pr_closed:pullRequests(states: CLOSED){
      totalCount
    }
    pr_merged:pullRequests(states: MERGED){
      totalCount
    }
    repositories(orderBy: {field: STARGAZERS, direction: DESC}){
      nodes{
        name
        stargazers{
          totalCount
        }
        watchers{
          totalCount
        }
        forkCount
      }
    }   
  }
}

USES

Use this to monitor and design apps to get notifications on important actions like follower count increase, watchers count increase, stargazer increase etc.

TODO

  • Right now you exploit a bug(?) by calling repositories twice to ignore pagination when the number of repositories is less than 100. If it is more than 100 anyways you'd need pagination so rewrite this query with proper pagination.
  • Can we get stats like stargazers, watchers, issues, prs without iterating on repository nodes? If not, then why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment