Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a primary or a list of languages from github's URL using github API?

I have an url to github repo, for instance: https://github.com/dotnet/corefx

Is there any possible approach in github's API to get "C#" as a primary language of the repository?

like image 444
Vladislav Rudskoy Avatar asked Feb 21 '17 15:02

Vladislav Rudskoy


1 Answers

You can use List languages Github API that will give you all language used in this repo with the number of bytes of code written in that language :

GET https://api.github.com/repos/dotnet/corefx/languages

that will give you :

{
  "C#": 131055040,
  "C": 1078381,
  "Visual Basic": 829607,
  "C++": 622926,
  "XSLT": 462336,
  "OpenEdge ABL": 139178,
  "Shell": 70286,
  "CMake": 60136,
  "PowerShell": 51624,
  "DIGITAL Command Language": 26402,
  "Groovy": 25726,
  "Batchfile": 21796,
  "Objective-C": 9455,
  "Makefile": 9085,
  "Roff": 4236,
  "Perl": 3895,
  "ASP": 1687,
  "Python": 1535,
  "1C Enterprise": 903,
  "HTML": 653
}

With bash you can use jq to parse and select the field with the max bytes value :

language=`curl -s https://api.github.com/repos/dotnet/corefx/languages | jq 'to_entries | max_by(.value) | .key'`
echo "$language"
like image 72
Bertrand Martel Avatar answered Jan 05 '23 06:01

Bertrand Martel