Skip to content
Snippets Groups Projects
Commit 2849e2fd authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Commit format sniffer now reports across all branches

parent 02c5b870
No related branches found
No related tags found
No related merge requests found
......@@ -250,6 +250,9 @@ class GitlabCommit:
def is_merge(self) -> bool:
return len(self.git_commit.parent_ids) > 1
def is_revert(self) -> bool:
return self.get_message().startswith('Revert')
def get_id(self) -> str:
return self.git_commit.id
......@@ -659,6 +662,12 @@ class GitlabProject:
commits.append(GitlabCommit(commit))
return commits
def get_branch_names(self) -> List[str]:
branches = self.git_project.branches.list()
branch_names: List[str] = list(map(lambda b: b.name, branches))
return branch_names
def get_labels(self) -> Set[str]:
"""
:return: set of label names
......
from api.gitlab_classes import *
from course import Course
if __name__ == '__main__':
projects = GitlabProject.get_projects_by_group(Course.gitlab_namespace)
projects = list(filter(lambda p: p.get_name().startswith('30pair'), projects))
projects.sort(key=lambda p: p.get_name())
for project in projects:
commits = project.get_commits()
print(f'\n\n. >>>> {project} <<<<')
print(f'{len(commits)} commits on the master branch')
# noinspection PyShadowingNames
def judge_commits(commits: List[GitlabCommit]):
merges = 0
reverts = 0
well_formatted_commits = 0
......@@ -16,14 +11,34 @@ if __name__ == '__main__':
for commit in commits:
if commit.is_merge():
merges += 1
elif commit.get_message().startswith('Revert'):
elif commit.is_revert():
reverts += 1
elif commit.is_well_formatted():
well_formatted_commits += 1
else:
malformatted_commits.append(commit)
print(
f'{merges} merges, {reverts} reverts, {well_formatted_commits} well-formatted commits, '
f'\t\t{merges} merges, {reverts} reverts, {well_formatted_commits} well-formatted commits, '
f'and {len(malformatted_commits)} malformatted commits')
for commit in malformatted_commits:
print(f'{commit.detail_formatting_problems()} ({commit.get_author()})')
print(f'\t\t{commit.get_timestamp()} {commit.detail_formatting_problems()} ({commit.get_author()["name"]})')
if __name__ == '__main__':
projects = GitlabProject.get_projects_by_group(Course.gitlab_namespace)
# projects = list(filter(lambda p: p.get_name().startswith('30pair'), projects))
projects = list(filter(lambda p: p.get_name().startswith('36team'), projects)) # TODO: soft-code prefix
projects.sort(key=lambda p: p.get_name())
for project in projects:
print(f'\n\n\t>>>> {project} <<<<')
master_branch_commits = project.get_commits()
print(f'{len(master_branch_commits)} commits on the master branch')
all_branches_commits: Set[GitlabCommit] = set()
for branch in project.get_branch_names():
for commit in project.get_commits(branch):
all_branches_commits.add(commit)
print(f'{len(all_branches_commits)} commits among all branches')
print('\tOn the master branch:')
judge_commits(master_branch_commits)
print('\tOn all other branches:')
judge_commits(list(sorted(all_branches_commits - set(master_branch_commits), key=lambda c: c.get_timestamp())))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment