Get all file names from a Github repo through the Github API

后端 未结 4 1307
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 01:02

Is it possible to get all the file names from repository using the GitHub API?

I\'m currently trying to tinker this using PyGithub, but I\'m totally ok with manually

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 02:00

    You can use Github git trees

    https://api.github.com/repos/[USER]/[REPO]/git/trees/[BRANCH]?recursive=1

    Repo

    https://github.com/deeja/bing-maps-loader

    Api Call

    https://api.github.com/repos/deeja/bing-maps-loader/git/trees/master?recursive=1

    which returns

    {
    sha: "55382e87889ccb4c173bc99a42cc738358fc253a",
    url: "https://api.github.com/repos/deeja/bing-maps-loader/git/trees/55382e87889ccb4c173bc99a42cc738358fc253a",
    tree: [
    {
    path: "README.md",
    mode: "100644",
    type: "blob",
    sha: "41ceefc1262bb80a25529342ee3ec2ec7add7063",
    size: 3196,
    url: "https://api.github.com/repos/deeja/bing-maps-loader/git/blobs/41ceefc1262bb80a25529342ee3ec2ec7add7063"
    },
    {
    path: "index.js",
    mode: "100644",
    type: "blob",
    sha: "a81c94f70d1ca2a0df02bae36eb2aa920c7fb20e",
    size: 1581,
    url: "https://api.github.com/repos/deeja/bing-maps-loader/git/blobs/a81c94f70d1ca2a0df02bae36eb2aa920c7fb20e"
    },
    {
    path: "package.json",
    mode: "100644",
    type: "blob",
    sha: "45f24dcb7a457b14fede4cb907e957600882b340",
    size: 595,
    url: "https://api.github.com/repos/deeja/bing-maps-loader/git/blobs/45f24dcb7a457b14fede4cb907e957600882b340"
    }
    ],
    truncated: false
    }
    

提交回复
热议问题