gerrit 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d050a0ac17abfa314ecaa5b6fd07037499f8e471
4
- data.tar.gz: 72446d0641f5ed8ca4e4963234b126166e01f36a
3
+ metadata.gz: b3eefb2813d2ee8ef4a5483b89e24452b8be748e
4
+ data.tar.gz: 4931198fab15caed1fed6611833a054c3090a3ff
5
5
  SHA512:
6
- metadata.gz: 9dd2197c2035696ea52a8cf13595b88ecdcbaabeb2dfede9d60299f11d3097b54bf7e3ae7843d3dae75984433c0dd4b6b1f4bbc66384369c3f82af3fa62bcbb0
7
- data.tar.gz: 6b403e7c5c7dae06f10734d94a8de8a681f484f701946634b042b8c8ca71586e33e85b90b6267c7bc472655d956642a25a4baad72b6355d986d78edf0c09ef99
6
+ metadata.gz: 6c11d9e7fdb707dc9008c2b1391a16afc7f4c02c64159b34a7dd718b7b3b9f00cfce99a953c9a34a65d16c4ed5c1acbdae983b2a7ed22579649670edbd59a916
7
+ data.tar.gz: 964136850e519b217c5e4f25c240832b24e123b1edea216f824d73569de591653b9a4e0ab64400c4145eb0c32fb8142319682f89fb36af418bf5ea8404aa8049
data/lib/gerrit/cli.rb CHANGED
@@ -47,26 +47,8 @@ module Gerrit
47
47
  # Display all open changes by default
48
48
  arguments = ['list'] if arguments.empty?
49
49
 
50
- command_class = find_command(arguments)
51
- command_class.new(config, @ui, arguments).run
52
- end
53
-
54
- # Finds the {Command} corresponding to the given set of arguments.
55
- #
56
- # @param [Array<String>] arguments
57
- # @return [Class]
58
- def find_command(arguments)
59
- cmd = arguments.first
60
-
61
- begin
62
- require 'gerrit/command/base'
63
- require "gerrit/command/#{Utils.snake_case(cmd)}"
64
- rescue LoadError => ex
65
- raise Errors::CommandInvalidError,
66
- "`gerrit #{cmd}` is not a valid command"
67
- end
68
-
69
- Command.const_get(Utils.camel_case(cmd))
50
+ require 'gerrit/command/base'
51
+ Command::Base.from_arguments(config, @ui, arguments).run
70
52
  end
71
53
  end
72
54
  end
@@ -7,6 +7,26 @@ module Gerrit::Command
7
7
  class Base
8
8
  include Gerrit::Utils
9
9
 
10
+ # Create a command from a list of arguments.
11
+ #
12
+ # @param config [Gerrit::Configuration]
13
+ # @param ui [Gerrit::UI]
14
+ # @param arguments [Array<String>]
15
+ # @return [Gerrit::Command::Base] appropriate command for the given
16
+ # arguments
17
+ def self.from_arguments(config, ui, arguments)
18
+ cmd = arguments.first
19
+
20
+ begin
21
+ require "gerrit/command/#{Gerrit::Utils.snake_case(cmd)}"
22
+ rescue LoadError => ex
23
+ raise Gerrit::Errors::CommandInvalidError,
24
+ "`gerrit #{cmd}` is not a valid command"
25
+ end
26
+
27
+ Gerrit::Command.const_get(Gerrit::Utils.camel_case(cmd)).new(config, ui, arguments)
28
+ end
29
+
10
30
  # @param config [Gerrit::Configuration]
11
31
  # @param ui [Gerrit::UI]
12
32
  # @param arguments [Array<String>]
@@ -28,6 +48,13 @@ module Gerrit::Command
28
48
  raise NotImplementedError, 'Define `execute` in Command subclass'
29
49
  end
30
50
 
51
+ # Executes another command from the same context as this command.
52
+ #
53
+ # @param command_arguments [Array<String>]
54
+ def execute_command(command_arguments)
55
+ self.class.from_arguments(config, ui, command_arguments).execute
56
+ end
57
+
31
58
  private
32
59
 
33
60
  # @return [Array<String>]
@@ -0,0 +1,71 @@
1
+ module Gerrit::Command
2
+ # Clone a Gerrit project and set up its remotes to push/pull from Gerrit.
3
+ class Clone < Base
4
+ def execute
5
+ unless config[:push_remote]
6
+ raise ConfigurationInvalidError,
7
+ 'Missing `push_remote` option in your configuration'
8
+ end
9
+
10
+ unless config[:remotes]
11
+ raise ConfigurationInvalidError,
12
+ 'Missing `remotes` option in your configuration'
13
+ end
14
+
15
+ unless config[:remotes][config[:push_remote]]
16
+ raise ConfigurationInvalidError,
17
+ "Missing `#{config[:push_remote]}` remote in your `remotes` configuration"
18
+ end
19
+
20
+ project_name = project
21
+
22
+ remote_url = config[:remotes][config[:push_remote]]['url'] % {
23
+ user: config[:user],
24
+ host: config[:host],
25
+ port: config[:port],
26
+ project: project_name,
27
+ }
28
+
29
+ clone(remote_url, project_name)
30
+ end
31
+
32
+ private
33
+
34
+ def clone(remote_url, project)
35
+ p = Pastel.new
36
+
37
+ result =
38
+ ui.spinner("Cloning #{p.magenta(project)} from #{p.cyan(remote_url)}...") do
39
+ spawn(%W[git clone #{remote_url}])
40
+ end
41
+
42
+ project_dir = File.join(Dir.pwd, project)
43
+
44
+ if result.success?
45
+ ui.success("#{project} successfully cloned into #{project_dir}")
46
+ ui.newline
47
+ setup_remotes(project_dir)
48
+ else
49
+ ui.error(result.stdout + result.stderr)
50
+ end
51
+ end
52
+
53
+ def project
54
+ if arguments[1]
55
+ arguments[1]
56
+ else
57
+ ui.ask('Enter name of the Gerrit project would you like to clone: ')
58
+ .argument(:required)
59
+ .read_string
60
+ end
61
+ end
62
+
63
+ def setup_remotes(repo_directory)
64
+ Dir.chdir(repo_directory) do
65
+ # Remove default remote so we can set up Gerrit remotes
66
+ `git remote rm origin`
67
+ execute_command(%w[setup])
68
+ end
69
+ end
70
+ end
71
+ end
@@ -2,11 +2,7 @@ module Gerrit::Command
2
2
  # Show a list of changes matching a specified query.
3
3
  class List < Base
4
4
  def execute
5
- # Get changes ordered from newest to oldest
6
- changes =
7
- ui.spinner('Loading ') do
8
- client.query_changes(query).sort_by { |change| -change['lastUpdated'] }
9
- end
5
+ changes = ui.spinner('Loading ') { self.class.find_changes(client, query) }
10
6
 
11
7
  # Display changes in reverse order so that the newest are at the bottom of
12
8
  # the table (i.e. the part that will be visible in a console when there is
@@ -30,6 +26,15 @@ module Gerrit::Command
30
26
  end
31
27
  end
32
28
 
29
+ # HACK: We cache the results of this since we may want to reuse the result
30
+ # of the query in other commands (see Command::Submit for an example).
31
+ # We also make this a public class method so other commands can call it.
32
+ def self.find_changes(client, search_query)
33
+ @matching_changes ||= {}
34
+ @matching_changes[search_query] =
35
+ client.query_changes(search_query).sort_by { |change| -change['lastUpdated'] }
36
+ end
37
+
33
38
  private
34
39
 
35
40
  def query
@@ -0,0 +1,42 @@
1
+ module Gerrit::Command
2
+ # Display a list of submittable changes and ask the user which to submit.
3
+ class Submit < Base
4
+ # Default search query that assumes a change is submittable if there is at
5
+ # least one +1 for both Code-Review and Verified labels and no -1s.
6
+ DEFAULT_SEARCH_QUERY = %w[
7
+ is:open
8
+ label:Code-Review+1
9
+ label:Verified+1
10
+ NOT label:Code-Review-1
11
+ NOT label:Verified-1
12
+ ].join(' ')
13
+
14
+ def execute
15
+ list_query = config.fetch('submittable_changes', DEFAULT_SEARCH_QUERY)
16
+ execute_command(['list', list_query])
17
+
18
+ # This will return a cached result from Command::List
19
+ changes = Gerrit::Command::List.find_changes(client, list_query)
20
+
21
+ index = 0
22
+ while index < 1 || index > changes.size
23
+ range = changes.size == 1 ? '' : "(1 - #{changes.size})"
24
+ index = ui.ask("Which change would you like to submit? #{range} ")
25
+ .argument(:required)
26
+ .read_int
27
+ end
28
+
29
+ submit_change(changes[index - 1])
30
+ end
31
+
32
+ private
33
+
34
+ def submit_change(change)
35
+ p = Pastel.new
36
+ description = p.cyan("#{change['subject']}") + p.green(" (##{change['number']})")
37
+ ui.spinner("Submitting #{description}...") do
38
+ ui.print(client.execute(%W[review change:#{change['number']} --submit]))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module Gerrit
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gerrit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess
@@ -80,6 +80,7 @@ files:
80
80
  - lib/gerrit/client.rb
81
81
  - lib/gerrit/command/base.rb
82
82
  - lib/gerrit/command/checkout.rb
83
+ - lib/gerrit/command/clone.rb
83
84
  - lib/gerrit/command/console.rb
84
85
  - lib/gerrit/command/groups.rb
85
86
  - lib/gerrit/command/help.rb
@@ -88,6 +89,7 @@ files:
88
89
  - lib/gerrit/command/projects.rb
89
90
  - lib/gerrit/command/push.rb
90
91
  - lib/gerrit/command/setup.rb
92
+ - lib/gerrit/command/submit.rb
91
93
  - lib/gerrit/command/version.rb
92
94
  - lib/gerrit/configuration.rb
93
95
  - lib/gerrit/constants.rb