Skip to content

Get content of random file for given language? #24597

Discussion options

You must be logged in to vote

Hey, thanks again for your help! I ended up using the search API to find the files as well. So my sequence is:

  1. Get a repository list from api.github.com/search/repositories?q=language:${codeLanguage}&sort=stars&order=desc
  2. Get a file list from api.github.com/search/code?q=%20+language:${codeLanguage}+repo:${repoName}
  3. Get file contents using URLs provided by step 2 (which use the repo contents API you showed me)

This way I don’t have to crawl the Git tree to find files and can keep API requests few. The search also handles finding files by language even when the files may have one of multiple extensions (JavaScript has many).

One weird thing is that the Search API requires a string to s…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment