Skip to content

Instantly share code, notes, and snippets.

@mikaelvesavuori
Last active January 9, 2024 00:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelvesavuori/a0b75f0ebc617e20caab42a2b25c66f3 to your computer and use it in GitHub Desktop.
Save mikaelvesavuori/a0b75f0ebc617e20caab42a2b25c66f3 to your computer and use it in GitHub Desktop.
Get Individual Contributor metrics from GitHub's GraphQL API.

Get Individual Contributor metrics from GitHub's GraphQL API

These are some handy snippets to get common metrics for checking how active a software engineer is.

  • How many pushes are made by the IC?
  • How many reviews are made by the IC?
  • How many comments are made by the IC?

Setup

The API endpoint is https://api.github.com/graphql.

Don't forget to create a Personal Access Token ("classic") and set the correct headers before calling the API.

Header Value
Content-Type  application/json
Accept  application/vnd.github.v3+json
Authorization  Bearer {PAT}

References

How many pushes are made by the IC?

query ($user: String!, $start: DateTime!, $end: DateTime!) {
  user(login: $user) {
    contributionsCollection(from: $start, to: $end) {
      commitContributionsByRepository(maxRepositories: 100) {
        repository {
          nameWithOwner
        }
        contributions {
          totalCount
        }
      }
    }
  }
  rateLimit {
    cost
    remaining
  }
}

Query variables

{
  "user": "YOUR_USER",
  "start": "2022-01-01T00:00:00Z",
  "end": "2022-12-31T00:00:00Z"
}

JSONPath Plus

Use $.data..totalCount to get the count for each repository.

How many reviews are made by the IC?

query ($query: String!) {
  search(last: 100, query: $query, type: ISSUE) {
    nodes {
      ... on PullRequest {
        number
        title
        createdAt
        mergedAt
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
  rateLimit {
    cost
    remaining
  }
}

Query variables

{
  "query": "created:2022-01-01..2022-12-31 reviewed-by:YOUR_USER"
}

JSONPath Plus

Use $.data.search.nodes.length to get the count.

How many comments are made by the IC?

query ($query: String!) {
  search(last: 100, query: $query, type: ISSUE) {
    nodes {
      ... on Comment {
        createdAt
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
  rateLimit {
    cost
    remaining
  }
}

Query variables

{
  "query": "created:2022-01-01..2022-12-31 commenter:YOUR_USER"
}

JSONPath Plus

Use $.data.search.nodes.length to get the count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment