Category: PHP, api, javascript

While building https://www.amitmerchant.com/your-first-commit-ever/, I needed to retrieve the oldest commit of a GitHub user. This endpoint along with a few filters through the query parameters would return a response consisting of the oldest 30 commits.

As you can tell, the first query parameter q with author targets the specific GitHub user for whom you want to retrieve the commits.

function fetchUserCommits(user) { $.ajax({ url: "https://api.github.com/search/commits?q=author:" + user + "&order=asc&sort=committer-date", type: "get", headers: { 'Accept': 'application/vnd.github.cloak-preview' }, dataType: 'json', success: function (data) { console.log(data); }, error: function () { console.log('No GitHub user is available of this username.'); }}); }

And from here, you can pick the oldest commit by using data.items and retrieve all the important detail about that commit like commit date, commit repository, commit message, and so on.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners