Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/scripts/cherry-pick-to-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,29 @@ else

lookup_milestone "${VERSION}"

# Build the PR body using printf to avoid quoting pitfalls with embedded
# newlines (mixed $'...' and '...' quoting can leave literal \n in output).
CONFLICT_BODY="$(printf '%s' \
"Cherry-pick of #${PR_NUMBER} (${MERGE_COMMIT_SHA}) into " \
"\`${TARGET_BRANCH}\` **failed due to merge conflicts**." \
"${MILESTONE_NOTE}" \
$'\n\nPlease resolve manually:\n```bash\n' \
"git fetch origin" \
$'\n' \
"git checkout ${CHERRY_PICK_BRANCH}" \
$'\n' \
"${CHERRY_PICK_CMD}" \
$'\n' \
"# resolve conflicts" \
$'\n' \
"git push origin ${CHERRY_PICK_BRANCH} --force" \
$'\n```')"

gh pr create \
--draft \
--base "${TARGET_BRANCH}" \
--head "${CHERRY_PICK_BRANCH}" \
--title "[${VERSION} Cherry-pick - CONFLICTS] ${PR_TITLE}" \
${MILESTONE_ARG} \
--body $'Cherry-pick of #'"${PR_NUMBER}"' ('"${MERGE_COMMIT_SHA}"') into `'"${TARGET_BRANCH}"'` **failed due to merge conflicts**.'"${MILESTONE_NOTE}"$'\n\nPlease resolve manually:\n```bash\ngit fetch origin\ngit checkout '"${CHERRY_PICK_BRANCH}"'\n'"${CHERRY_PICK_CMD}"$'\n# resolve conflicts\ngit push origin '"${CHERRY_PICK_BRANCH}"' --force\n```'
--body "${CONFLICT_BODY}"
fi
49 changes: 49 additions & 0 deletions .github/scripts/tests/cherry-pick-to-release.bats
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,52 @@ STUB
# Should have created an empty commit.
grep -q "GIT: commit --allow-empty" "${STUB_DIR}/git.log"
}

@test "conflict PR body contains real newlines, not literal backslash-n" {
write_git_mock '
if [[ "$1" == "fetch" ]]; then exit 0; fi
if [[ "$1" == "cherry" ]]; then echo "+ abc123"; exit 0; fi
if [[ "$1" == "checkout" ]]; then exit 0; fi
if [[ "$1" == "rev-list" ]]; then echo "abc123def456 parent1"; exit 0; fi
if [[ "$1" == "cherry-pick" ]]; then
if [[ "$2" == "--abort" ]]; then exit 0; fi
exit 1
fi
if [[ "$1" == "commit" ]]; then exit 0; fi
if [[ "$1" == "push" ]]; then exit 0; fi
exit 0
'
# Capture the full --body argument to a file for inspection.
write_gh_mock '
if [[ "$1" == "api" ]]; then echo "7.0.1"; exit 0; fi
if [[ "$1" == "pr" && "$2" == "create" ]]; then
while [[ $# -gt 0 ]]; do
if [[ "$1" == "--body" ]]; then
printf "%s" "$2" > "'"${STUB_DIR}"'/pr-body.txt"
break
fi
shift
done
exit 0
fi
exit 0
'

run bash "${SCRIPT}"
[ "$status" -eq 0 ]

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

The PR’s stated behavior change is that conflict PRs are created as drafts, but this new test only inspects the --body argument. Add an assertion that gh pr create was invoked with --draft (e.g., via ${STUB_DIR}/gh.log) so the behavior is covered and won’t regress.

Suggested change
# gh pr create must have been logged and invoked with --draft.
[ -f "${STUB_DIR}/gh.log" ]
grep -F -- "--draft" "${STUB_DIR}/gh.log"

Copilot uses AI. Check for mistakes.
# The body file must exist (gh pr create was called with --body).
[ -f "${STUB_DIR}/pr-body.txt" ]

local body
body="$(cat "${STUB_DIR}/pr-body.txt")"

# Must NOT contain literal two-character sequence '\n'.
[[ "$body" != *'\\n'* ]]
# Each command in the code block must be on its own line.
[[ "$body" == *$'\ngit fetch origin\n'* ]]
[[ "$body" == *$'\ngit checkout dev/automation/pr-42-to-7.0.1\n'* ]]
[[ "$body" == *$'\ngit cherry-pick abc123def456\n'* ]]
[[ "$body" == *$'\n# resolve conflicts\n'* ]]
[[ "$body" == *$'\ngit push origin dev/automation/pr-42-to-7.0.1 --force\n'* ]]
}
Loading