Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

rest - How to use Github V3 API to get commits ahead/behind data for forks that cannot be compared with parent?

I write a Firefox extension to make Github "Forks" page more useful. I need commits ahead/behind data for each fork.

To do so right way, I tried to use Github REST API through jQuery AJAX requests:

const url = `https://api.github.com/repos/${parent_owner}/${repo_name}/compare/${parent_branch}...${child_owner}:${child_branch}`;
console.log(url);
$.ajax({
    url: url,
    async: false,
    headers: {
        Accept: "application/vnd.github.v3+json",
        Authorization: `token ${token}`
    },
    success : function(response) {
        const commits_ahead = response.ahead_by;
        const commits_behind = response.behind_by;
        const status = response.status;
        console.log(`ahead: ${commits_ahead}, behind: ${commits_behind}, status: ${status}`);
        },
    error : function(jqXHR, textStatus, errorThrown){
        console.log(errorThrown);
    }
});

But Github shows commits ahead/behind data on fork repos that cannot be compared to parent, for example: https://github.com/1292765944/tensorflow

Is there another way to get such data through Github REST API?

question from:https://stackoverflow.com/questions/65651776/how-to-use-github-v3-api-to-get-commits-ahead-behind-data-for-forks-that-cannot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...