lib/octopolo/github/pull_request_creator.rb in octopolo-0.2.1 vs lib/octopolo/github/pull_request_creator.rb in octopolo-0.3.0

- old
+ new

@@ -1,6 +1,7 @@ require_relative "../renderer" +require 'tempfile' module Octopolo module GitHub class PullRequestCreator include ConfigWrapper @@ -105,10 +106,31 @@ # Public: The body (primary copy) of the pull request # # Returns a String def body - Renderer.render Renderer::PULL_REQUEST_BODY, body_locals + output = Renderer.render Renderer::PULL_REQUEST_BODY, body_locals + output = edit_body(output) if options[:editor] + output + end + + def edit_body(body) + return body unless ENV['EDITOR'] + + # Open the file, write the contents, and close it + tempfile = Tempfile.new(['octopolo_pull_request', '.md']) + tempfile.write(body) + tempfile.close + + # Allow the user to edit the file + system "#{ENV['EDITOR']} #{tempfile.path}" + + # Reopen the file, read the contents, and delete it + tempfile.open + output = tempfile.read + tempfile.unlink + + output end # Public: The local variables to pass into the template def body_locals {