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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners