-
Notifications
You must be signed in to change notification settings - Fork 129
Add workflow to check PR titles & descriptions #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # 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. | ||
|
|
||
| # 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: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| branches: | ||
| - main | ||
|
|
||
| workflow_dispatch: | ||
| inputs: | ||
| pr-number: | ||
| description: 'The PR number of the PR to check:' | ||
| type: string | ||
| required: true | ||
| debug: | ||
| description: 'Run with debugging options' | ||
| type: boolean | ||
| default: true | ||
|
|
||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| check-pr-text: | ||
| name: "Title & description check" | ||
| if: github.repository_owner == 'quantumlib' | ||
| runs-on: ubuntu-slim | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Enable shell debugging if requested | ||
| if: ${{inputs.debug || runner.debug}} | ||
| run: echo "SHELLOPTS=xtrace" >> "${GITHUB_ENV}" | ||
|
|
||
| # Note that this workflow does not need to check out the git repo because | ||
| # it does not need to read any files in the repo. | ||
| - name: Check title and description | ||
| run: | | ||
| pr_title=$(jq -r ".pull_request.title" "${GITHUB_EVENT_PATH}") | ||
| pr_body=$(jq -r ".pull_request.body" "${GITHUB_EVENT_PATH}") | ||
|
|
||
| declare -a problems=() | ||
| if [[ -z "${pr_title}" ]]; then | ||
| problems+=("PR title cannot be empty.") | ||
| else | ||
| read -ra title_words <<< "${pr_title}" | ||
| if [[ ${#title_words[@]} -lt 2 ]]; then | ||
| problems+=("PR title must contain at least two words.") | ||
| fi | ||
| fi | ||
|
|
||
| if [[ -z "${pr_body}" || ${#pr_body} -lt 10 ]]; then | ||
| problems+=("PR description must be at least 10 characters long.") | ||
| fi | ||
|
|
||
| if [[ ${#problems[@]} -gt 0 ]]; then | ||
| # shellcheck disable=SC2034 | ||
| { | ||
| echo "Please fix the following problem(s) with this PR:" | ||
| printf -- ":x: %s\n" "${problems[@]}" | ||
| } >> "${GITHUB_STEP_SUMMARY}" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
| fi | ||
|
|
||
| # Point people to the list of problems. Done as a separate step to make | ||
| # this text easier for people to find in the workflow results. | ||
| - name: Report outcome | ||
| run: | | ||
| if [[ "${result}" == "error" ]]; then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| echo '::error::Failed checks. Please check the workflow summary.' | ||
| exit 1 | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code ever visited by shellcheck? If not, please remove.