Home > other >  How do I get file names from a directory in a repository using Github API
How do I get file names from a directory in a repository using Github API

Time:02-02

I'm trying to make an electron app that gets the file names of a directory in a repository. I just don't know how to do this with the api. I know there is a way, I just don't know how.

For example:

I want to get the file names in the src/ directory of a github repository using the api.

I use axios to make api requests.

CodePudding user response:

Use Get repository content endpoint, documented here

Check out an example using Octokit

List Repository contents                                                                                 View in Fusebit
// If you don't send the path property, by default will send the contents from the root level
const repoContent = await github.rest.repos.getContent({
  owner: 'repo-owner',
  repo: 'repo-name'
});
  
console.log('Files found at root level', repoContent.data.map((file) => file.name));

  •  Tags:  
  • Related