From 8adde940c0682e10793ace0f7be32e52a0f2f0e0 Mon Sep 17 00:00:00 2001 From: AlexisErazoGlobant <168037709+AlexisErazoGlobant@users.noreply.github.com> Date: Thu, 9 May 2024 07:58:38 -0500 Subject: [PATCH] DYN-6915 Changes to check the PR description, and adding some context to PR template. (#15202) * DYN-6915 Changes to check the PR description, and adding some context to PR template. * Adjustment to regex. --------- Co-authored-by: Alexis Erazo --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/pr_description_check.yml | 51 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr_description_check.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5dc1c6dbfb0..52a161f1e1e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -29,7 +29,7 @@ Check these if you believe they are true ### Release Notes -(FILL ME IN) Brief description of the fix / enhancement. **Mandatory section** +(FILL ME IN) Brief description of the fix / enhancement. Use N/A to indicate that the changes in this pull request do not apply to Release Notes. **Mandatory section** ### Reviewers diff --git a/.github/workflows/pr_description_check.yml b/.github/workflows/pr_description_check.yml new file mode 100644 index 00000000000..81862588916 --- /dev/null +++ b/.github/workflows/pr_description_check.yml @@ -0,0 +1,51 @@ +name: PR description checker + +on: + pull_request: + types: [opened, edited, reopened] + +jobs: + check_release_notes: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Extract Description + id: extract_description + run: | + echo "${{ github.event.pull_request.body }}" > pr_description.txt + sed -i ':a;N;$!ba;s/\n/ /g' pr_description.txt + cat pr_description.txt + + - name: Extract Release Notes + id: extract_notes + run: | + release_notes=$(grep -oP '(?s)(?<=### Release Notes)\s*([\s\S]*?)\s*(?=###)' pr_description.txt) + echo "$release_notes" > release_notes.txt + cat release_notes.txt + + - name: Validate Release Notes + id: validate_notes + run: | + release_notes=$(cat release_notes.txt) + if [[ "$release_notes" == *"(FILL ME IN)"* ]]; then + echo "Error: Release notes must be filled in." + echo "Author: Please check if the text in Release Notes is the default text." + exit 1 + elif [[ "$release_notes" == *"N/A"* ]]; then + echo "Release notes are not applicable for this pull request." + echo "Reviewer: Please check if this pull request have non-applicable Release notes." + exit 0 + else + word_count=$(wc -w <<< "$release_notes") + if [ $word_count -ge 6 ]; then + echo "Release notes have at least 6 words." + exit 0 + else + echo "Error: Release notes must have at least 6 words." + echo "Author: Please add more context of your changes." + exit 1 + fi + fi