-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(backport): fetch original PR description
Backport PR will fetch the original PR description and other content and amend the backport PR description with it.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,34 @@ jobs: | |
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport')) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install GH CLI | ||
uses: dev-hanz-ops/[email protected] | ||
|
||
- name: Fetch PR description and update backportrc | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
REPO: ${{ github.repository }} | ||
run: | | ||
# Grab raw original PR body, gh CLI uses the default token. | ||
BODY_CONTENT="$(gh api "/repos/$REPO/pulls/$PR_NUMBER" | jq -r .body)" | ||
# Escape the markdown content so that sed can produce valid JSON. | ||
# Remove starting and ending quites and replace new lines with literals. | ||
ESCAPED_CONTENT=$(echo "$BODY_CONTENT" | jq -aRs .) | ||
ESCAPED_CONTENT="${ESCAPED_CONTENT%\"}" | ||
ESCAPED_CONTENT="${ESCAPED_CONTENT#\"}" | ||
ESCAPED_CONTENT=$(echo "$ESCAPED_CONTENT" | sed 's/[\/&]/\\&/g') | ||
# sourcePullRequest is an actual variable, but the PR description is not provided byt the action or the CLI. | ||
# Instead we are using it as a substitution target and replacing it with the markdown content. | ||
sed -i "s/{{sourcePullRequest}}/$ESCAPED_CONTENT/g" .backportrc.json | ||
- name: Backport Action | ||
uses: sorenlouv/[email protected] | ||
with: | ||
|