Skip to content

ci: validate-pr: validate commit messages through GitHub API - #53327

Merged
vvoland merged 1 commit into
moby:masterfrom
thaJeztah:improve_commit_checks
Aug 11, 2026
Merged

ci: validate-pr: validate commit messages through GitHub API#53327
vvoland merged 1 commit into
moby:masterfrom
thaJeztah:improve_commit_checks

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Aug 7, 2026

Copy link
Copy Markdown
Member

ci: validate-pr: validate commit messages through GitHub API

Use the pull request commits API to validate commit messages instead of
checking out the repository and inspecting the local Git history.

This avoids fetching the repository solely for commit metadata, making the
check lighter and faster. It also avoids executing validation scripts from
the PR checkout, reducing exposure to untrusted PR-controlled code.

While updating; also touched-up the messages slightly, and added a log
for successful checks (to verify the expected number of commits were
checked).

Before this patch, the check took 20-30 seconds; with this patch it's
1-2 seconds.

Failing check:

Run Check GitHub references
  Run gh api --paginate --slurp "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" > "$RUNNER_TEMP/pr-commits.json"
  Error: commit ea73f3de6fd7e88db036c24ebc178eecb3e58ad8 contains a GitHub issue or PR reference; use a commit hash instead if a reference is needed.

  Remove GitHub issue or PR references from commit messages.
  Use commit hashes instead if a reference is needed.
  Keep GitHub issue or PR references in GitHub-visible text, such as PR descriptions or comments.
  Error: Process completed with exit code 1.

Successful check:

Run Check GitHub references
  Run gh api --paginate --slurp "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" > "$RUNNER_TEMP/pr-commits.json"
  Checked 3 commit(s); no GitHub issue or PR references found.

Before:

Screenshot 2026-08-07 at 14 02 02

After:

Screenshot 2026-08-07 at 14 04 22 Screenshot 2026-08-07 at 14 04 56

Release notes (optional)

A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.6.3 milestone Aug 7, 2026
@thaJeztah thaJeztah added status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/ci ci/validate-only labels Aug 7, 2026
@thaJeztah
thaJeztah force-pushed the improve_commit_checks branch 2 times, most recently from 193b6d3 to ea73f3d Compare August 7, 2026 11:46
@thaJeztah
thaJeztah force-pushed the improve_commit_checks branch from d2a2eaf to 51efc68 Compare August 7, 2026 11:58
@thaJeztah thaJeztah modified the milestones: 29.6.3, 29.8.0 Aug 7, 2026
@thaJeztah
thaJeztah marked this pull request as ready for review August 7, 2026 12:12
@thaJeztah
thaJeztah requested review from crazy-max and a lite review from Copilot August 7, 2026 12:12

Copilot AI 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.

Pull request overview

This workflow update makes the validate-pr CI check validate PR commit messages via the GitHub Pull Request Commits API (using gh api) instead of checking out the repository and scanning local git history. This reduces runtime and avoids executing scripts from untrusted PR checkouts.

Changes:

  • Replace repository checkout + hack/validate/pr-gh-references execution with gh api fetching PR commits and jq-based validation.
  • Update workflow token permissions to pull-requests: read.
  • Improve log output by printing a success message including the number of commits checked.

Comment thread .github/workflows/validate-pr.yml Outdated
Use the pull request commits API to validate commit messages instead of
checking out the repository and inspecting the local Git history.

This avoids fetching the repository solely for commit metadata, making the
check lighter and faster. It also avoids executing validation scripts from
the PR checkout, reducing exposure to untrusted PR-controlled code.

While updating; also touched-up the messages slightly, and added a log
for successful checks (to verify the expected number of commits were
checked).

Before this patch, the check took 20-30 seconds; with this patch it's
1-2 seconds.

Failing check:

    Run Check GitHub references
      Run gh api --paginate --slurp "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" > "$RUNNER_TEMP/pr-commits.json"
      Error: commit ea73f3d contains a GitHub issue or PR reference; use a commit hash instead if a reference is needed.

      Remove GitHub issue or PR references from commit messages.
      Use commit hashes instead if a reference is needed.
      Keep GitHub issue or PR references in GitHub-visible text, such as PR descriptions or comments.
      Error: Process completed with exit code 1.

Successful check:

    Run Check GitHub references
      Run gh api --paginate --slurp "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" > "$RUNNER_TEMP/pr-commits.json"
      Checked 3 commit(s); no GitHub issue or PR references found.

Signed-off-by: Sebastiaan van Stijn <[email protected]>

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@vvoland
vvoland merged commit af16d51 into moby:master Aug 11, 2026
55 checks passed
@thaJeztah
thaJeztah deleted the improve_commit_checks branch August 11, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci area/docs ci/validate-only kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants