From 8dde5bd6e0849525a812b782e34025b48d74b7a6 Mon Sep 17 00:00:00 2001 From: Jacek Marchwicki Date: Tue, 24 Oct 2023 12:40:53 +0200 Subject: [PATCH] chore: add verifyication step for pull-request title --- .../pull_request_template.md | 28 ++++--- .github/workflows/verify-pr-description.yml | 36 ++++++++ .markdown-link-check.json | 3 + build-tools/verify-pr-description.py | 83 +++++++++++++++++++ 4 files changed, 140 insertions(+), 10 deletions(-) rename pull_request_template.md => .github/pull_request_template.md (53%) create mode 100644 .github/workflows/verify-pr-description.yml create mode 100755 build-tools/verify-pr-description.py diff --git a/pull_request_template.md b/.github/pull_request_template.md similarity index 53% rename from pull_request_template.md rename to .github/pull_request_template.md index e9531ec4c..30c34a9a0 100644 --- a/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,16 +1,19 @@ +# Pull-Request ## Description -*Add here short description what has changed* ### Why? -*Describe why the change is introduced* + + +### What? + ## Links to related issues -- Fixes [LD-XXX](https://loudius.atlassian.net/jira/software/projects/LD/boards/3) -- Not covered by the PR: [LD-XXX](https://loudius.atlassian.net/jira/software/projects/LD/boards/3) -- Possible improvements: [LD-XXX](https://loudius.atlassian.net/jira/software/projects/LD/boards/3) +- Fixes [LD-XXX](https://loudius.atlassian.net/browse/LD-XXX) +- Not covered by the PR: [LD-XXX](https://loudius.atlassian.net/browse/LD-XXX) +- Possible improvements: [LD-XXX](https://loudius.atlassian.net/browse/LD-XXX) ## Demo @@ -22,7 +25,13 @@ Screenshots or video that presents the feature or fix |---------------|--------------| | | | - +## How to test + +* **Step 1**: Describe step 1 +* **Step 2**: Describe step 2 +* **Expected:** Describe what is expected to happen ## Documentation - Link to documentation: **Add link here** @@ -34,8 +43,7 @@ Screenshots or video that presents the feature or fix All those checkboxes should be marked before submitting the PR --> -- [ ] New functionality is covered by Analytics events -- [ ] Analytics events are documented -- [ ] Analytics dashboard is updated - [ ] Functionality covered by unit tests -- [ ] I have manually tested if the code works +- [ ] Functionality covered by integration tests +- [ ] I have updated PR description with relevant information +- [ ] I have manually tested if the code and app works diff --git a/.github/workflows/verify-pr-description.yml b/.github/workflows/verify-pr-description.yml new file mode 100644 index 000000000..396cfe737 --- /dev/null +++ b/.github/workflows/verify-pr-description.yml @@ -0,0 +1,36 @@ +name: Verify Pull-Request Description + +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + +permissions: read-all + +jobs: + unit-tests: + name: Verify Pull-Request Description + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: | + build-tools/ + .github/ + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Verify PR + shell: bash + run: python "build-tools/verify-pr-description.py" + env: + TITLE: ${{ github.event.pull_request.title }} + BODY: ${{ github.event.pull_request.body }} \ No newline at end of file diff --git a/.markdown-link-check.json b/.markdown-link-check.json index ca6150231..78858b54a 100644 --- a/.markdown-link-check.json +++ b/.markdown-link-check.json @@ -5,6 +5,9 @@ "ignorePatterns": [ { "pattern": "^https://www.notion.so/appunite" + }, + { + "pattern": "^https://loudius.atlassian.net/browse/LD-XXX$" } ] } diff --git a/build-tools/verify-pr-description.py b/build-tools/verify-pr-description.py new file mode 100755 index 000000000..4840c47c7 --- /dev/null +++ b/build-tools/verify-pr-description.py @@ -0,0 +1,83 @@ +# Copyright 2023 AppUnite S.A. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re +import os + + +def get_text_for_header(markdown_text, header): + """Returns all text for a given header from a Markdown. + + Args: + markdown_text: The path to the Markdown file. + header: The header to get the text for. + + Returns: + A string containing all text for the given header, or None if the header is + not found. + """ + header_pattern = r'^#{1,6}\s+(.*?)$' + header_matches = re.finditer(header_pattern, markdown_text, re.MULTILINE) + + for match in header_matches: + current_header = match.group(1) + if header in current_header: + next_match = next(header_matches, None) + if next_match: + end_pos = next_match.start() + else: + end_pos = len(markdown_text) + # Extract text between headers + return markdown_text[match.end():end_pos].strip() + return None + + +def remove_html_comments(text): + return re.sub(r"", "", text, flags=re.DOTALL) + + +def main(): + title = os.environ['TITLE'] + body = os.environ['BODY'] + errors = [] + + if not re.search(r'LD-[0-9]+', title): + errors.append('The title should contain a link to a jira task') + if not re.search(r'LD-[0-9]+', body) or "LD-XXX" in body: + errors.append('The description should contain a link jira ticket') + if re.search(r'^- \[ ]', body): + errors.append('Please go through PR checklist') + + body_without_comments = remove_html_comments(body) + if not get_text_for_header(body_without_comments, "Why?"): + errors.append('Please describe why you\'ve introduced the change') + if not get_text_for_header(body_without_comments, "What?"): + errors.append('Please describe what you\'ve changed') + if "Describe what is expected to happen" in body or "Describe step 1" in body: + errors.append('Add test steps') + if "Add link here" in body or "Add here other useful documentation links" in body: + errors.append('Add links to documentation') + if "| | |" in body or not get_text_for_header(body_without_comments, "Demo"): + errors.append("Fill the Demo section") + + for error in errors: + print(f"Error {error}", file=sys.stderr) + + if errors: + sys.exit(1) + + +if __name__ == "__main__": + main()