From 210a798907fd920ffa72dfa44904288129266d48 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Thu, 15 Aug 2024 01:10:00 +1000 Subject: [PATCH] fix: Use CRLF When editing PRs in GitHub web, PR bodies use CRLF. But since gh-cli doesn't convert body inputs from LF to CRLF, this can lead to mixed LF/CRLF. Ideally we identify what a PR currently uses (if it was submitted via CLI or web), but simply using CRLF across the board isn't too bad either. Most modern text editors can handle both anyway. [1] https://github.com/actions/runner/issues/1462 --- README.md | 1 + gh-ph | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba7f9b4..d15a927 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - [`jq`](https://github.com/stedolan/jq) - [`bat`](https://github.com/sharkdp/bat) +- Command UNIX CLI utilities such as `tr`, `grep`, `sed`, etc. # Usage diff --git a/gh-ph b/gh-ph index edf0d14..3ebc8fe 100755 --- a/gh-ph +++ b/gh-ph @@ -97,6 +97,10 @@ function pager() { esac } +function unix2dos() { + tr -d $'\r' | sed 's/$/\r/' +} + PR_DETAILS="$(set -eo pipefail; gh pr view "$GH_PH_PULL_REQUEST_ID" --json baseRefName,body)" PR_BASE="$(set -eo pipefail; jq -r '.baseRefName' <<<"$PR_DETAILS")" PR_BODY="$(set -eo pipefail; jq -r '.body' <<<"$PR_DETAILS")" @@ -106,11 +110,11 @@ inject_history "$PR_BASE" <<<"$PR_BODY" | pager if read -r -n1 -p 'Update pull request body? [y/n] '; then printf '\n' if [[ "$REPLY" == 'y' ]]; then - inject_history "$PR_BASE" <<<"$PR_BODY" | gh pr edit "$GH_PH_PULL_REQUEST_ID" --body-file - + inject_history "$PR_BASE" <<<"$PR_BODY" | unix2dos | gh pr edit "$GH_PH_PULL_REQUEST_ID" --body-file - else printf 'Aborted\n' fi elif is_vim; then printf '\nVim detected\n' - inject_history "$PR_BASE" <<<"$PR_BODY" | gh pr edit "$GH_PH_PULL_REQUEST_ID" --body-file - + inject_history "$PR_BASE" <<<"$PR_BODY" | unix2dos | gh pr edit "$GH_PH_PULL_REQUEST_ID" --body-file - fi