xgqfrms-GitHub / Node-CLI-Tools

一个 Node.js CLI 工具,查看指定 git 仓库的 commit history ; 能对 commit history 进行搜索; 能查看指定时间范围的 commit history.
https://node-cli-tools.xgqfrms.xyz
MIT License
6 stars 2 forks source link

github repos commits #6

Open xgqfrms-GitHub opened 7 years ago

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/repos/commits/


let username = `xgqfrms-GitHub`;
     repo = `Node-CLI-Tools`;

fetch(`https://api.github.com/repos/${username}/${repo}/commits`,{
    data: {
        client_id: '08ecc2f68d922f18800e',
        client_secret: '5846d428b5340812b76c9637eceaee979340b922'
    }
})
.then((response) => response.json())
.then((json)=> {
    console.log(`json = ${json}`);
    return repos = json;
})
.then((repos)=>{
    console.log(`repos = ${repos}`);
    console.log(`repos = ${repos.length}`);
    for (let i = 0; i < repos.length; i++) {
        console.log(`repos${i}  = ${repos[i].commit.message}`);
    }
});
xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/git/commits/

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/gists/comments/

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/

Accept: application/vnd.github.v3+json

xgqfrms-GitHub commented 7 years ago

view-the-change-history-of-a-file-using-github-com/

https://stackoverflow.com/questions/17888643/view-the-change-history-of-a-file-using-github-com/44485982#44485982

xgqfrms-GitHub commented 7 years ago

https://help.github.com/desktop/guides/contributing/viewing-an-individual-commit/

xgqfrms-GitHub commented 7 years ago

https://help.github.com/articles/differences-between-commit-views/ https://help.github.com/desktop/guides/contributing/viewing-an-individual-commit/

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/repos/

xgqfrms-GitHub commented 7 years ago

https://developer.github.com/v3/users/

xgqfrms-GitHub commented 7 years ago

commits json

[
{
    "sha":"c66c9a9b21b1799cc0d069982a0ff0971ea2d8e3",
    "commit":{
        "author":{
            "name":"anonymous",
            "email":"xgqfrms@gmail.com",
            "date":"2017-06-11T15:28:34Z"
        },
        "committer":{
            "name":"GitHub",
            "email":"noreply@github.com",
            "date":"2017-06-11T15:28:34Z"
        },
        "message":"backup",
        "tree":{
            "sha":"f9bf73ffcb5911499b989b31a386dac75d24cb96",
            "url":"https://api.github.com/repos/xgqfrms-GitHub/Node-CLI-Tools/git/trees/f9bf73ffcb5911499b989b31a386dac75d24cb96"
        },
        "url":"https://api.github.com/repos/xgqfrms-GitHub/Node-CLI-Tools/git/commits/c66c9a9b21b1799cc0d069982a0ff0971ea2d8e3",
        "comment_count":0
    },
    "url":"https://api.github.com/repos/xgqfrms-GitHub/Node-CLI-Tools/commits/c66c9a9b21b1799cc0d069982a0ff0971ea2d8e3",
    "html_url":"https://github.com/xgqfrms-GitHub/Node-CLI-Tools/commit/c66c9a9b21b1799cc0d069982a0ff0971ea2d8e3",
    "comments_url":"https://api.github.com/repos/xgqfrms-GitHub/Node-CLI-Tools/commits/c66c9a9b21b1799cc0d069982a0ff0971ea2d8e3/comments",
    "author":{
        "login":"xgqfrms-GitHub",
        "id":18028768,
        "avatar_url":"https://avatars0.githubusercontent.com/u/18028768?v=3",
        "gravatar_id":"",
        "url":"https://api.github.com/users/xgqfrms-GitHub",
        "html_url":"https://github.com/xgqfrms-GitHub",
        "followers_url":"https://api.github.com/users/xgqfrms-GitHub/followers",
        "following_url":"https://api.github.com/users/xgqfrms-GitHub/following{/other_user}",
        "gists_url":"https://api.github.com/users/xgqfrms-GitHub/gists{/gist_id}",
        "starred_url":"https://api.github.com/users/xgqfrms-GitHub/starred{/owner}{/repo}",
        "subscriptions_url":"https://api.github.com/users/xgqfrms-GitHub/subscriptions",
        "organizations_url":"https://api.github.com/users/xgqfrms-GitHub/orgs",
        "repos_url":"https://api.github.com/users/xgqfrms-GitHub/repos",
        "events_url":"https://api.github.com/users/xgqfrms-GitHub/events{/privacy}",
        "received_events_url":"https://api.github.com/users/xgqfrms-GitHub/received_events",
        "type":"User",
        "site_admin":false
    },
    "committer":{
        "login":"web-flow",
        "id":19864447,
        "avatar_url":"https://avatars0.githubusercontent.com/u/19864447?v=3",
        "gravatar_id":"",
        "url":"https://api.github.com/users/web-flow",
        "html_url":"https://github.com/web-flow",
        "followers_url":"https://api.github.com/users/web-flow/followers",
        "following_url":"https://api.github.com/users/web-flow/following{/other_user}",
        "gists_url":"https://api.github.com/users/web-flow/gists{/gist_id}",
        "starred_url":"https://api.github.com/users/web-flow/starred{/owner}{/repo}",
        "subscriptions_url":"https://api.github.com/users/web-flow/subscriptions",
        "organizations_url":"https://api.github.com/users/web-flow/orgs",
        "repos_url":"https://api.github.com/users/web-flow/repos",
        "events_url":"https://api.github.com/users/web-flow/events{/privacy}",
        "received_events_url":"https://api.github.com/users/web-flow/received_events",
        "type":"User",
        "site_admin":false
    },
    "parents":[
        {
            "sha":"02ec87944cbb16270ef307110731f3f63d0d970d",
            "url":"https://api.github.com/repos/xgqfrms-GitHub/Node-CLI-Tools/commits/02ec87944cbb16270ef307110731f3f63d0d970d",
            "html_url":"https://github.com/xgqfrms-GitHub/Node-CLI-Tools/commit/02ec87944cbb16270ef307110731f3f63d0d970d"
        }
    ]
}
]
xgqfrms-GitHub commented 7 years ago

OK demo

const colors = require('colors');
const fetch = require('node-fetch');

let username = process.argv[2] ? process.argv[2] : `xgqfrms-GitHub`;
    repo = process.argv[3] ? process.argv[3] : `Node-CLI-Tools`;

fetch(`https://api.github.com/repos/${username}/${repo}/commits`,{
    data: {
        client_id: '08ecc2f68d922f18800e',
        client_secret: '5846d428b5340812b76c9637eceaee979340b922'
    }
})
.then((response) => response.json())
.then((json)=> {
    console.log(`json = ${json}`);
    return repos = json;
})
.then((repos)=>{
    console.log(`repos = ${repos}`);
    console.log(`repos = ${repos.length}`);
    for (let i = 0; i < repos.length; i++) {
        console.log(`\n\nrepos${i}\n`);
        console.log(`${i} sha = ${repos[i].sha}`);
        console.log(`${i} url = ${repos[i].url}`);
        console.log(`${i} login = ${repos[i].author.login}`);
        console.log(`${i} avatar_url = ${repos[i].author.avatar_url}`);
        console.log(`${i} commit.message = ${repos[i].commit.message}`);
        console.log(`${i} url = ${repos[i].commit.url}`);
        console.log(`${i} date = ${repos[i].commit.author.date}`);
        console.log(`${i} name = ${repos[i].commit.author.name}`);
    }
});