Class: Gerrit::Command::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/gerrit/command/push.rb

Overview

Push one or more commits for review.

Instance Method Summary collapse

Methods inherited from Base

#execute_command, from_arguments, #initialize, #run

Methods included from Utils

camel_case, commit_hash?, human_time, map_in_parallel, snake_case

Constructor Details

This class inherits a constructor from Gerrit::Command::Base

Instance Method Details

#executeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gerrit/command/push.rb', line 4

def execute
  # Sanity check: does this repository have a valid remote_url?
  # (this will raise an exception if that's not the case)
  remote_url = repo.remote_url

  # If an explicit ref is given, skip a bunch of the questions
  if commit_hash?(arguments[1]) || arguments[1] == 'HEAD'
    ref = arguments[1]
    reviewer_args = arguments[2..-1] || []
    type = 'publish'
    topic = nil
    target_branch = 'master'
  else
    ref = 'HEAD'
    reviewer_args = arguments[1..-1] || []
    type = ask_review_type
    topic = ask_topic
    target_branch = ask_target_branch
  end

  reviewers = extract_reviewers(reviewer_args)

  if reviewers.size >= @config.fetch(:warn_reviewer_count, 4)
    ui.newline
    ui.info("You are adding #{reviewers.size} people as reviewers for this change")

    reviewers.each do |username|
      ui.print username
    end

    until %w[y n].include?(answer = ui.ask('Is this ok? (y/n) ')
                                      .argument(:required)
                                      .modify(:downcase)
                                      .read_string)
    end

    return unless answer == 'y'
  end

  push_changes(remote_url, ref, reviewers, target_branch, type, topic)
end