Skip to content

Commit 6217d92

Browse files
Merge pull request #37 from ccdc-opensource/SYS-8303-co-pilot-autofix
Sys-8303 co-pilot autofix
2 parents 2ca7d04 + 2b1bb8b commit 6217d92

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The commit will be flagged if it includes certain text files with:
1414
* Certain C++ #include patterns and std::exception
1515

1616
The commit will also be flagged if the commit message does not include a Jira
17-
ID (unless marked with NO_JIRA), or if the size of new or modiffied files
18-
exceeds a threshold.
17+
ID (unless marked with NO_JIRA or a Copilot Autofix co-author line), or if the
18+
size of new or modified files exceeds a threshold.
1919

2020

2121
# Github action

main/githooks.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
LARGE_FILE_MARKER = 'LARGE_FILE'
2626
# No jira marker in commit message
2727
NO_JIRA_MARKER = 'NO_JIRA'
28+
# Copilot Autofix co-author in commit message description
29+
copilot_autofix_coauthor_pattern = re.compile(
30+
r'^Co-authored-by:\s+.*<\d+\+Copilot@users\.noreply\.github\.com>$',
31+
re.MULTILINE,
32+
)
2833
# A marker to represent it's a change we don't want to commit
2934
DO_NOT_COMMIT = 'do not' + ' commit'
3035
# Check file content if it has these extensions
@@ -854,11 +859,16 @@ def check_commit_msg(message, files, repo):
854859
# Do not check for JIRA in opensource repo as we don't want to require external contributors to do this
855860
return 0
856861

857-
if NO_JIRA_MARKER not in message:
858-
if jira_id_pattern.search(message) is None:
859-
_fail('Every commit should contain a Jira issue ID or the text '
860-
f'{NO_JIRA_MARKER}')
861-
return 1
862+
if (
863+
NO_JIRA_MARKER not in message
864+
and copilot_autofix_coauthor_pattern.search(message) is None
865+
and jira_id_pattern.search(message) is None
866+
):
867+
_fail(
868+
'Every commit should contain a Jira issue ID, '
869+
f'{NO_JIRA_MARKER}, or be a Copilot Autofix commit'
870+
)
871+
return 1
862872

863873
for filename in files:
864874
size = Path(filename).stat().st_size / 1024**2
@@ -904,6 +914,11 @@ def _test(input, is_good=True):
904914
_test('ABC-1234')
905915
_test('Some changes for ABC-1234 ticket')
906916
_test('Trivial change NO_JIRA')
917+
_test(
918+
'Trivial change\n\n'
919+
'Co-authored-by: Copilot Autofix powered by AI '
920+
'<175728472+Copilot@users.noreply.github.com>'
921+
)
907922
_test("Merge branch 'main' into my_branch")
908923
_test("Merge branch 'branch_1' into branch_2")
909924
_test("Merge branch 'jira_pyapi_123_abc' of github.com:ccdc-confidential/cpp-apps-main into jira_pyapi_123_abc")

0 commit comments

Comments
 (0)