Skip to content

Commit c6433fe

Browse files
committed
Merge branch 'main' into PLA-3204_conventional-commit
2 parents cbbc1e4 + 6217d92 commit c6433fe

2 files changed

Lines changed: 33 additions & 9 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

100755100644
Lines changed: 31 additions & 7 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
@@ -853,20 +858,34 @@ def check_commit_msg(message, files, repo):
853858
if re.match(r'^ccdc-opensource/', 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
856-
857861

862+
858863
# Check for Conventional Commits compliance.
859864
# Opt-in per repo: commit an empty marker file named
860865
# `.conventional-commits` at the repo root.
861866
if _conventional_commits_enabled():
862867
if check_conventional_commit(message):
863868
return 1
864-
865-
if NO_JIRA_MARKER not in message:
866-
if jira_id_pattern.search(message) is None:
867-
_fail('Every commit should contain a Jira issue ID or the text '
868-
f'{NO_JIRA_MARKER}')
869-
return 1
869+
870+
871+
if (
872+
NO_JIRA_MARKER not in message
873+
and copilot_autofix_coauthor_pattern.search(message) is None
874+
and jira_id_pattern.search(message) is None
875+
):
876+
_fail(
877+
'Every commit should contain a Jira issue ID, '
878+
f'{NO_JIRA_MARKER}, or be a Copilot Autofix commit'
879+
)
880+
if (
881+
NO_JIRA_MARKER not in message
882+
and copilot_autofix_coauthor_pattern.search(message) is None
883+
and jira_id_pattern.search(message) is None
884+
):
885+
_fail(
886+
'Every commit should contain a Jira issue ID, '
887+
f'{NO_JIRA_MARKER}, or be a Copilot Autofix commit'
888+
return 1
870889

871890
for filename in files:
872891
size = Path(filename).stat().st_size / 1024**2
@@ -947,6 +966,11 @@ def _test(input, is_good=True):
947966
_test('ABC-1234')
948967
_test('Some changes for ABC-1234 ticket')
949968
_test('Trivial change NO_JIRA')
969+
_test(
970+
'Trivial change\n\n'
971+
'Co-authored-by: Copilot Autofix powered by AI '
972+
'<175728472+Copilot@users.noreply.github.com>'
973+
)
950974
_test("Merge branch 'main' into my_branch")
951975
_test("Merge branch 'branch_1' into branch_2")
952976
_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)