Fix single-commit check for stable branch PRs#1167
Merged
chris1984 merged 1 commit intotheforeman:developfrom Mar 4, 2026
Merged
Fix single-commit check for stable branch PRs#1167chris1984 merged 1 commit intotheforeman:developfrom
chris1984 merged 1 commit intotheforeman:developfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates the single-commit GitHub Actions workflow to compare commits against the PR’s actual base branch instead of hardcoding the develop branch, so the single-commit check works for PRs to any branch, including stable branches. Sequence diagram for updated single-commit GitHub Actions workflowsequenceDiagram
actor Developer
participant GitHub
participant SingleCommitWorkflow
participant ActionsCheckout
participant GitCLI
Developer->>GitHub: Open pull_request (head -> base_branch)
GitHub-->>SingleCommitWorkflow: Trigger workflow on pull_request
SingleCommitWorkflow->>ActionsCheckout: Checkout current HEAD (PR branch)
ActionsCheckout-->>SingleCommitWorkflow: Working copy at HEAD
SingleCommitWorkflow->>GitCLI: git fetch origin github.base_ref
GitCLI-->>SingleCommitWorkflow: Fetched base branch refs
SingleCommitWorkflow->>GitCLI: git branch base_branch origin/github.base_ref
GitCLI-->>SingleCommitWorkflow: Local base_branch created
SingleCommitWorkflow->>GitCLI: git log --oneline --no-merges HEAD ^base_branch
GitCLI-->>SingleCommitWorkflow: Commit list between HEAD and base_branch
SingleCommitWorkflow->>SingleCommitWorkflow: Count commits and compare to 1
SingleCommitWorkflow-->>GitHub: Report success or failure
GitHub-->>Developer: Show status of single-commit check
Flow diagram for updated single-commit job stepsflowchart TD
A[Start single-commit job] --> B[Checkout PR HEAD with actions/checkout]
B --> C[Fetch origin github.base_ref]
C --> D[Create local base_branch from origin/github.base_ref]
D --> E[Run git log --oneline --no-merges HEAD ^base_branch]
E --> F[Count commits between HEAD and base_branch]
F --> G{Commit count == 1}
G -- Yes --> H[Job succeeds]
G -- No --> I[Job fails]
H --> J[End]
I --> J[End]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
chris1984
approved these changes
Mar 4, 2026
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The commit count check still references
develop; it should be updated to compare against the newly createdbase_branch(e.g.,git log --oneline --no-merges HEAD ^base_branch). - Consider quoting
${{ github.base_ref }}in thegit fetchcommand to avoid issues if the branch name ever contains characters interpreted by the shell (e.g.,git fetch origin "${{ github.base_ref }}").
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The commit count check still references `develop`; it should be updated to compare against the newly created `base_branch` (e.g., `git log --oneline --no-merges HEAD ^base_branch`).
- Consider quoting `${{ github.base_ref }}` in the `git fetch` command to avoid issues if the branch name ever contains characters interpreted by the shell (e.g., `git fetch origin "${{ github.base_ref }}"`).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
c1790ac to
9511ee2
Compare
Collaborator
|
Awesome, thanks @zjhuntin! Seems https://github.com/Katello/katello/blob/master/.github/workflows/pull_request.yml will need the same fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The single-commit workflow added in #1032 enforces one commit per PR to ensure squashed commits before merging. However, it was hardcoded to compare against
develop, which breaks for PRs targeting stable branches likeforeman_3_18.This change uses
github.base_refto dynamically compare against the PR's actual target branch.Problem
PRs like #1166 (Release 13.2.3) targeting
foreman_3_18fail the commit count check because the stable branch has diverged fromdevelop.Solution
Replace hardcoded
developwith${{ github.base_ref }}so the check works for PRs targeting any branch.Summary by Sourcery
CI: