1

Can someone explain me or give some tutorial to get all the commit details for a particular in github. I saw this and I didn't understand how to use that.

1 Answer 1

3

You can check my article about this:
http://ondrek.me/articles/how-to-parse-github-API-in-nodejs/

This is NodeJs way
(for client js change require("https") to client ajax JSON - code is very simular)

Quick sample link for repo MDOWN of user ONDREK
https://api.github.com/repos/ondrek/mdown/git/refs/heads/

How to make a request to Github API

var options = {
    user : 'ondrek',
    repo : 'favicon-blog',
    branch : 'master'
};

function getHttpRequestJson(customPath, callback){
    require('https').request({
        hostname: 'api.github.com',
        path: customPath,
        method: 'GET'
    }, function(res){
        var data = '';
        res.on('data', function (chunk) {
            data += chunk;
        });
        res.on('end', function () {
            callback(JSON.parse(data));
        });
    }).end();
}

How to get user details json from Github API

(inject previous code)

var url = '/repos/'+options.user+'/'+options.repo+'/git/refs/heads/'+options.branch;
getHttpRequestJson(url, function(userJson){
    var lastCommitUrl = userJson.object.url;
    getLastCommit(lastCommitUrl);
});

How to get last commit json from Github API

(inject previous code)

function getLastCommit(url){
    getHttpRequestJson(url+auth, function(lastCommitJson){
        var treeUrl = lastCommitJson.tree.url;
        getTree(treeUrl);
    });
}

How to get tree of last commit from Github API

(inject previous code)

function getTree(url){
    getHttpRequestJson(url+auth, function(treeJson){
        var treeArr = treeJson.tree;
        getOnlyPages(treeArr);
    });
}

How to get specific folder of last commit from Github API

(inject previous code)

function getOnlyPages(treeArr){
    treeArr.forEach(function(ele){
        if (ele.path==='blog') { getArticles(ele.url); }
    });
}

function getArticles(url){
    getHttpRequestJson(url+auth, function(treeJson){
        var treeArr = treeJson;
        parseMarkdownArticles(treeArr.tree);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.