|
25 | 25 | LARGE_FILE_MARKER = 'LARGE_FILE' |
26 | 26 | # No jira marker in commit message |
27 | 27 | 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 | +) |
28 | 33 | # A marker to represent it's a change we don't want to commit |
29 | 34 | DO_NOT_COMMIT = 'do not' + ' commit' |
30 | 35 | # Check file content if it has these extensions |
@@ -853,20 +858,34 @@ def check_commit_msg(message, files, repo): |
853 | 858 | if re.match(r'^ccdc-opensource/', repo): |
854 | 859 | # Do not check for JIRA in opensource repo as we don't want to require external contributors to do this |
855 | 860 | return 0 |
856 | | - |
857 | 861 |
|
| 862 | + |
858 | 863 | # Check for Conventional Commits compliance. |
859 | 864 | # Opt-in per repo: commit an empty marker file named |
860 | 865 | # `.conventional-commits` at the repo root. |
861 | 866 | if _conventional_commits_enabled(): |
862 | 867 | if check_conventional_commit(message): |
863 | 868 | 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 |
870 | 889 |
|
871 | 890 | for filename in files: |
872 | 891 | size = Path(filename).stat().st_size / 1024**2 |
@@ -947,6 +966,11 @@ def _test(input, is_good=True): |
947 | 966 | _test('ABC-1234') |
948 | 967 | _test('Some changes for ABC-1234 ticket') |
949 | 968 | _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 | + ) |
950 | 974 | _test("Merge branch 'main' into my_branch") |
951 | 975 | _test("Merge branch 'branch_1' into branch_2") |
952 | 976 | _test("Merge branch 'jira_pyapi_123_abc' of github.com:ccdc-confidential/cpp-apps-main into jira_pyapi_123_abc") |
|
0 commit comments