finding when a file was introduced on github

Viewed 50
2 Answers

You can use https://api.github.com/repos/OWNER/REPO/commits?path=<path/to/file>, as described here.

The results of this request can then be parsed by jq, with the following options .[-1].commit.author.date.
This tells jq to get the last item of the array ([-1]), and then parse the value of commit, then author and then the date, which is the date of the commit.

So using the follwing command

curl "https://api.github.com/repos/RaRe-Technologies/gensim/commits?path=gensim/scripts/make_wikicor
pus.py" | jq -r ".[-1].commit.author.date"

will result in

2012-07-21T20:00:29Z

The alternative, using GitHub CLI gh, and its gh api command:

# Windows
gh api -X GET repos/RaRe-Technologies/gensim/commits \
       -f path="gensim/scripts/make_wikicorpus.py" \
       --jq ".[-1].commit.author.date"

# Linux
gh api -X GET repos/RaRe-Technologies/gensim/commits \
       -f path='gensim/scripts/make_wikicorpus.py' \
       --jq '.[-1].commit.author.date'

2012-07-21T20:00:29Z

You don't even need jq if you have gh installed.

Related