How to receive the total number of contributors with GitHub API for a list of repositories?

Hi guys,

I am struggling with getting the total contributors count and the total commits of a repository.

My Plan is to receive the most popular repositories by stars within a specific time frame and list different variables i.e. total releases, number of forks, number of watchers etc… I also used pagination to be able to get more than 100 repositories.

However I am not able to obtain the total contributors number and the total number of commits.

I found following code but this would just work for a single repository.

query {
  repository(owner:"rails", name:"rails") {
    object(expression:"master") {
      ... on Commit {
        history {
          totalCount
        }
      }
    }
  }
}

The query I used looks like this and I am trying to find a way to insert two additional requests for total contributors and commit: 

query {
  search(
    #after:"Y3Vyc29yOjEwMDA="
    type:REPOSITORY,
    query: """
      stars:>=500
      forks:>=1
      size:>=1000
      pushed:>=2019-08-01
      created:>=2018-08-01

    """,
    last: 100
  ) {
        pageInfo{
          hasNextPage
          endCursor
        }
    repos: edges {
      repo: node {
        ... on Repository {
          name
          createdAt
          description
          url
          isArchived
          owner{__typename}
          stargazers{stars: totalCount}
          diskUsage
          watchers{watchers: totalCount}
          releases {releases: totalCount}
          forks: forkCount
          licenseInfo{name}
          milestones{totalCount}
          openpullRequests:pullRequests(states:OPEN){totalCount}
          pullRequests {pullRequests: totalCount}
          openIssues: issues(states:OPEN){totalCount}
          totalIssues: issues {totalIssues: totalCount}
          primaryLanguage {primaryLanguage: name}
          languages(first: 1) { nodes {name} }
          pushedAt
          updatedAt

            }
          }
        }
      }
    }

Does anybody have an idea? Help would be very appreciated! :slight_smile:

Hi @ranicki69,

Thank you for being here! 

It seems that you are on the right track and may need to include some other variables into your query.  Here is an example that may help you along the way:

{
  gson: repository(owner: "google", name: "gson") {
    ...RepoFragment
  }
  martian: repository(owner: "google", name: "martian") {
    ...RepoFragment
  }
  keyboard: repository(owner: "jasonrudolph", name: "keyboard") {
    ...RepoFragment
  }
}
fragment RepoFragment on Repository {
  name
  refs(first: 100, refPrefix: "refs/heads/") {
    edges {
      node {
        name
        target {
          ... on Commit {
            id
            history(first: 0) {
              totalCount
            }
          }
        }
      }
    }
  }
}
1 Like