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

2

18

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?

Mccartan answered 21/2, 2017 at 15:34 Comment(0)
D
24

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"
Dutra answered 21/2, 2017 at 16:34 Comment(0)
S
3

Update for 2023

you can find the docs for the list of languages here

GET https://api.github.com/repos/microsoft/vscode/languages

and you can also find the most used language in the repo if you do a normal repo request under the language property

GET https://api.github.com/repos/microsoft/vscode
Sorrento answered 18/5, 2023 at 1:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.