Skip to content

Commit

Permalink
chore: add verifyication step for pull-request title
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-marchwicki committed Oct 24, 2023
1 parent e4a71c7 commit 8dde5bd
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pull_request_template.md → .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Pull-Request
## Description
*Add here short description what has changed*

### Why?
*Describe why the change is introduced*
<!-- Describe why the change is introduced -->

### What?
<!-- Add here short description what has changed -->

## Links to related issues
<!---
Add links to related tickets
-->
- 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
Expand All @@ -22,7 +25,13 @@ Screenshots or video that presents the feature or fix
|---------------|--------------|
| | |


## How to test
<!--
Add a description that will help reviewer check if given change works as expected
-->
* **Step 1**: Describe step 1
* **Step 2**: Describe step 2
* **Expected:** Describe what is expected to happen

## Documentation
- Link to documentation: **Add link here**
Expand All @@ -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
36 changes: 36 additions & 0 deletions .github/workflows/verify-pr-description.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .markdown-link-check.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"ignorePatterns": [
{
"pattern": "^https://www.notion.so/appunite"
},
{
"pattern": "^https://loudius.atlassian.net/browse/LD-XXX$"
}
]
}
83 changes: 83 additions & 0 deletions build-tools/verify-pr-description.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8dde5bd

Please sign in to comment.