Skip to content

Commit

Permalink
fix: Use CRLF
Browse files Browse the repository at this point in the history
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] actions/runner#1462
  • Loading branch information
Frederick888 committed Aug 14, 2024
1 parent c0bbb6a commit 210a798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions gh-ph
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand All @@ -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

0 comments on commit 210a798

Please sign in to comment.