user18075453
user18075453

Reputation:

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

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.

Upvotes: 6

Views: 1637

Answers (1)

Ruben Restrepo
Ruben Restrepo

Reputation: 1196

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));

Upvotes: 4

Related Questions