@ -2,8 +2,8 @@
|
|||||||
#-*- coding: utf-8 -*-
|
#-*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import git
|
|
||||||
import re
|
import re
|
||||||
|
import git
|
||||||
|
|
||||||
class Commits:
|
class Commits:
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ class Commits:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self._repository = git.Repo(os.getcwd())
|
self._repository = git.Repo(os.getcwd())
|
||||||
|
|
||||||
self._failed = []
|
self._failed = []
|
||||||
merge_base = self._repository.merge_base('development', self._repository.active_branch)
|
merge_base = self._repository.merge_base('development', self._repository.active_branch)
|
||||||
self._merge_base = str(merge_base[0])
|
self._merge_base = str(merge_base[0])
|
||||||
@ -20,22 +20,22 @@ class Commits:
|
|||||||
|
|
||||||
|
|
||||||
def fetch_all(self) -> bool: # get the commits and filter to only the current branch
|
def fetch_all(self) -> bool: # get the commits and filter to only the current branch
|
||||||
|
|
||||||
commits = list(self._repository.iter_commits(self._repository.active_branch))
|
commits = list(self._repository.iter_commits(self._repository.active_branch))
|
||||||
|
|
||||||
clean = True
|
clean = True
|
||||||
Branch_commits = []
|
branch_commits = []
|
||||||
for remove in commits:
|
for remove in commits:
|
||||||
|
|
||||||
if str(remove).lower() == self._merge_base.lower():
|
if str(remove).lower() == self._merge_base.lower():
|
||||||
|
|
||||||
clean = False
|
clean = False
|
||||||
|
|
||||||
if clean:
|
if clean:
|
||||||
|
|
||||||
Branch_commits.append(remove)
|
branch_commits.append(remove)
|
||||||
|
|
||||||
self._commits = Branch_commits
|
self._commits = branch_commits
|
||||||
|
|
||||||
|
|
||||||
def fetch(self, sha1:str) -> str: # fetch a single git message
|
def fetch(self, sha1:str) -> str: # fetch a single git message
|
||||||
@ -48,64 +48,82 @@ class Commits:
|
|||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
# Get the last line of the commit message if has more than 2 lines
|
||||||
def footer(self, git_message:str) -> list: # Get the last line of the commit message if has more than 2 lines
|
def footer(self, git_message:str) -> list:
|
||||||
|
footer = None
|
||||||
|
|
||||||
if git_message.count("\n") > 2:
|
if git_message.count("\n") > 2:
|
||||||
|
|
||||||
footer_line = git_message.split("\n")
|
footer_line = git_message.split("\n")
|
||||||
footer_line = footer_line[(len(footer_line)-1)]
|
footer_line = footer_line[(len(footer_line)-1)]
|
||||||
|
|
||||||
footer = re.findall(r"([\!|\#][0-9]+)", str(git_message))
|
commit_footer = re.findall(r"([\!|\#][0-9]+)", str(git_message))
|
||||||
|
|
||||||
if len(footer) > 0:
|
if len(footer) > 0:
|
||||||
return footer
|
footer = commit_footer
|
||||||
else:
|
else:
|
||||||
return False
|
footer = False
|
||||||
|
|
||||||
return None
|
return footer
|
||||||
|
|
||||||
|
|
||||||
def junit(self) -> bool:
|
def junit(self) -> bool:
|
||||||
junit = False
|
|
||||||
|
|
||||||
junit_testsuites = '<testsuites id="Commits Messages Check" name="commit footer references" errors="{0}" tests="{1}" time="0">'.format(len(self._failed), len(self._commits))
|
junit_testsuites = '''<testsuites
|
||||||
junit_testsuite = '<testsuite errors="{0}" name="commit footer references" tests="{1}">'.format(len(self._failed), len(self._commits))
|
id="Commits Messages Check"
|
||||||
|
name="commit footer references"
|
||||||
|
errors="{0}"
|
||||||
|
tests="{1}"
|
||||||
|
time="0">'''.format(len(self._failed), len(self._commits))
|
||||||
|
|
||||||
|
junit_testsuite = '''<testsuite
|
||||||
|
errors="{0}"
|
||||||
|
name="commit footer references"
|
||||||
|
tests="{1}">'''.format(len(self._failed), len(self._commits))
|
||||||
|
|
||||||
junit_testcase = ''
|
junit_testcase = ''
|
||||||
for commit in self._failed:
|
for commit in self._failed:
|
||||||
for key in commit:
|
for key in commit:
|
||||||
junit_testcase += '''
|
junit_testcase += '''
|
||||||
<testcase classname="{0}" file="{2}/gitlab_release/README.md" line="0" name="No commit footer references found" time="0" timestamp="date">
|
<testcase
|
||||||
<failure message="No References in the commit footer" type="validation">{1}</failure>
|
classname="{0}"
|
||||||
|
file="{2}/gitlab_release/README.md"
|
||||||
|
line="0"
|
||||||
|
name="No commit footer references found"
|
||||||
|
time="0"
|
||||||
|
timestamp="date">
|
||||||
|
<failure
|
||||||
|
message="No References in the commit footer"
|
||||||
|
type="validation">{1}</failure>
|
||||||
<system-out>
|
<system-out>
|
||||||
<![CDATA[ {1} ]]>
|
<![CDATA[ {1} ]]>
|
||||||
</system-out>
|
</system-out>
|
||||||
<system-err>
|
<system-err>
|
||||||
<![CDATA[ {1} ]]>
|
<![CDATA[ {1} ]]>
|
||||||
</system-err>
|
</system-err>
|
||||||
</testcase>'''.format(key, str(commit[key], os.environ['ROOT_DIR']))
|
</testcase>'''.format(key, str(commit[key]), os.environ['ROOT_DIR'])
|
||||||
|
|
||||||
|
|
||||||
if junit_testcase == '':
|
if junit_testcase == '':
|
||||||
junit_testcase = '<testcase classname="Commit footer references check" file="' + os.environ['ROOT_DIR'] + '/gitlab_release/README.md" name="has commit footer references"/>'
|
junit_testcase = '''<testcase
|
||||||
|
classname="Commit footer references check"
|
||||||
|
file="' + os.environ['ROOT_DIR'] + '/gitlab_release/README.md"
|
||||||
|
name="has commit footer references"/>'''
|
||||||
|
|
||||||
junit_close = '</testsuite></testsuites>'
|
junit_close = '</testsuite></testsuites>'
|
||||||
print(str(junit_testsuites))
|
print(str(junit_testsuites))
|
||||||
print(str(junit_testsuite))
|
print(str(junit_testsuite))
|
||||||
print(str(junit_testcase))
|
print(str(junit_testcase))
|
||||||
print(str(junit_close))
|
print(str(junit_close))
|
||||||
|
|
||||||
|
|
||||||
def check(self) -> bool:
|
def check(self) -> bool:
|
||||||
check = True
|
check = True
|
||||||
|
|
||||||
start_check = False
|
|
||||||
|
|
||||||
for commit in self._commits:
|
for commit in self._commits:
|
||||||
|
|
||||||
if commit.message.count('\n') < 3:
|
if commit.message.count('\n') < 3:
|
||||||
continue
|
continue
|
||||||
footer = self.footer(commit.message)
|
footer = self.footer(commit.message)
|
||||||
|
|
||||||
if footer is False:
|
if footer is False:
|
||||||
@ -119,5 +137,3 @@ class Commits:
|
|||||||
check = False
|
check = False
|
||||||
|
|
||||||
return check
|
return check
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user