Getting single file history

schema-request

#1

Hey guys!

I am in the process of writing a query that will return a list of contributors to a single file, however currently I can only find a way to retrieve a list of all commits. One day I might have thousands of commits so It could cause this query to be a pain to manage. Also I want to move the query close to the resource that uses it, of which If I did the entire repo commit history query for hundereds of files I could easily reach the rate limiter. Basically, is there a way to query a single file and get it’s history without waisting resources on unrelated queries.

Here’s my current query

query repositoryQuery($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    object(expression: "master") {
      ... on Commit {
        history(first: 100){
          nodes {
            message
            author {
              user {
                avatarUrl
                login
                url
              }
            }
          }
        }
      }
    }
  }
}

#2

hi @falconmick

If you know the path of the particular file then you can just add that in the history query to get the commits of a particular file:

query repositoryQuery($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    object(expression: "master") {
      ... on Commit {
        history(first: 100, path: "README.md") {
          nodes {
            resourcePath
            message
            author {
              user {
                avatarUrl
                login
                url
              }
            }
          }
        }
      }
    }
  }
}

#3

Cheers that was exactly what I was looking for!