Support bare version shorthand in /backport comments

Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-08-24 14:42:56 +00:00
committed by GitHub
co-authored by kaovilai
parent 09c1656df9
commit 077a9f8159
2 changed files with 21 additions and 1 deletions
+2
View File
@@ -60,6 +60,8 @@ branches.
space-delimited: `/backport release-1.17 release-1.18`. The label causes the
backport to run automatically when the PR merges.
- **After merge:** the same comment immediately creates the backport PR.
- **Shorthand:** a bare version like `/backport 1.17` is automatically expanded
to `release-1.17`; this works generically for any `X.Y` version.
- Only repository **owners, members, and collaborators** may trigger these commands.
## General coding guidelines
+19 -1
View File
@@ -16,6 +16,11 @@ name: Backport merged pull request
# In both cases multiple target branches can be space-delimited in a comment:
# /backport release-1.17 release-1.18
#
# As a shorthand, a bare release version (e.g. `1.17`) is automatically
# expanded to the corresponding `release-1.17` branch, so `/backport 1.17`
# and `/backport release-1.17` are equivalent. This works generically for
# any `X.Y` version, e.g. `/backport 1.18 1.19`.
#
# See: https://github.com/velero-io/velero/issues/9603
on:
@@ -89,6 +94,10 @@ jobs:
fi
for branch in $branches; do
# Shorthand: a bare version like "1.17" expands to "release-1.17".
if [[ "$branch" =~ ^[0-9]+\.[0-9]+$ ]]; then
branch="release-${branch}"
fi
label="backport ${branch}"
echo "Applying label: '${label}'"
# Create the label if it does not exist yet (idempotent).
@@ -141,7 +150,16 @@ jobs:
# (may be empty, falls back to labels).
line=$(printf '%s' "$COMMENT_BODY" | head -n1 | tr -d '\r')
branches=$(printf '%s' "$line" | sed -E 's#^/(backport|cherrypick)[[:space:]]*##')
echo "branches=${branches}" >> "$GITHUB_OUTPUT"
normalized=""
for branch in $branches; do
# Shorthand: a bare version like "1.17" expands to "release-1.17".
if [[ "$branch" =~ ^[0-9]+\.[0-9]+$ ]]; then
branch="release-${branch}"
fi
normalized="${normalized}${normalized:+ }${branch}"
done
echo "branches=${normalized}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v7
with: