Skip to content

Commit 5c3e66c

Browse files
committed
Allow the PR repo to be controlled.
1 parent 1668431 commit 5c3e66c

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

.github/workflows/backport.yml

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,41 @@ on:
44
workflow_dispatch:
55
inputs:
66
end_branch:
7-
description: 'The branch to end at (e.g. 4.7). Defaults to the oldest branch receiving security updates.'
7+
description: 'The branch to end at (e.g. 6.9). Defaults to the current supported branch.'
88
required: false
99
type: string
10-
default: '4.7'
10+
default: '7.0'
1111
pr-name:
12-
description: 'The name for the pull requests. When provided, PRs are titled "<name> - <branch> branch".'
12+
description: 'Pull request name (format is "<pr-name> - <branch> branch".'
1313
required: false
1414
type: string
1515
default: ''
1616
commit-sha:
17-
description: 'The full length commit hash to cherry-pick. When provided, PR numbers are ignored.'
17+
description: 'Full length commit hash to stage for backport.'
1818
required: false
1919
type: string
2020
default: ''
2121
pr_numbers:
22-
description: 'Comma-separated PR numbers. Each PR is merged as a single commit using the PR title as the commit message. Ignored when a commit SHA is provided.'
22+
description: 'Comma-separated PR numbers. Ignored when a SHA is provided.'
2323
required: false
2424
type: string
2525
default: ''
26-
pr-source:
27-
description: 'The repository the PR numbers belong to.'
26+
repo-source:
27+
description: 'Repository to stage changes from.'
2828
required: false
2929
type: choice
3030
default: 'upstream'
3131
options:
3232
- upstream
3333
- current
34+
pr-target:
35+
description: 'Repository to submit pull requests to.'
36+
required: false
37+
type: choice
38+
default: 'current'
39+
options:
40+
- upstream
41+
- current
3442

3543
# Disable permissions for all available scopes by default.
3644
# Any needed permissions should be configured at the job level.
@@ -163,9 +171,9 @@ jobs:
163171
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164172
STEPS_UPSTREAM_OUTPUTS_REPO: ${{ steps.upstream.outputs.repo }}
165173
INPUTS_PR_NUMBERS: ${{ inputs.pr_numbers }}
166-
INPUTS_PR_SOURCE: ${{ inputs.pr-source }}
174+
INPUTS_REPO_SOURCE: ${{ inputs.repo-source }}
167175
run: |
168-
if [ "${INPUTS_PR_SOURCE}" = "upstream" ]; then
176+
if [ "${INPUTS_REPO_SOURCE}" = "upstream" ]; then
169177
PR_REPO="${STEPS_UPSTREAM_OUTPUTS_REPO}"
170178
else
171179
PR_REPO="${GITHUB_REPOSITORY}"
@@ -223,10 +231,11 @@ jobs:
223231
MATRIX_BRANCH: ${{ matrix.branch }}
224232
INPUTS_COMMIT_SHA: ${{ inputs.commit-sha }}
225233
INPUTS_PR_NUMBERS: ${{ inputs.pr_numbers }}
226-
INPUTS_PR_SOURCE: ${{ inputs.pr-source }}
234+
INPUTS_REPO_SOURCE: ${{ inputs.repo-source }}
235+
INPUTS_PR_TARGET: ${{ inputs.pr-target }}
227236
STEPS_BACKPORT_BRANCH_OUTPUTS_NAME: ${{ steps.backport-branch.outputs.name }}
228237
run: |
229-
if [ "${INPUTS_PR_SOURCE}" = "upstream" ]; then
238+
if [ "${INPUTS_REPO_SOURCE}" = "upstream" ]; then
230239
PR_REPO="${STEPS_UPSTREAM_OUTPUTS_REPO}"
231240
else
232241
PR_REPO="${GITHUB_REPOSITORY}"
@@ -241,10 +250,10 @@ jobs:
241250
if [ -n "${INPUTS_COMMIT_SHA}" ]; then
242251
BODY="This pull request backports \`${INPUTS_COMMIT_SHA}\` (https://github.com/${STEPS_UPSTREAM_OUTPUTS_REPO}/commit/${INPUTS_COMMIT_SHA}) to the \`${MATRIX_BRANCH}\` branch."
243252
else
244-
BODY="Backport to the \`${MATRIX_BRANCH}\` branch."
253+
BODY="Backports to the \`${MATRIX_BRANCH}\` branch."
245254
fi
246255
247-
BODY="${BODY}\n\n## Changes\n"
256+
BODY="${BODY}\n\n## Changes Included\n"
248257
249258
if [ -n "${INPUTS_COMMIT_SHA}" ]; then
250259
COMMIT_MESSAGE=$(git log --format=%B -n 1 "${INPUTS_COMMIT_SHA}")
@@ -260,9 +269,18 @@ jobs:
260269
done
261270
fi
262271
272+
if [ "${INPUTS_PR_TARGET}" = "upstream" ]; then
273+
PR_REPO="${STEPS_UPSTREAM_OUTPUTS_REPO}"
274+
PR_HEAD="${GITHUB_REPOSITORY_OWNER}:${STEPS_BACKPORT_BRANCH_OUTPUTS_NAME}"
275+
else
276+
PR_REPO="${GITHUB_REPOSITORY}"
277+
PR_HEAD="${STEPS_BACKPORT_BRANCH_OUTPUTS_NAME}"
278+
fi
279+
263280
gh pr create \
281+
--repo "${PR_REPO}" \
264282
--base "${MATRIX_BRANCH}" \
265-
--head "${STEPS_BACKPORT_BRANCH_OUTPUTS_NAME}" \
283+
--head "${PR_HEAD}" \
266284
--title "$PR_TITLE" \
267285
--assignee "${GITHUB_ACTOR}" \
268286
--body "$(echo -e "$BODY")"

0 commit comments

Comments
 (0)