Skip to content

Commit eff4b24

Browse files
committed
Merge pull request #24 from jehiah/create_issue_with_editor_24
use $EDITOR to create new issues
2 parents 126bbcf + 0837547 commit eff4b24

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

git-open-pull

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fi
7474
python_data_script() {
7575
local SCRIPT=$1
7676
local OPT_ARG=$2
77-
77+
7878
$PYTHON_CMD -c "
7979
try:
8080
import json
@@ -88,13 +88,21 @@ $SCRIPT
8888
}
8989

9090
json_escape() {
91-
echo "$1" | $PYTHON_CMD -c "
91+
$PYTHON_CMD -c "
9292
import sys
9393
try:
9494
import json
9595
except 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"`
106114
GITHUB_USER=`$GIT_CMD config --get github.user`
107115
GITHUB_PASSWORD=`$GIT_CMD config --get github.password`
108116
GITHUB_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+
109122
FEATURE_BRANCH=`$GIT_CMD rev-parse --abbrev-ref HEAD`
110123
ISSUE_NUMBER=`echo $FEATURE_BRANCH | perl -p -e 's/.*[-_]([0-9]+)$/\1/'`
111124
if [ "$ISSUE_NUMBER" == "$FEATURE_BRANCH" ]; then
@@ -246,10 +259,32 @@ fi
246259
if [ -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

Comments
 (0)