Skip to content

feat: add PR title check action - #18

Merged
uniqueg merged 5 commits into
mainfrom
ci/pr-title-action
Oct 28, 2026
Merged

uniqueg merged 5 commits into
mainfrom
ci/pr-title-action

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the composite action actions/pr-title, which checks pull request titles against the org convention with a plain script (no token, no third-party action):

  • format <type>[(<scope>)][!]: <description> with an allowed type (input types, whitespace- or newline-separated; default build chore ci docs feat fix perf refactor revert style test);
  • at most max-length (default 50) characters in total, counted as Unicode code points;
  • the description doesn't start with a capitalised word (Add); acronyms and names with more capitals or digits (API, OpenAPI, S3, C++) pass. This keeps the lowercase rule of the current cloud-components check without rejecting names seen in FOCA's history;
  • no trailing period or ellipsis, no leading or trailing whitespace (including no-break and zero-width spaces), one line only;
  • every failed rule is reported as an error annotation, with the title's length. The title comes in through env: only and never starts a log line, so it can't inject workflow commands.

Also:

  • tests/pr-title/test.sh: good and bad titles, asserting the exit status and the reported rule, invalid inputs, several rules at once, injection attempts.
  • CI: the test job (Test) runs those tests and the action itself, once with a custom types list (a type that is not a default, so it passes only if the input arrives) and once with max-length (fails only if the input arrives); the gate now needs test.
  • pre-commit: shellcheck (shellcheck-py) and the shebang/executable checks for the new scripts.
  • Docs: actions/pr-title/README.md with the caller workflow from the issue, the root README, and CONTRIBUTING (the type list is closed, the description starts lowercase, the PR title check enforces it).

The workflow template moved to #17: it has to pin the action by a release commit, which only exists after the first release.

Closes #13

Verification

  • bash tests/pr-title/test.sh: all tests pass; a mutation check (reverting the multi-line types and acronym fixes) made 5 tests fail.
  • pre-commit run --all-files (incl. shellcheck, check-github-actions on action.yml, markdownlint) and the manual gitleaks-all: passed.
  • actionlint with shellcheck: no findings.
  • CI: runs 40642337619 and, after the Sourcery fixes, 40643327018 passed (Lint, Test, CI passed); the log shows the good title passing with the custom types and the bad one failing on max-length (10).

Declined review findings

  • Count graphemes instead of code points (decomposed accents count twice): needs a Unicode normaliser in the runner; documented in the action's README instead.
  • Lower the default limit to make room for GitHub's (#N) squash suffix: the issue and CONTRIBUTING set 50 characters for the title; the README says the suffix doesn't count.
  • Exercise the default title (the PR's own title) in CI: that would turn CI into a title check for this repo, which doesn't re-run when a title is edited; the per-repo pr-title.yml is the place for it.
  • A plain capitalised name (Docker image tags) still fails: it can't be told from a capitalised verb; documented.
  • Sourcery, "assert the complete set of reported rules" in the tests: each failure case asserts its rule, one case asserts several rules together, and any :: line other than the script's own annotations fails a test; asserting full sets would duplicate the messages without catching more.

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 28, 2026 06:38
Add the composite action actions/pr-title. A script checks the whole
title: Conventional Commits format with an allowed type, at most 50
characters in total, no uppercase start of the description, no
trailing period or whitespace, one line. The title comes in through
the environment only, and every failed rule is reported with the
title length. Tests cover good and bad titles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the test job: run the title tests, and the action itself on a
good and a bad title. The gate now needs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read types across lines, allow acronyms and names at the start of the
description, reject an empty title, a trailing ellipsis or no-break
space. Tests now assert the reported rule, cover invalid inputs and
several rules at once, and CI exercises the types and max-length
inputs. Lint shell scripts with shellcheck; document the rules in the
READMEs and CONTRIBUTING.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Treat no-break, figure, narrow no-break and zero-width spaces as
whitespace at both ends of the description, let acronyms such as S3
or C++ start it, keep the max-length input out of the log, and test
the types input in CI with a type that is not a default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces a secure, plain Bash composite action for enforcing the repository’s pull request title convention, with configurable types and length, exhaustive rule reporting, documentation, focused tests, CI integration, and shell-script linting.

Sequence diagram for the PR title check action

sequenceDiagram
    participant Workflow
    participant Action
    participant Script
    participant GitHub
    Workflow->>Action: Run actions/pr-title
    Action->>Script: bash check.sh
    Action->>Script: PR_TITLE, PR_TITLE_TYPES, PR_TITLE_MAX_LENGTH
    Script->>Script: Validate title rules
    alt Rules pass
        Script-->>Action: Exit 0
        Action-->>Workflow: Check succeeds
    else Rules fail
        Script->>GitHub: Emit error annotations
        Script-->>Action: Exit 1
        Action-->>Workflow: Check fails
    end
Loading

Flow diagram for PR title validation rules

flowchart TD
    A[PR title from pull_request event] --> B[Read title and inputs from environment]
    B --> C{Valid inputs and non-empty title?}
    C -- No --> E[Emit error annotation and exit 1]
    C -- Yes --> D[Validate format, allowed type, length, casing, whitespace, and punctuation]
    D --> F{Any rules failed?}
    F -- Yes --> G[Report every failed rule with title length]
    G --> E
    F -- No --> H[Print success with title length and exit 0]
Loading

File-Level Changes

Change Details Files
Add a dependency-free composite action that validates pull request titles and safely reports all violations.
  • Implement Conventional Commits-style parsing with configurable allowed types and maximum total length.
  • Validate Unicode code-point length, single-line content, whitespace, punctuation, and lowercase description rules while allowing acronyms and names.
  • Pass inputs through environment variables and emit GitHub error annotations without allowing title content to inject workflow commands.
  • Document action inputs, behavior, usage, release pinning, and repository conventions.
actions/pr-title/action.yml
actions/pr-title/check.sh
actions/pr-title/README.md
README.md
CONTRIBUTING.md
Add comprehensive automated coverage for the title checker and composite action integration.
  • Test valid and invalid formats, custom type lists, length boundaries, Unicode, capitalization exceptions, whitespace, punctuation, malformed inputs, multiple simultaneous failures, and injection attempts.
  • Run the standalone tests and action checks in CI, including custom inputs that verify workflow input propagation.
  • Require the test job to pass through the CI gate.
tests/pr-title/test.sh
.github/workflows/ci.yml
Extend repository validation to cover the new shell scripts and executable conventions.
  • Enable executable/shebang pre-commit checks.
  • Add pinned ShellCheck validation for action and test scripts.
.pre-commit-config.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#13 Add a reusable composite action that validates the whole PR title against the configured Conventional Commits format and allowed types, enforces the total length limit and trailing-punctuation rules, and reports failures safely without a token or third-party action. ✅
#13 Provide tests and CI coverage for valid and invalid titles, including total-length, format, type, scope, breaking-change marker, punctuation, and unsafe-input cases. ✅
#13 Document how repositories call the action from a thin workflow, including the required trigger, permissions, Dependabot skip, and check name. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review October 28, 2026 06:13

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 9 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="actions/pr-title/README.md" line_range="36" />
<code_context>
+name: PR title
+on:
+  pull_request:
+    types: [opened, edited, synchronize, reopened, ready_for_review]
+
+permissions: {}
</code_context>
<issue_to_address>
**Obsolete title checks leave stale results**

When a PR title is edited while an earlier title-check run is queued or running, both workflow runs check their event's title snapshot and publish the `PR title` check for the same head commit. The earlier run can finish last, leaving a successful check for an invalid current title or a failing check for a valid one.

Cancel or otherwise prevent superseded title-check runs from publishing results.
</issue_to_address>

### Comment 2
<location path="actions/pr-title/check.sh" line_range="70" />
<code_context>
+  fi
+  # A capitalised word (`Add`), not an acronym or name (`API`, `OpenAPI`,
+  # `S3`, `C++`)
+  if [[ "${description}" =~ ^[[:upper:]][[:lower:]]*([[:space:]]|$) ]]; then
+    errors+=("The description starts with a capitalised word; use lowercase")
+  fi
</code_context>
<issue_to_address>
**Capitalized descriptions pass validation**

When the description starts with a capitalized word followed by punctuation or one of the listed invisible spaces, the casing check in `check.sh` recognizes a word boundary only at POSIX whitespace or the end of the description, so it accepts titles that violate the lowercase-description rule.

Update the casing check to recognize punctuation and the listed invisible spaces as word boundaries.

Also at `actions/pr-title/check.sh:71`.
</issue_to_address>

### Comment 3
<location path="actions/pr-title/check.sh" line_range="54" />
<code_context>
+
+# Type, optional scope (no spaces or parentheses), optional `!`, then `: `
+# and a description that starts with a visible character
+format="^([a-z]+)(\\([^()[:space:]]+\\))?(!)?: ([^[:space:]${invisible}].*)\$"
+if [[ "${title}" =~ ${format} ]]; then
+  type="${BASH_REMATCH[1]}"
</code_context>
<issue_to_address>
**Allowed custom types are rejected**

When the caller configures an allowed type containing a hyphen or digit, the `format` regex accepts only `[a-z]+` for the type, so a configured type such as `security-fix` or `v2` is rejected as malformed.

Make the format check accept configured types containing hyphens or digits.
</issue_to_address>

### Comment 4
<location path="actions/pr-title/check.sh" line_range="54" />
<code_context>
+
+# Type, optional scope (no spaces or parentheses), optional `!`, then `: `
+# and a description that starts with a visible character
+format="^([a-z]+)(\\([^()[:space:]]+\\))?(!)?: ([^[:space:]${invisible}].*)\$"
+if [[ "${title}" =~ ${format} ]]; then
+  type="${BASH_REMATCH[1]}"
</code_context>
<issue_to_address>
**Whitespace in scopes passes validation**

When a scope contains a no-break, figure, narrow no-break, or zero-width space, the scope character class in `format` excludes POSIX whitespace but not the additional characters in `invisible`, so the title passes despite the no-spaces scope rule.

Exclude the characters in `invisible` from the scope character class.
</issue_to_address>

### Comment 5
<location path="actions/pr-title/check.sh" line_range="50" />
<code_context>
+
+# Whitespace that [[:space:]] misses: no-break, figure, narrow no-break and
+# zero-width spaces
+invisible=$'\u00a0\u2007\u202f\u200b'
+
+# Type, optional scope (no spaces or parentheses), optional `!`, then `: `
</code_context>
<issue_to_address>
**Zero-width no-break space passes validation**

When a title contains U+FEFF at the start of its description or at its end, `invisible` omits U+FEFF, and the format and trailing-whitespace checks do not otherwise recognize it, so the title passes despite the documented whitespace rule.

Include U+FEFF in the invisible whitespace set used by the format and trailing-whitespace checks.

Also at `actions/pr-title/check.sh:54`, `actions/pr-title/check.sh:77`.
</issue_to_address>

### Comment 6
<location path="actions/pr-title/check.sh" line_range="44" />
<code_context>
+  title="${title//[$'\n\r']/ }"
+fi
+
+if ((length > max_length)); then
+  errors+=("Too long: ${length} characters, at most ${max_length} allowed")
+fi
</code_context>
<issue_to_address>
**Large limits reject valid titles**

When `max-length` is a positive decimal larger than Bash's signed integer range, `((length > max_length))` evaluates the limit as a fixed-width signed integer, which wraps negative and reports ordinary titles as too long.

Compare the limit without signed-integer overflow or reject values outside the supported range.
</issue_to_address>

### Comment 7
<location path="actions/pr-title/check.sh" line_range="44" />
<code_context>
+  title="${title//[$'\n\r']/ }"
+fi
+
+if ((length > max_length)); then
+  errors+=("Too long: ${length} characters, at most ${max_length} allowed")
+fi
</code_context>
<issue_to_address>
**Valid limits abort checking**

When the `max-length` input is `08` or another accepted value that Bash cannot parse as octal, bash evaluates `max_length` as an octal number in `((length > max_length))`; `08` passes the positive-integer validation but causes an arithmetic error, so the action exits without reporting the title check result.

Evaluate the limit explicitly in base 10 or reject values that Bash arithmetic cannot safely parse.
</issue_to_address>

### Comment 8
<location path="tests/pr-title/test.sh" line_range="24" />
<code_context>
+  if [[ "${got}" != "${want}" ]]; then
+    echo "NOT OK: expected ${want}, got ${got}: ${title@Q}"
+    failures=$((failures + 1))
+  elif [[ -n "${message}" && "${output}" != *"${message}"* ]]; then
+    echo "NOT OK: expected output ${message@Q}, got ${output@Q}: ${title@Q}"
+    failures=$((failures + 1))
</code_context>
<issue_to_address>
**Extra rule failures go unnoticed**

When the checker emits the expected annotation alongside an unrelated failure annotation, `expect` in `tests/pr-title/test.sh` only checks that `$output` contains `$message`, so a checker that reports the expected rule plus unrelated false-positive rules still passes these cases.

Assert the complete set of reported rule annotations for each failure case.
</issue_to_address>

### Comment 9
<location path="tests/pr-title/test.sh" line_range="27" />
<code_context>
+  elif [[ -n "${message}" && "${output}" != *"${message}"* ]]; then
+    echo "NOT OK: expected output ${message@Q}, got ${output@Q}: ${title@Q}"
+    failures=$((failures + 1))
+  elif grep -qE '^::(warning|notice|debug|add-mask|stop-commands)' <<< "${output}"; then
+    echo "NOT OK: the title injected a workflow command: ${title@Q}"
+    failures=$((failures + 1))
</code_context>
<issue_to_address>
**Error-command injection goes unnoticed**

When a multiline title contains `::error::injected` and the checker prints that line as a workflow command, the `expect` helper in `tests/pr-title/test.sh` excludes `::error` from its workflow-command scan, while the multiline injection cases use only `::warning`; a regression that emits an injected `::error` command therefore passes the injection check.

Distinguish the expected error annotations from title-derived output and assert that no title content produces an additional workflow command.

Also at `tests/pr-title/test.sh:122-123`.
</issue_to_address>

Sourcery assessment

Approval pending. 9 findings to address first.

Blocking findings: actions/pr-title/README.md:36, actions/pr-title/check.sh:70, actions/pr-title/check.sh:54, actions/pr-title/check.sh:54, actions/pr-title/check.sh:50, and 4 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread actions/pr-title/README.md Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread actions/pr-title/check.sh Resolved
Comment thread tests/pr-title/test.sh Resolved
Comment thread tests/pr-title/test.sh Resolved
Bound max-length to 1-9999 and compare it in base 10, allow custom
types with digits and hyphens, treat U+FEFF and other invisible
spaces as whitespace in the scope and description, catch capitalised
words followed by punctuation, test that no title line becomes a
workflow command (::error included), and cancel superseded runs in
the documented caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 498b73e into main Oct 28, 2026
4 checks passed
@uniqueg
uniqueg deleted the ci/pr-title-action branch October 28, 2026 06:24
uniqueg added a commit to uniqueg/dotgithub-release-dryrun that referenced this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: add a PR title check action

1 participant