Sha256: 5f86a6e4f01228c3938e2d32b8aaea75baf4999380c4daf4909147e2c4534fce

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

desc 'review will push your latest feature branch changes to your remote repo and create a pull request'
arg_name 'Describe arguments to review here'
command :review do |c|
  c.desc 'push your latest feature branch changes to your remote repo and create a pull request against the destination branch'
  c.arg_name '[destination_branch] - the branch you want to merge your feature branch into'
  c.flag [:t, :title], default_value: 'last commit message'
  c.flag [:m, :message], default_value: 'title'
  c.action do |global_options,options,args|
    pull_request_msg_file = "#{GitReflow.git_root_dir}/.git/GIT_REFLOW_PR_MSG"

    if global_options[:title] || global_options[:message]
      review_options = {
        'base' => args[0],
        'title' => (global_options[:title]   || GitReflow.current_branch),
        'body' =>  global_options[:message]
      }
    else
      default_editor = "#{ENV['EDITOR']}"
      if default_editor.empty?
        default_editor = 'vi'
      end

      File.open(pull_request_msg_file, 'w') do |file|
        file.write(GitReflow.current_branch)
      end

      GitReflow.run("#{default_editor} #{pull_request_msg_file}", with_system: true)

      pr_msg = File.open(pull_request_msg_file).each_line.map(&:strip).to_a
      title  = pr_msg.shift

      File.delete(pull_request_msg_file)

      unless pr_msg.empty? 
        pr_msg.shift if pr_msg.first.empty?
      end

      review_options = {'base' => args[0],'title' => title,'body' =>  pr_msg.join("\n")}
    end

    puts "\nReview your PR:\n"
    puts "--------\n"
    puts "Title:\n#{review_options['title']}\n\n"
    puts "Body:\n#{review_options['body']}\n"
    puts "--------\n"
    GitReflow.review(review_options) unless ask("Submit pull request? (Y)") =~ /n/i
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_reflow-0.6.5 lib/git_reflow/commands/review.rb
git_reflow-0.6.4 lib/git_reflow/commands/review.rb
git_reflow-0.6.3 lib/git_reflow/commands/review.rb