7474python_data_script () {
7575 local SCRIPT=$1
7676 local OPT_ARG=$2
77-
77+
7878 $PYTHON_CMD -c "
7979try:
8080 import json
@@ -88,13 +88,21 @@ $SCRIPT
8888}
8989
9090json_escape () {
91- echo " $1 " | $PYTHON_CMD -c "
91+ $PYTHON_CMD -c "
9292import sys
9393try:
9494 import json
9595except ImportError:
9696 import simplejson as json
97- sys.stdout.write(json.dumps(sys.stdin.read().rstrip()))
97+ sys.stdout.write(json.dumps(sys.stdin.read().strip()))
98+ "
99+ }
100+
101+ make_tmp_file () {
102+ $PYTHON_CMD -c "
103+ import tempfile, sys
104+ _, path = tempfile.mkstemp()
105+ sys.stdout.write(path)
98106"
99107}
100108
@@ -106,6 +114,11 @@ BASE_BRANCH=`$GIT_CMD config --get gitOpenPull.base || echo "master"`
106114GITHUB_USER=` $GIT_CMD config --get github.user`
107115GITHUB_PASSWORD=` $GIT_CMD config --get github.password`
108116GITHUB_TOKEN=` $GIT_CMD config --get gitOpenPull.token`
117+ GIT_EDITOR=` $GIT_CMD config --get core.editor`
118+ if [ -z " $GIT_EDITOR " ]; then
119+ GIT_EDITOR=" $EDITOR "
120+ fi
121+
109122FEATURE_BRANCH=` $GIT_CMD rev-parse --abbrev-ref HEAD`
110123ISSUE_NUMBER=` echo $FEATURE_BRANCH | perl -p -e ' s/.*[-_]([0-9]+)$/\1/' `
111124if [ " $ISSUE_NUMBER " == " $FEATURE_BRANCH " ]; then
246259if [ -z " $ISSUE_NUMBER " ]; then
247260 read -p " enter issue number (or 'c' to create): " ISSUE_NUMBER
248261 if [ " $ISSUE_NUMBER " == " c" ]; then
249- read -p " issue title: " ISSUE_TITLE
250- read -p " issue description: " ISSUE_DESCRIPTION
251- ISSUE_TITLE=$( json_escape " $ISSUE_TITLE " )
252- ISSUE_DESCRIPTION=$( json_escape " $ISSUE_DESCRIPTION " )
262+
263+ EDITOR=${EDITOR:- vi}
264+ TMPFILE=$( make_tmp_file)
265+
266+ echo "
267+
268+ # Please enter a title and description for your new issue. The first
269+ # line will be used as the issue title, and any subsequent lines will
270+ # be used as the issue description.
271+ #
272+ # Lines starting with '#' will be ignored." > " $TMPFILE "
273+
274+ $GIT_EDITOR " $TMPFILE "
275+ if [ $? -ne 0 ]; then
276+ echo " error: there was a problem with the editor '$GIT_EDITOR '"
277+ exit 1
278+ fi
279+
280+ RAW_ISSUE=$( grep -v " ^#" " $TMPFILE " )
281+ rm " $TMPFILE "
282+ ISSUE_TITLE=$( echo " $RAW_ISSUE " | head -n 1)
283+ ISSUE_DESCRIPTION=$( echo " $RAW_ISSUE " | tail -n +2)
284+
285+ ISSUE_TITLE=$( echo " $ISSUE_TITLE " | json_escape)
286+ ISSUE_DESCRIPTION=$( echo " $ISSUE_DESCRIPTION " | json_escape)
287+
253288 endpoint=" https://api.github.com/repos/$BASE_ACCOUNT /$BASE_REPO /issues"
254289 json=" {\" title\" : $ISSUE_TITLE , \" body\" : $ISSUE_DESCRIPTION }"
255290 ISSUE_JSON=` curl --silent -H " Accept: application/vnd.github-issue.text+json,application/json" --data-binary " $json " " $endpoint ?access_token=$GITHUB_TOKEN " `
0 commit comments