Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/pr-text-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2026 Google LLC
#
# 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
#
# https://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.

# Summary: check the subject and description of each PR for basic best
# practices and fail with an error if a PR doesn't meet the conditions.

name: Pull request text checker
run-name: >-
Check title and description of
PR #${{github.event.inputs.pr-number || github.event.pull_request.number}}
by ${{github.actor}}

on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize
branches:
- main

permissions: read-all

jobs:
check-text-length:
name: "Minimum length check"
runs-on: ubuntu-slim
timeout-minutes: 5
steps:
- name: Check the lengths of the PR title and description
env:
SHELLOPTS: ${{runner.debug && 'xtrace' || '' }}
run: |
pr_title=$(jq -r ".pull_request.title" "${GITHUB_EVENT_PATH}")
pr_body=$(jq -r ".pull_request.body" "${GITHUB_EVENT_PATH}")

read -ra title_words <<< "${pr_title}"
if [[ ${#title_words[@]} -lt 2 ]]; then
echo "::error::PR title must contain at least two words."
error=1
fi
if [[ -z "${pr_body}" || ${#pr_body} -lt 10 ]]; then
echo "::error::PR description must be at least 10 characters long."
error=1
fi

if [[ -v error ]]; then
{
printf "❌ Problem(s) found with the PR title and/or description."
} >> "${GITHUB_STEP_SUMMARY}"
exit 1
fi
Loading