1

I am trying to get a count of files that have been changed for a given date range (monthly report).

I am able to get a commit count pretty easily with GitHub's API V4. I modified that query to also get a count of changed files in each commit and I figured I could aggregate them manually. This works with small volumes. For reference, here is the query I am using:

query ($owner: String!, $name: String!, $pagedEndCursor: String, $sinceTS: GitTimestamp!, $untilTS: GitTimestamp!) {
  repository(owner: $owner, name: $name) {
    refs(first: 100, refPrefix: "refs/heads/", after: $pagedEndCursor, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
      totalCount
      edges {
        node {
          name
          target {
            ... on Commit {
              history(first: 100, since: $sinceTS, until: $untilTS) {
                totalCount
                nodes {
                  changedFiles
                  committedDate
                }
                pageInfo{
                  hasNextPage
                }
              }
            }
          }
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

The problem I am facing is that our teams make extensive use of branches, so we have many repositories that have over 100 branches, which is why I built in paging when going through the branches. While the chance of 100 branches having commits within a given month are slim, it is certainly possible that a single branch could have over 100 commits in a given month.

I thought to do paging within the history (I left the innermost pageInfo to show where), but I don't think it would work to page across multiple inner objects.

I could do it in multiple passes, where I run the query to get the list of branches that have changes in the given month, and then run a separate query for each of those branches to get the changed file count, but that seems to defeat the purpose of using GraphQL.

Are there any other ways to get the changed file count for a date range across all branches of a repository?

BrianH
  • 7,932
  • 10
  • 50
  • 71

0 Answers0