From ea41bb444c1afe98055655e1ab98ce923047f941 Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Fri, 2 Dec 2022 14:14:35 +0100 Subject: [PATCH 1/5] chore: rewrite PR title linting workflow in py3 --- .github/workflows/lint-pr.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index 68a42a0d..56ef22ea 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -13,11 +13,21 @@ jobs: TITLE: ${{ github.event.pull_request.title }} steps: - run: | - if [[ "$TITLE" =~ (^(chore|feat|fix|refactor|test|revert){1}?: ([[:alnum:]])+([[:space:][:print:]]*)) ]]; then - echo "Valid PR title" - else - echo 'PR title does not follow the convention "type: subject"' - echo 'type must be one of the following: feat|fix|chore|refactor|test|revert' - exit 1 - fi - shell: bash + import os, re + valid_types = ['chore', 'feat', 'fix', 'refactor', 'test', 'revert'] + try: + segments = re.split(r':\s*', os.getenv('TITLE', '')) + if (len(segments) != 2): + raise Exception('Invalid number of commit types used') + type, subject = segments + if type.lower() not in valid_types: + raise Exception('Invalid commit type') + if not all(c.isprintable() for c in subject): + raise Exception('Invalid commit subject') + print('PR title is valid') + exit(0) + except Exception as e: + print('Error: {}'.format(e.args[0])) + print('PR title does not follow the convention "type: subject"\nValid types are: {}'.format(', '.join(valid_types))) + exit(1) + shell: python From a113a5ee89563a7b1222b4af366dfb0b42cae919 Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Fri, 2 Dec 2022 15:18:00 +0100 Subject: [PATCH 2/5] Update .github/workflows/lint-pr.yml Co-authored-by: Avinash Dwarapu --- .github/workflows/lint-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index 56ef22ea..432fda66 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -16,9 +16,9 @@ jobs: import os, re valid_types = ['chore', 'feat', 'fix', 'refactor', 'test', 'revert'] try: - segments = re.split(r':\s*', os.getenv('TITLE', '')) + segments = re.split(r':\s*', title, maxsplit=1) if (len(segments) != 2): - raise Exception('Invalid number of commit types used') + raise Exception('PR title does not follow "type: subject" convention') type, subject = segments if type.lower() not in valid_types: raise Exception('Invalid commit type') From 208a949d403e97ea2d7b6685825d17e773adde22 Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Fri, 2 Dec 2022 15:18:09 +0100 Subject: [PATCH 3/5] Update .github/workflows/lint-pr.yml Co-authored-by: Avinash Dwarapu --- .github/workflows/lint-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index 432fda66..3a974be1 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -20,7 +20,7 @@ jobs: if (len(segments) != 2): raise Exception('PR title does not follow "type: subject" convention') type, subject = segments - if type.lower() not in valid_types: + if type not in valid_types: raise Exception('Invalid commit type') if not all(c.isprintable() for c in subject): raise Exception('Invalid commit subject') From ed62003eb5c7346b5ec62352b0a6ec625b2f787f Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Fri, 2 Dec 2022 15:18:43 +0100 Subject: [PATCH 4/5] Update .github/workflows/lint-pr.yml Co-authored-by: Avinash Dwarapu --- .github/workflows/lint-pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index 3a974be1..feffb042 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -15,6 +15,7 @@ jobs: - run: | import os, re valid_types = ['chore', 'feat', 'fix', 'refactor', 'test', 'revert'] + title = os.environ['TITLE'] try: segments = re.split(r':\s*', title, maxsplit=1) if (len(segments) != 2): From 3565b7cc253f53bdc60e66ae271eca4a16c2ff1a Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Fri, 2 Dec 2022 15:19:33 +0100 Subject: [PATCH 5/5] Update lint-pr.yml --- .github/workflows/lint-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index feffb042..28e3ba85 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -15,8 +15,8 @@ jobs: - run: | import os, re valid_types = ['chore', 'feat', 'fix', 'refactor', 'test', 'revert'] - title = os.environ['TITLE'] try: + title = os.environ['TITLE'] segments = re.split(r':\s*', title, maxsplit=1) if (len(segments) != 2): raise Exception('PR title does not follow "type: subject" convention')