|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Summary: check the subject and description of each PR for basic best |
| 16 | +# practices and fail with an error if a PR doesn't meet the conditions. |
| 17 | + |
| 18 | +name: Pull request text checker |
| 19 | +run-name: >- |
| 20 | + Check title and description of |
| 21 | + PR #${{github.event.inputs.pr-number || github.event.pull_request.number}} |
| 22 | + by ${{github.actor}} |
| 23 | +
|
| 24 | +on: |
| 25 | + pull_request: |
| 26 | + types: |
| 27 | + - edited |
| 28 | + - opened |
| 29 | + - reopened |
| 30 | + - synchronize |
| 31 | + branches: |
| 32 | + - main |
| 33 | + |
| 34 | +permissions: read-all |
| 35 | + |
| 36 | +jobs: |
| 37 | + check-text-length: |
| 38 | + name: "Minimum length check" |
| 39 | + runs-on: ubuntu-slim |
| 40 | + timeout-minutes: 5 |
| 41 | + steps: |
| 42 | + - name: Check the lengths of the PR title and description |
| 43 | + env: |
| 44 | + SHELLOPTS: ${{runner.debug && 'xtrace' || '' }} |
| 45 | + run: | |
| 46 | + pr_title=$(jq -r ".pull_request.title" "${GITHUB_EVENT_PATH}") |
| 47 | + pr_body=$(jq -r ".pull_request.body" "${GITHUB_EVENT_PATH}") |
| 48 | +
|
| 49 | + read -ra title_words <<< "${pr_title}" |
| 50 | + if [[ ${#title_words[@]} -lt 2 ]]; then |
| 51 | + echo "::error::PR title must contain at least two words." |
| 52 | + error=1 |
| 53 | + fi |
| 54 | + if [[ -z "${pr_body}" || ${#pr_body} -lt 10 ]]; then |
| 55 | + echo "::error::PR description must be at least 10 characters long." |
| 56 | + error=1 |
| 57 | + fi |
| 58 | +
|
| 59 | + if [[ -v error ]]; then |
| 60 | + { |
| 61 | + printf "❌ Problem(s) found with the PR title and/or description." |
| 62 | + } >> "${GITHUB_STEP_SUMMARY}" |
| 63 | + exit 1 |
| 64 | + fi |
0 commit comments