-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add verifyication step for pull-request title
- Loading branch information
1 parent
e4a71c7
commit 8dde5bd
Showing
4 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |