0
commit = repo.get_commit(sha="0adf369fda5c2d4231881d66e3bc0bd12fb86c9a")
print(commit.stats.total)
i = commit.files[0].filename

I can get the filename, even the file sha; but can't seem to get loc of the file. Any pointers?

Karthik Nayak
  • 731
  • 3
  • 14
  • When you say lines of code, do you mean including documentation (e.g., docstrings) or only executable lines of code? – astrochun Mar 15 '21 at 20:48

1 Answers1

0

So let's see this line

commit = repo.get_commit(sha="0adf369fda5c2d4231881d66e3bc0bd12fb86c9a")

Here the commit is of type github.Commit.Commit

Now when you pick a file, it's of the type github.File.File

If you checked that, you'll see that there is no real way of getting lines of code directly. But there is one important field raw_url.

This will give you the raw_url of the file, which you can now get, perhaps like

url = commit.files[0].raw_url
r = requests.get(url)
r.text

This will give you the raw data of the file and you can use it to get the number of lines of code.

Karthik Nayak
  • 731
  • 3
  • 14