|
| 1 | +name: PR Description Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - master |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - synchronize |
| 11 | + - reopened |
| 12 | + - edited |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-description: |
| 16 | + runs-on: macos-latest |
| 17 | + steps: |
| 18 | + - name: Install GitHub CLI |
| 19 | + run: | |
| 20 | + brew install gh |
| 21 | + - name: Check PR Description |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ github.token }} |
| 24 | + run: | |
| 25 | + pr_link="https://github.com/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" |
| 26 | + |
| 27 | + echo "$pr_link" |
| 28 | + |
| 29 | + pr_description=$(gh pr view $pr_link --json body -q ".body") |
| 30 | + |
| 31 | + if [ -z "$pr_description" ]; then |
| 32 | + echo "Failed to fetch the PR description" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + # Define minimum character count for each section |
| 37 | + MIN_CHARS=10 |
| 38 | + # Extract contents |
| 39 | + what_changed=$(echo "$pr_description" | sed -n -e '/\*What was changed?\*/,/\*Why was it changed?\*/p' | sed '$d' | sed '1d') |
| 40 | + why_changed=$(echo "$pr_description" | sed -n -e '/\*Why was it changed?\*/,/\*How was it changed?\*/p' | sed '$d' | sed '1d') |
| 41 | + how_changed=$(echo "$pr_description" | sed -n -e '/\*How was it changed?\*/,/\*What testing was done for the changes?\*/p' | sed '$d' | sed '1d') |
| 42 | + testing_done=$(echo "$pr_description" | sed -n -e '/\*What testing was done for the changes?\*/,/By submitting this pull request/p' | sed '$d' | sed '1d') |
| 43 | + |
| 44 | + error_occurred=0 |
| 45 | + if [[ ${#what_changed} -lt $MIN_CHARS ]]; then |
| 46 | + echo "PR description for what changed section is either missing or too short. Required: ${MIN_CHARS}, Current: ${what_changed}" |
| 47 | + error_occurred=1 |
| 48 | + fi |
| 49 | + if [[ ${#why_changed} -lt $MIN_CHARS ]]; then |
| 50 | + echo "PR description for why it changed section is either missing or too short. Required: ${MIN_CHARS}, Current: ${why_changed}" |
| 51 | + error_occurred=1 |
| 52 | + fi |
| 53 | + if [[ ${#how_changed} -lt $MIN_CHARS ]]; then |
| 54 | + echo "PR description for how was it changed section is either missing or too short. Required: ${MIN_CHARS}, Current: ${how_changed}" |
| 55 | + error_occurred=1 |
| 56 | + fi |
| 57 | + if [[ ${#testing_done} -lt $MIN_CHARS ]]; then |
| 58 | + echo "PR description for testing section are either missing or too short. Required: ${MIN_CHARS}, Current: ${testing_done}" |
| 59 | + error_occurred=1 |
| 60 | + fi |
| 61 | + if [[ $error_occurred -eq 1 ]]; then |
| 62 | + exit 1 |
| 63 | + fi |
0 commit comments