Skip to content

Commit 2280909

Browse files
authored
Merge pull request #29 from ccdc-opensource/remove-opensource-jira
Remove the requirement for jira in opensource
2 parents bfe2d06 + 7b3b9fb commit 2280909

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

main/githooks.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def get_text_file_content(filename):
136136
data = _get_output(['git', 'show', f':{filename}'])
137137
return data
138138

139-
140139
def get_sha():
141140
'''Get the commit sha
142141
@@ -148,6 +147,14 @@ def get_sha():
148147
'''
149148
return _get_output(['git','rev-parse', get_branch()])
150149

150+
def get_repo():
151+
'''Get the repo name in the format of "owner/repo"'''
152+
if _is_github_event():
153+
return os.environ['GITHUB_REPOSITORY']
154+
else:
155+
url = _get_output(['git', 'config', '--get', 'remote.origin.url'])
156+
org = re.search(r'github\.com[:\/](.+?)(\.git)?$', url)
157+
return org.group(1) if org else url
151158

152159
def get_event():
153160
'''Get the git event'''
@@ -183,7 +190,7 @@ def get_commit_files():
183190
commands += ['HEAD~..', '--']
184191
else:
185192
commands = ['git', 'diff-index', '--ignore-submodules', 'HEAD', '--cached']
186-
193+
187194
output = _get_output(commands)
188195
result = defaultdict(list)
189196
for line in output.splitlines():
@@ -462,7 +469,7 @@ def test_trim_trailing_whitespace(self):
462469
content = 'first line\nsecond line \nthird line '
463470
trimmed_content = 'first line\nsecond line\nthird line'
464471

465-
name = NamedTemporaryFile().name
472+
name = NamedTemporaryFile().name
466473
try:
467474
Path(name).write_text(content)
468475
# Trailing whitespace found
@@ -826,7 +833,7 @@ def check_content(files):
826833
return retval
827834

828835

829-
def check_commit_msg(message, files):
836+
def check_commit_msg(message, files, repo):
830837
'''Check commit message (and file size).
831838
832839
Abort if file size exceeds hard (github.com) limit.
@@ -843,6 +850,10 @@ def check_commit_msg(message, files):
843850
# Not checking for JIRA or large file in commit message generated by github
844851
return 0
845852

853+
if re.match(r'^ccdc-opensource', repo):
854+
# Do not check for JIRA in opensource repo as we don't want to require external contributors to do this
855+
return 0
856+
846857
if NO_JIRA_MARKER not in message:
847858
if jira_id_pattern.search(message) is None:
848859
_fail('Every commit should contain a Jira issue ID or the text '
@@ -888,7 +899,7 @@ def _test(input, is_jira=True):
888899
class TestCheckCommitMessage(unittest.TestCase):
889900
def test_various_strings(self):
890901
def _test(input, is_good=True):
891-
rc = check_commit_msg(input, [])
902+
rc = check_commit_msg(input, [], "dummy/repo")
892903
self.assertEqual(rc == 0, is_good)
893904
_test('ABC-1234')
894905
_test('Some changes for ABC-1234 ticket')
@@ -933,6 +944,6 @@ def commit_msg_hook():
933944
commit_message = Path(sys.argv[1]).read_text()
934945

935946
print(' Check commit message ...')
936-
retval += check_commit_msg(commit_message, files['M'] + files['A'])
947+
retval += check_commit_msg(commit_message, files['M'] + files['A'], get_repo())
937948

938-
return retval
949+
return retval

0 commit comments

Comments
 (0)