如何使用github API从github的URL获取主要语言或语言列表?

问题描述 投票:3回答:1

我有一个github repo网址,例如:https://github.com/dotnet/corefx

在github的API中是否有任何可能的方法来将“C#”作为存储库的主要语言?

api github github-api
1个回答
4
投票

您可以使用List languages Github API,它将为您提供此repo中使用的所有语言,以及使用该语言编写的代码字节数:

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

那会给你:

{
  "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
}

使用bash,您可以使用jq来解析并选择具有最大字节值的字段:

language=`curl -s https://api.github.com/repos/dotnet/corefx/languages | jq 'to_entries | max_by(.value) | .key'`
echo "$language"
© www.soinside.com 2019 - 2024. All rights reserved.