0

Is there any way to get the total number of files & the total number of lines of code from *github.Repository.

There is a Go package that helps explore git in Go code. The Repository class in which we are speaking is here.

As per this documentation, looks like there is no direct way to get the total number of files or a total number of lines of code.

Any expert who can shed light on this or a workaround for this?

I got to know about 'total_count' field in the response schema but that is just the total count of the results returned. Not related to what we are speaking here. Cloc is probably another option but it would create a dependency to maintain this.

9
  • This has been asked before: stackoverflow.com/questions/26881441/… Commented Feb 9, 2024 at 9:05
  • Another option would be to iterate the files via the API and count files and LOC in Go. Not sure how performant that is. Would need some parallelization, but beware of potential github API limits. stackoverflow.com/questions/25022016/… Commented Feb 9, 2024 at 9:19
  • Please note that you should only use a particular programming language tag if you have a practical problem to solve in that language. The fact you're using some ready-made package written in that language to perform some abstract task is not relevant to problems you might have achieving that abstract task. I mean, you could as well use a github web API wrapper written in Python, Ruby, Perl, FroBozz and so on. This question is about particularities of that web API, not programming in Go. Hope this helps. Commented Feb 9, 2024 at 10:09
  • Also consider searching Github discussions and start another one, if relevant. Commented Feb 9, 2024 at 10:16
  • @kostix, You are probably right that this question is not about the language itself. However, it is probably fair to tag 'go' since the code itself is in go language including the user code & the package code. Isn't it? Commented Feb 9, 2024 at 11:05

1 Answer 1

0

It's not a question about go language.

It's a shell question.

I would do in zsh:

$ git clone [your repo]
$ print -l **/*.go |wc -l # number of files
$ cat **/*.go | wc -l # number of lines
Sign up to request clarification or add additional context in comments.

2 Comments

That seems what people revert to mostly. Still it means the repository first must be cloned locally. The question wants to know how to get the information via the github API.
@TehSphinX, Yes, You are right. The question is about getting the count through the github API's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.