-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LoC(lines of code) tracker #62
Changes from 11 commits
f551f61
6638e1d
8acb0ed
5ea57fc
6f011e0
747c6a8
3943413
d832b11
3988069
33fae5b
d09425c
42ea9cb
6ec8025
c680e6a
c958ff6
1fed3ba
34b19de
130db5e
2994813
f963d9f
61c66bc
f693c18
588a344
4588621
51cc282
8297b08
23bbdbf
f68874f
7777117
98534ef
a076bdf
7446ba1
708e445
8aae488
7ef9110
ca15bc9
baf94d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
This module calculates the absolute value of lines of code (LoC) changed (added or removed) | ||
in the given Git repository. | ||
""" | ||
|
||
import git | ||
|
||
|
||
def calculate_loc_changes(repo_path: str): | ||
willdavidson05 marked this conversation as resolved.
Show resolved
Hide resolved
willdavidson05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Finds the total number of code lines changed | ||
|
||
Args: | ||
repo_path(str): The path to the git repository | ||
Returns: | ||
int: Total number of lines added or removed | ||
""" | ||
repo = git.Repo(repo_path) | ||
|
||
total_lines_changed = 0 | ||
willdavidson05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for commit in repo.iter_commits(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to tie in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the idea Dave! I was able to implement |
||
# Retrieve commit statistics | ||
diff_stat = commit.stats.total | ||
total_lines_changed += diff_stat["lines"] | ||
return total_lines_changed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Testing LoC_tracker functionality for calculating total lines changed in a given repository. | ||
""" | ||
|
||
import pathlib | ||
|
||
from almanack.LoC_tracker import calculate_loc_changes | ||
|
||
|
||
def test_calculate_loc_changes(repository_paths: dict[str, pathlib.Path]): | ||
# repository_paths.items() returns a dictionary | ||
for _, repo_path in repository_paths.items(): | ||
# Check that the changes are non-negative for each repository | ||
assert calculate_loc_changes(repo_path) > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider generalizing the name for this module to help invite further work where / when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do! I have been thinking about a new name, and the best I have is
code_tracker.py
. Let me know what you think of this! I'm not sure how I feel about it yet.