Skip to content
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

Gc/python module refacto #5

Merged
merged 7 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM python:3.9-slim-buster
ADD git-quality-check.py /
ADD git_quality_check /git_quality_check
ADD example /example
ADD setup.py /
ADD README.md /

# RUN pip install pystrich

RUN apt-get upgrade -y
RUN apt-get update
RUN apt-get -y install software-properties-common
RUN apt-get upgrade -y
RUN apt-get update
RUN apt-add-repository ppa:git-core/ppa -y
RUN apt-get -y install git
ENTRYPOINT [ "python", "/git-quality-check.py" ]

RUN python setup.py develop

ENTRYPOINT [ "python", "/example/git-quality-check.py" ]
50 changes: 50 additions & 0 deletions example/git-quality-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from git_quality_check.utils import (
git_logs,
git_all_branches,
set_output,
format_number,
parse_inputs,
)

from git_quality_check.indicators.counters import (
count_old_branches,
count_coupled,
process_logs,
)


from git_quality_check.indicators.commits import (
is_empty_body,
not_a_squashed_commit,
count_bad_words,
is_test_commit,
)

from git_quality_check.scoring import compute_score


if __name__ == "__main__":

bad_words, main_branches = parse_inputs()

logs = git_logs()
branches = git_all_branches()

bad_commit_index = process_logs(
logs, [not_a_squashed_commit, is_empty_body, count_bad_words(bad_words)]
)
test_index = process_logs(logs, [is_test_commit])

old_branches_index = count_old_branches(branches)
coupling_index = count_coupled(branches, main_branches)

print(bad_commit_index)
print(test_index)
print(old_branches_index)
print(coupling_index)

overall = compute_score(
bad_commit_index, test_index, old_branches_index, coupling_index
)

set_output(format_number(overall))
220 changes: 0 additions & 220 deletions git-quality-check.py

This file was deleted.

Empty file added git_quality_check/__init__.py
Empty file.
1 change: 1 addition & 0 deletions git_quality_check/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "v0.0-beta"
4 changes: 4 additions & 0 deletions git_quality_check/indicators/commits/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .is_empty_body import is_empty_body
from .not_a_squashed_commit import not_a_squashed_commit
from .count_bad_words import count_bad_words
from .is_test_commit import is_test_commit
9 changes: 9 additions & 0 deletions git_quality_check/indicators/commits/count_bad_words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def count_bad_words(bad_words: list[str]):
def _count_bad_words(log: str):
counter = 0
for word in bad_words:
if word in log.lower().split():
counter += 1
return counter

return _count_bad_words
13 changes: 13 additions & 0 deletions git_quality_check/indicators/commits/is_empty_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from git_quality_check.utils import (
is_valid_log,
remove_header,
)


def is_empty_body(log: str):
if not is_valid_log(log):
return 1
log = remove_header(log)
if not is_valid_log(log):
return 1
return 0
5 changes: 5 additions & 0 deletions git_quality_check/indicators/commits/is_test_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def is_test_commit(log: str):
for word in ["test", "testing"]:
if word in log.lower().split():
return 1
return 0
4 changes: 4 additions & 0 deletions git_quality_check/indicators/commits/not_a_squashed_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def not_a_squashed_commit(log: str):
if "(#" not in log:
return 1
return 0
3 changes: 3 additions & 0 deletions git_quality_check/indicators/counters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .count_old_branches import count_old_branches
from .count_coupled import count_coupled
from .process_logs import process_logs
12 changes: 12 additions & 0 deletions git_quality_check/indicators/counters/count_coupled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from git_quality_check.utils import sample, are_coupled


def count_coupled(branches, main_branches):
branches, count = sample(branches, 10)
branches.extend(main_branches)
count += len(main_branches)
counter = 0
for bA in branches:
for bB in branches:
counter += 1 if are_coupled(bA, bB) else 0
return counter / count * 100
9 changes: 9 additions & 0 deletions git_quality_check/indicators/counters/count_old_branches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from git_quality_check.utils import sample, is_old


def count_old_branches(branches):
counter = 0
branches, count = sample(branches, 10)
for branch in branches:
counter += 1 if is_old(branch) else 0
return counter / count * 100
8 changes: 8 additions & 0 deletions git_quality_check/indicators/counters/process_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def process_logs(logs: list[str], functions: list[str:int]):
counter = 0
count = len(logs) * len(functions)
for i in range(len(logs)):
log = logs[i]
for function in functions:
counter += function(log)
return counter / count * 100
1 change: 1 addition & 0 deletions git_quality_check/scoring/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .overall import compute_score
7 changes: 7 additions & 0 deletions git_quality_check/scoring/overall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def compute_score(bad_commit_index, test_index, old_branches_index, coupling_index):
return (
(100 - bad_commit_index)
+ test_index
+ (100 - old_branches_index)
+ (100 - coupling_index)
) / 4
10 changes: 10 additions & 0 deletions git_quality_check/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .git import (
is_valid_log,
remove_header,
is_old,
are_coupled,
git_logs,
git_all_branches,
)

from .common import sample, set_output, format_number, parse_inputs
Loading