lib/thegarage/gitx/cli.rb in thegarage-gitx-1.4.1 vs lib/thegarage/gitx/cli.rb in thegarage-gitx-1.5.0.pre1
- old
+ new
@@ -18,21 +18,29 @@
super(*args)
RestClient.proxy = ENV['HTTPS_PROXY'] if ENV.has_key?('HTTPS_PROXY')
RestClient.log = Logger.new(STDOUT) if options[:trace]
end
- desc "reviewrequest", "Create a pull request on github"
+ desc "reviewrequest", "Create or update a pull request on github"
method_option :description, :type => :string, :aliases => '-d', :desc => 'pull request description'
method_option :assignee, :type => :string, :aliases => '-a', :desc => 'pull request assignee'
+ method_option :open, :type => :boolean, :aliases => '-o', :desc => 'open the pull request in a web browser'
# @see http://developer.github.com/v3/pulls/
def reviewrequest
update
+ fail 'Github authorization token not found' unless github.authorization_token
- changelog = run_cmd "git log #{Thegarage::Gitx::BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'* %s%n%b'"
- url = github.create_pull_request(current_branch, changelog, options)
- say 'Pull request created: '
- say url, :green
+ pull_request = github.find_pull_request(current_branch)
+ if pull_request.nil?
+ changelog = run_cmd "git log #{Thegarage::Gitx::BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'* %s%n%b'"
+ pull_request = github.create_pull_request(current_branch, changelog, options)
+ say 'Pull request created: '
+ say pull_request['html_url'], :green
+ end
+ github.assign_pull_request(pull_request, options[:assignee]) if options[:assignee]
+
+ run_cmd "open #{pull_request['html_url']}" if options[:open]
end
# TODO: use --no-edit to skip merge messages
# TODO: use pull --rebase to skip merge commit
desc 'update', 'Update the current branch with latest changes from the remote feature branch and master'
@@ -71,10 +79,10 @@
end
desc 'start', 'start a new git branch with latest changes from master'
def start(branch_name = nil)
unless branch_name
- example_branch = %w{ api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link }.sort_by { rand }.first
+ example_branch = %w{ api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link }.shuffle.first
repo = Grit::Repo.new(Dir.pwd)
remote_branches = repo.remotes.collect {|b| b.name.split('/').last }
until branch_name = ask("What would you like to name your branch? (ex: #{example_branch})") {|q|
q.validate = Proc.new { |branch|
branch =~ /^[A-Za-z0-9\-_]+$/ && !remote_branches.include?(branch)