Date:

Share:

How to Retrieve The Oldest Commit of a GitHub User – Amit Merchant – A blog on PHP, JavaScript, and more

Related Articles

While building your first ever Commit, I had to retrieve the oldest GitHub user commit. After a few google searches, I found a GitHub API An endpoint that can be used to achieve this.

API endpoint

Essentially, there is End point To Search is required For a specific user.

GET / search / commits

This endpoint along with some filters through the query parameters will return a response consisting of the 30 oldest commitments.

This is what the endpoint will look like after applying these filters.

GET / search / commits?That= author: amitmerchant1990 &Order= asc &Type= Commitable date

As you can see, the query parameter first q With author Targets the specific GitHub user for whom you want to retrieve the commitments.

The second and third parameters, order and sort Respectively, sort the liabilities by the date of the obligation in ascending order.

Using the endpoint

This endpoint can then be called a GET request. Here is an excerpt from my app where I read it through jQuery Ajax.

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.');
        
    );

Here’s how the reaction (data) Returned from the API for a valid GitHub user looks like.

Hence, you can select the oldest commit by using data.items[0] And retrieve all the important details about that commit like commit date, commit repository, commit message, and so on.

oldest github commit

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles