Skip to content

Instantly share code, notes, and snippets.

@mikaelvesavuori
Last active January 14, 2025 07:25
Show Gist options
  • Select an option

  • Save mikaelvesavuori/a0b75f0ebc617e20caab42a2b25c66f3 to your computer and use it in GitHub Desktop.

Select an option

Save mikaelvesavuori/a0b75f0ebc617e20caab42a2b25c66f3 to your computer and use it in GitHub Desktop.

Revisions

  1. mikaelvesavuori revised this gist Nov 22, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ic-metrics-gh-graphql-api.md
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,10 @@ These are some handy snippets to get common metrics for checking how active a so

    ## Setup

    Don't forget to [create a Personal Access Token ("classic")](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and set the correct headers before calling the API.

    **The API endpoint is [https://api.github.com/graphql](https://api.github.com/graphql)**.

    Don't forget to [create a Personal Access Token ("classic")](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and set the correct headers before calling the API.

    | Header | Value |
    | ---------------- | -------------------------------- |
    | `Content-Type`  | `application/json` |
  2. mikaelvesavuori revised this gist Nov 22, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ic-metrics-gh-graphql-api.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ These are some handy snippets to get common metrics for checking how active a so

    Don't forget to [create a Personal Access Token ("classic")](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and set the correct headers before calling the API.

    **The API endpoint is [https://api.github.com/graphql](https://api.github.com/graphql)**.

    | Header | Value |
    | ---------------- | -------------------------------- |
    | `Content-Type`  | `application/json` |
  3. mikaelvesavuori revised this gist Nov 22, 2022. 1 changed file with 35 additions and 4 deletions.
    39 changes: 35 additions & 4 deletions ic-metrics-gh-graphql-api.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,25 @@
    # Get Individual Contributor metrics from GitHub's GraphQL API

    Description.
    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

    Don't forget to [create a Personal Access Token ("classic")](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) 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

    - [GitHub GraphQL API](https://docs.github.com/en/graphql)
    - [Searching issues and pull requests](https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests)

    ## How many pushes are made by the IC?

    @@ -25,7 +44,7 @@ query ($user: String!, $start: DateTime!, $end: DateTime!) {
    }
    ```

    Query variables:
    ### Query variables

    ```json
    {
    @@ -35,6 +54,10 @@ Query variables:
    }
    ```

    ### JSONPath Plus

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

    ## How many reviews are made by the IC?

    ```gql
    @@ -60,14 +83,18 @@ query ($query: String!) {
    }
    ```

    Query variables:
    ### Query variables

    ```json
    {
    "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?

    ```gql
    @@ -90,10 +117,14 @@ query ($query: String!) {
    }
    ```

    Query variables:
    ### Query variables

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

    ### JSONPath Plus

    Use `$.data.search.nodes.length` to get the count.
  4. mikaelvesavuori revised this gist Nov 22, 2022. 1 changed file with 55 additions and 55 deletions.
    110 changes: 55 additions & 55 deletions ic-metrics-gh-graphql-api.md
    Original file line number Diff line number Diff line change
    @@ -6,94 +6,94 @@ Description.

    ```gql
    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
    }
    user(login: $user) {
    contributionsCollection(from: $start, to: $end) {
    commitContributionsByRepository(maxRepositories: 100) {
    repository {
    nameWithOwner
    }
    contributions {
    totalCount
    }
    }
    }
    }
    rateLimit {
    cost
    remaining
    }
    }
    ```

    Query variables:

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

    ## How many reviews are made by the IC?

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

    Query variables:

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

    ## How many comments are made by the IC?

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

    Query variables:

    ```json
    {
    "query": "created:2022-01-01..2022-12-31 commenter:YOUR_USER"
    "query": "created:2022-01-01..2022-12-31 commenter:YOUR_USER"
    }
    ```
    ```
  5. mikaelvesavuori renamed this gist Nov 22, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. mikaelvesavuori created this gist Nov 22, 2022.
    99 changes: 99 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    # Get Individual Contributor metrics from GitHub's GraphQL API

    Description.

    ## How many pushes are made by the IC?

    ```gql
    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:

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

    ## How many reviews are made by the IC?

    ```gql
    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:

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

    ## How many comments are made by the IC?

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

    Query variables:

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