GraphQL - Get all commits by all users in all orgs with filtered date

Hi,

  I have the following query which returns all the commit history for the given org. 

Questions 1:-

  1. Not sure, How to filter commits history by date

  2. Here, I pass orgName. How to get across all orgs?

    {
    search(query: “org:test”, type: REPOSITORY, last: 100) {
    edges {
    node {
    … on Repository {
    name
    defaultBranchRef {
    name
    target {
    … on Commit {
    history(first: 100) {
    edges {
    node {
    … on Commit {
    committedDate
    additions
    author {
    name
    email
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }

You can filter commit history by date using the since or until parameter to the history connection on Commit:

{
  search(query: "org:test", type: REPOSITORY, last: 100) {
    nodes {
      ... on Repository {
        name
        defaultBranchRef {
          name
          target {
            ... on Commit {
              history(first: 100, since: "2013-07-11T00:00:00") {
                totalCount
                nodes {
                  ... on Commit {
                    committedDate
                    additions
                    author {
                      name
                      email
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

As for getting all orgs, there isn’t currently a way to do that via the GraphQL API because the search connection requires something in the search query. There’s also no top-level connection that allows you to list all users, orgs, or repositories.

I hope that helps!

1 Like