@@ -817,6 +817,21 @@ def find_editor():
817
817
error ('Could not find an editor! Set the EDITOR environment variable.' )
818
818
819
819
820
+ def _template_text_for_temp_file ():
821
+ text = template
822
+
823
+ # Ensure that there is a trailing space after '.. gh-issue:' to make
824
+ # filling in the template easier.
825
+ issue_line = ".. gh-issue:"
826
+ without_space = "\n " + issue_line + "\n "
827
+ with_space = "\n " + issue_line + " \n "
828
+ if without_space not in text :
829
+ sys .exit ("Can't find gh-issue line to ensure there's a space on the end!" )
830
+ text = text .replace (without_space , with_space )
831
+
832
+ return text
833
+
834
+
820
835
@subcommand
821
836
def add ():
822
837
"""
@@ -829,24 +844,9 @@ def add():
829
844
os .close (handle )
830
845
atexit .register (lambda : os .unlink (tmp_path ))
831
846
832
- def init_tmp_with_template ():
833
- with open (tmp_path , "wt" , encoding = "utf-8" ) as file :
834
- # hack:
835
- # my editor likes to strip trailing whitespace from lines.
836
- # normally this is a good idea. but in the case of the template
837
- # it's unhelpful.
838
- # so, manually ensure there's a space at the end of the gh-issue line.
839
- text = template
840
-
841
- issue_line = ".. gh-issue:"
842
- without_space = "\n " + issue_line + "\n "
843
- with_space = "\n " + issue_line + " \n "
844
- if without_space not in text :
845
- sys .exit ("Can't find gh-issue line to ensure there's a space on the end!" )
846
- text = text .replace (without_space , with_space )
847
- file .write (text )
848
-
849
- init_tmp_with_template ()
847
+ text = _template_text_for_temp_file ()
848
+ with open (tmp_path , "w" , encoding = "utf-8" ) as file :
849
+ file .write (text )
850
850
851
851
# We need to be clever about EDITOR.
852
852
# On the one hand, it might be a legitimate path to an
0 commit comments