4

I am attempting to use GitHub's GraphQL interface to query for the number of PR's reviewed within a GitHub repo during a specific month.

Ideally, I would like to only pull comments and reviews that took place within a specific time frame. Ultimately, I would like to group my results on a user by user basis.

userA  10 reviews during month
userB  6 reviews during month
userC  4 reviews during month

Here is the query that I have created so far.

{
  repository(owner: "DSpace", name: "DSpace") {
    pullRequests(last: 50) {
      nodes {
        state
        resourcePath
        comments (last: 100) {
          nodes {
            author {
              login
            }
          }
        }
        reviews(last: 100) {
          nodes {
            state
            author {
              login
            }
          }
        }
      }  
    }
  }
}

I suspect that I will need to iterate over all pull requests and then filter reviews/comments that fall within a specific date range.

When I look at the GitHub GraphDB schema, the "reviews" and "comments" objects do not seem to be filterable by date. I see that the available filters are first, last, author, and state. Is there some way to express such a filter in the GraphDB query language?

I see that GraphQL provides a way to filter by boolean properties with @include and @skip. Is there a way to pass expressions to these constructs?

terrywb
  • 3,740
  • 3
  • 25
  • 50

1 Answers1

4

You could try using Github GraphQL's search (more of a v3 REST contruct, but still available in v4 graphQL). The query string specifies the owner, repo name, date range of the pull requests last updated (which serves as an approximation of when comments/reviews are created), and type pr.

The new query, building on top of what you have so far, with a bit of modification:

{
  search(first: 100, query: "repo:DSpace/DSpace updated:2018-11-01..2018-12-01 type:pr", type: ISSUE) {
    nodes {
      ... on PullRequest {
        # use part of your original query from here onward
        state
        resourcePath
        comments(last: 100) {
          nodes {
            author {
              login
            }
          }
        }
        reviews(last: 100) {
          nodes {
            author {
              login
            }
          }
        }
      }
    }
  }
}
EricC
  • 1,355
  • 1
  • 20
  • 33