@@ -91,12 +91,21 @@ if sys.argv[1] == "json_escape":
9191 # take either a second argument, or stdin
9292 input_txt = None
9393 if len(sys.argv) > 2:
94- input_txt = sys.argv[2]
94+ input_txt = sys.argv[2].strip()
9595 else:
9696 input_txt = sys.stdin.read().strip()
9797 sys.stdout.write(json.dumps(input_txt))
9898 sys.exit(0)
9999
100+ if sys.argv[1] == "selected_labels":
101+ labels = []
102+ for line in open(sys.argv[2], "r"):
103+ if line.lstrip().startswith("Label:"):
104+ labels.append(line.strip()[6:].strip())
105+ if labels:
106+ sys.stdout.write(json.dumps(labels))
107+ sys.exit(0)
108+
100109# all following commands take a json blob as the second argument
101110data = json.loads(sys.argv[2].replace("\r","").replace("\n",""))
102111
@@ -128,6 +137,13 @@ if sys.argv[1] == "check_pull_request":
128137 print("Pull Request Opened")
129138 print(pull_link)
130139
140+ if sys.argv[1] == "format_labels":
141+ labels = [x["name"] for x in data]
142+ if labels:
143+ print ("\n# Uncomment to assign labels\n")
144+ for name in labels:
145+ print("# Label: %s" % name)
146+
131147' " $@ "
132148}
133149
@@ -282,24 +298,33 @@ if [ -z "$ISSUE_NUMBER" ]; then
282298 read -p " enter issue number (or 'c' to create): " ISSUE_NUMBER
283299 if [ " $ISSUE_NUMBER " == " c" ]; then
284300
285- TMPFILE=$( make_tmp_file)
301+ TMPFILE=$( make_tmp_file)
302+
303+ echo "
286304
287- echo "
305+ " > " $TMPFILE "
288306
307+ endpoint=" https://api.github.com/repos/$BASE_ACCOUNT /$BASE_REPO /labels"
308+ REPO_LABELS_JSON=` curl --silent -H " Accept: application/json" " $endpoint ?access_token=$GITHUB_TOKEN " `
309+ python_helper format_labels " $REPO_LABELS_JSON " >> " $TMPFILE "
310+
311+ echo "
289312# Please enter a title and description for your new issue. The first
290313# line will be used as the issue title, and any subsequent lines will
291314# be used as the issue description.
292315#
293- # Lines starting with '#' will be ignored." > " $TMPFILE "
316+ # Lines starting with '#' will be ignored." >> " $TMPFILE "
294317
295318 $GIT_EDITOR " $TMPFILE "
296319 if [ $? -ne 0 ]; then
297320 echo " error: there was a problem with the editor '$GIT_EDITOR '"
298321 exit 1
299322 fi
300323
301- RAW_ISSUE=$( grep -v " ^#" " $TMPFILE " )
324+ RAW_ISSUE=$( egrep -v " ^(#|\s?Label:)" " $TMPFILE " )
325+ SELECTED_LABELS=$( python_helper selected_labels " $TMPFILE " )
302326 rm " $TMPFILE "
327+
303328 ISSUE_TITLE=$( echo " $RAW_ISSUE " | head -n 1)
304329 ISSUE_DESCRIPTION=$( echo " $RAW_ISSUE " | tail -n +2)
305330
@@ -316,6 +341,12 @@ if [ -z "$ISSUE_NUMBER" ]; then
316341 fi
317342
318343 echo " created issue $ISSUE_NUMBER "
344+
345+ if [ -n " $SELECTED_LABELS " ]; then
346+ endpoint=" https://api.github.com/repos/$BASE_ACCOUNT /$BASE_REPO /issues/$ISSUE_NUMBER /labels"
347+ LABEL_CHANGE_JSON=` curl --silent -H " Accept: application/json" --data-binary " $SELECTED_LABELS " " $endpoint ?access_token=$GITHUB_TOKEN " `
348+ echo " set labels $SELECTED_LABELS "
349+ fi
319350 fi
320351else
321352 read -p " issue number [$ISSUE_NUMBER ]: " temp
0 commit comments