Get all files created within a date range

Hello all,

Could anyone advise on a query or process to get a list of commits or pull requests that committed a new file to a repository within a given date range?

Using the REST API I’ve been able to search for PRs within a date range based on a number of criteria like author, label, etc (python code snippet):

def get_author_query(author, owner, repo, begin_date, end_date):
    author_prs = 'https://api.github.com/search/issues?q=repo:{}/{} type:pr author:{} is:merged merged:{}..{}'.format(owner, repo, author, begin_date, end_date)
    return author_prs

def get_label_query(label, owner, repo, begin_date, end_date):
    label_prs = 'https://api.github.com/search/issues?q=repo:{}/{} type:pr label:{} is:merged merged:{}..{}'.format(owner, repo, label, begin_date, end_date)
    return label_prs

And I’ve used the GraphQL API to get detailed data about PRs (python code snippet):

pr_files_query = """{repository(owner:"%s", name: "%s") {
            pullRequest(number: %d){
                author{login}
                url
                title
                bodyText
                createdAt
                additions
                changedFiles
                state
                publishedAt
                number
                commits(first: 10)
                {
                edges{
                  node{
                    id
                    commit
                    {
                      changedFiles
                    }
                  }
                }
                }
                files(last: 100){
                edges{
                  node{
                    path
                    additions
                    deletions
                  }
                }
                }
            }
          }
        }
        """ % (owner, repo, int(pr_number))

Is there a property in one of the APIs that shows if this is the first commit on a file? Is there an easy way to tell if this is the first commit on a given file?

Thanks

There isn’t anything in the API that quickly and easily identifies if a given commit is the one that creates a file, no. You could use the list commits on a repository REST endpoint to find the commits that touch a particular file and paginate to the end to find the oldest one, though.

I hope that helps!