Skip to content

Commit e0803d1

Browse files
committed
Extract comment_pr helper in backport workflow
Collapse the three near-identical gh pr comment call sites into a single comment_pr helper, centralizing the best-effort (|| true) semantics in one place. No behavioral change.
1 parent 0f17f1d commit e0803d1

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

.github/workflows/backport-pr.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jobs:
7171
run: |
7272
set -euo pipefail
7373
74+
# Best-effort PR comment; a comment failure must never fail the backport.
75+
comment_pr() { gh pr comment "${PR_NUMBER}" --repo "${REPO}" --body "$1" || true; }
76+
7477
if [ -z "${MERGE_SHA}" ]; then
7578
echo "::error::merge_commit_sha is empty; cannot backport."
7679
exit 1
@@ -111,8 +114,7 @@ jobs:
111114
# Ensure origin/<base> exists locally for the worktree; a missing branch fails just this base, not the run.
112115
if ! git fetch --no-tags origin "+refs/heads/${base}:refs/remotes/origin/${base}"; then
113116
echo "::error::Target branch ${base} does not exist on origin; skipping."
114-
gh pr comment "${PR_NUMBER}" --repo "${REPO}" \
115-
--body "⚠️ Automatic backport to \`${base}\` skipped: the target branch does not exist." || true
117+
comment_pr "⚠️ Automatic backport to \`${base}\` skipped: the target branch does not exist."
116118
overall_rc=1
117119
continue
118120
fi
@@ -126,13 +128,11 @@ jobs:
126128
pr_url="$(gh pr list --repo "${REPO}" --head "${branch}" --state open --json url --jq '.[0].url // ""' || true)"
127129
echo "::notice::Opened backport PR for ${base}: ${pr_url}"
128130
if [ -n "${pr_url}" ]; then
129-
gh pr comment "${PR_NUMBER}" --repo "${REPO}" \
130-
--body "Backport to \`${base}\` opened: ${pr_url}" || true
131+
comment_pr "Backport to \`${base}\` opened: ${pr_url}"
131132
fi
132133
else
133134
echo "::error::Backport to ${base} failed."
134-
gh pr comment "${PR_NUMBER}" --repo "${REPO}" \
135-
--body "⚠️ Automatic backport to \`${base}\` failed. See the [workflow run](${RUN_URL}) for details, or backport manually with \`ddev release port-commit PR-${PR_NUMBER} --target-branch ${base}\`." || true
135+
comment_pr "⚠️ Automatic backport to \`${base}\` failed. See the [workflow run](${RUN_URL}) for details, or backport manually with \`ddev release port-commit PR-${PR_NUMBER} --target-branch ${base}\`."
136136
overall_rc=1
137137
fi
138138
echo "::endgroup::"

0 commit comments

Comments
 (0)