Can you get the number of lines of code from a GitHub repository?

前端 未结 15 1215
庸人自扰
庸人自扰 2020-12-04 04:26

In a GitHub repository you can see “language statistics”, which displays the percentage of the project that’s written in a language. It doesn’t, however, display ho

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 04:56

    You can clone just the latest commit using git clone --depth 1 and then perform your own analysis using Linguist, the same software Github uses. That's the only way I know you're going to get lines of code.

    Another option is to use the API to list the languages the project uses. It doesn't give them in lines but in bytes. For example...

    $ curl https://api.github.com/repos/evalEmpire/perl5i/languages
    {
      "Perl": 274835
    }
    

    Though take that with a grain of salt, that project includes YAML and JSON which the web site acknowledges but the API does not.

    Finally, you can use code search to ask which files match a given language. This example asks which files in perl5i are Perl. https://api.github.com/search/code?q=language:perl+repo:evalEmpire/perl5i. It will not give you lines, and you have to ask for the file size separately using the returned url for each file.

提交回复
热议问题