Reputation: 1172
I am doing this:
pull_request() {
local url="$1"
local title="$2"
local message=$(cat <<-END
$title\n
\n
- [Story]($url)
END
)
echo $message
local pr_url=$(hub pull-request -m "$message")
open $pr_url
}
I want this to be in the description:
- [Story](...url)
And the title to be some single-line thing. Instead the title is saying:
test\n \n - [Story](...url) END
When I run:
pull_request "...url" "test"
How do I set the description using the hub tool?
Upvotes: 1
Views: 432
Reputation: 13953
Since you are not quoting $message
in the echo-call, the output is shown on a single line. Use echo "$message"
to preserve the newlines. It is not necessary to use \n
since newlines are stored directly when using Heredoc. Actually, they are treated as normal text.
According to the documentation, "The text up to the first blank line in the message is treated as the pull request title, and the rest is used as pull request description in Markdown format." Because you have no blank line (remember \n
are not interpreted as newlines), the description never starts and everything ends up in the title.
To fix this, remove the unnecessary \n
and make sure there is a blank line after the title. Additionally, I suggest to use the --browse
argument of hub pull-request to automatically open the PR in the browser. By wrapping the call to hub you might mask other output (like authentication) and don't end up with the URL in the variable in all cases.
Here is a working script (make-pr.sh
):
#!/bin/bash
pull_request() {
local url="$1"
local title="$2"
local message=$(cat <<-END
$title
- [Story]($url)
END
)
echo "$message"
hub pull-request --browse -m "$message"
}
pull_request "$@"
Example:
$ ./make-pr.sh "https://abc.tld" "A nice title"
A nice title
- [Story](https://abc.tld)
Upvotes: 1