Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Add a reusable workflow that squashes all commits on a PR branch into a single commit when triggered by the /squash slash command. Uses git reset --soft for reliable non-interactive squashing in CI. Edge cases handled: - Fork PRs rejected (no write access to contributor repos) - Single-commit PRs produce informational no-op - Merge commits in branch history trigger warning - Co-authored-by and Signed-off-by trailers preserved - --force-with-lease prevents overwriting concurrent pushes
Add squash command entry to the _slash.yml reusable slash command config so repos using the shared dispatch get the /squash command automatically.
ca302d0 to
7caff61
Compare
Add fork PR support to the squash workflow. For fork PRs where "Allow edits from maintainers" is enabled, the workflow now checks maintainerCanModify via the GitHub API, checks out the fork repository, adds the upstream as a remote for merge-base computation, and pushes back to the fork branch. If the PR author has not enabled maintainer edits, the command reports a clear error asking them to enable it.
Support optional arguments for the /squash slash command: - /squash <message>: use a custom commit message instead of the first commit's message - /squash --last N: squash only the last N commits instead of all commits on the branch - /squash --last N <message>: combine both options Arguments are parsed by slash-command-dispatch v5 from the PR comment text after the /squash command.
Parse the full comment body for multiline commit messages. Lines after the /squash command line become the extended commit body, following standard git title/body convention with a blank line separator.
When using the default commit message (first commit's %B), trailers like Signed-off-by were duplicated because %B already includes them and the trailer collection loop appended them again. Add a grep-based dedup check to skip trailers already present in the commit message.
slash-command-dispatch uses key=value format for named args, not --key value. Parse --last N from the unnamed args string and strip it from the custom message. Supports both --last N and last=N syntax.
|
Tested on a fork with all features working: waveywaves/tekton-pipeline#5
|
vdemeester
left a comment
There was a problem hiding this comment.
Can the custom commit message be multi-line ?
| # | ||
| # Security Notes: | ||
| # - Only users with "write" permission can trigger this command (enforced in slash.yml) | ||
| # - Supports fork PRs when "Allow edits from maintainers" is enabled |
There was a problem hiding this comment.
This mean the "bot user" need to be maintainer right ? It has write access for sure, not sure if it has maintainer role.
There was a problem hiding this comment.
No, write (push) access is sufficient: maintainer role is not required.
The GitHub docs say: "People with push access to the upstream repository of a fork in a personal account can commit to the forked branches."
The Write role grants push access, so any user/bot with Write access can push to fork branches when the PR author enables "Allow edits from maintainers".
One important caveat: this only works with PATs, not with GITHUB_TOKEN or GitHub App installation tokens. GitHub intentionally restricts GITHUB_TOKEN from pushing to forks. Since CHATOPS_TOKEN is a PAT with write access, the fork push works. This is the same mechanism used by cirrus-actions/rebase (500+ stars) which pushes to forks using x-access-token:$TOKEN in the git URL.
Also note: this only works for user-owned forks, not org-owned forks (GitHub doesn't allow maintainer_can_modify for org forks).
Yes! Lines after the This produces a commit with:
The multiline parsing extracts everything after line 1 of the comment body via cc @vdemeester |
Changes
Add a
/squashslash command to the Tekton chatops system, following the same three-layer architecture as the existing/rebasecommand (PR tektoncd/pipeline#9375):_squash-command.yaml(new) — Reusable workflow containing the squash logic_slash.yml(modified) — Register/squashin the shared slash command dispatchHow it works
When a maintainer comments
/squashon a PR:slash.ymlin the consuming repo dispatches asquash-commandrepository eventgit reset --softto squash all commits into one using the first commit's message, and force pushes with--force-with-leaseEdge cases handled
Co-authored-byandSigned-off-bytrailers preserved from all commits--force-with-leaseprevents overwritingWhy
git reset --softinstead ofgit rebase -iInteractive rebase requires editor hacks (
GIT_SEQUENCE_EDITOR) in CI and is fragile with merge commits.git reset --soft $(git merge-base ...)is simpler, fully non-interactive, and produces identical results for the squash use case.Follow-up
A corresponding PR for
tektoncd/pipelinewill add the caller workflow (squash-command.yaml),slash.ymlentry, andCONTRIBUTING.mddocumentation once this is merged and a SHA is available for pinning./kind feature
Submitter Checklist
See the contribution guide
for more details.