gitlab 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88679bf87230b7d3d6bb8f0e96fb779967936216
4
- data.tar.gz: 6c41b6c43280434257bc160aa38963ef50a4cc72
3
+ metadata.gz: e1eec826134f7f158d272a521a17b9c52462563b
4
+ data.tar.gz: ce91d8223ae73ab6194680ac023919beb6178286
5
5
  SHA512:
6
- metadata.gz: ae58eefafd56dba8d8b87029c89972d036c479d3a3d15b6a7196e08495d9325de841a1860cb29151dd879aa05bee8fef1f340118d6309b520532804615b464d9
7
- data.tar.gz: a96ddd98eebc816f295856c6996b1b29462c9a236d4a1d67b5c6259dc00e7f1b7b08bbf395c7bc69d1b8983e7be990ca2cda9a143c218f33dab3d3df8134731f
6
+ metadata.gz: 2c64f4ef7633db83324ccd32a14ee073a437339b40e9cf8c58a0691a558dc09a4a9f8b24cf68cb86ef5b6b25a49d8d110113e9d32c8988bf2dbf2b6d4e09a047
7
+ data.tar.gz: 34d73c1a2b04ffb4339dbfb634d73f0a337a0d8919b851808d967d3c06dcb7327a93b82786dac59a64b8d6b99e0815c1ddf522f8272570d5535593e7513f333f
data/README.md CHANGED
@@ -28,18 +28,22 @@ Configuration example:
28
28
 
29
29
  ```ruby
30
30
  Gitlab.configure do |config|
31
- config.endpoint = 'https://example.net/api/v3' # API endpoint URL (required)
32
- config.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token (required)
33
- config.user_agent = 'Custom User Agent' # user agent, default to 'Gitlab Ruby Gem [version]' (optional)
31
+ config.endpoint = 'https://example.net/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
32
+ config.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
33
+ # Optional
34
+ # config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
35
+ # config.sudo = 'user' # username for sudo mode, default: nil
34
36
  end
35
37
  ```
36
38
 
39
+ (Note: If you are using Gitlab.com's hosted service, your endpoint will be `https://gitlab.com/api/v3`)
40
+
37
41
  Usage examples:
38
42
 
39
43
  ```ruby
40
44
  # set an API endpoint
41
45
  Gitlab.endpoint = 'http://example.net/api/v3'
42
- # => "http://example.net/api/v2"
46
+ # => "http://example.net/api/v3"
43
47
 
44
48
  # set a user private token
45
49
  Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
@@ -92,6 +96,24 @@ gitlab user --only=id,username
92
96
  gitlab user --except=email,bio
93
97
  ```
94
98
 
99
+ ## CLI Shell
100
+
101
+ Usage examples:
102
+
103
+ ```sh
104
+ # start shell session
105
+ gitlab shell
106
+
107
+ # list available commands
108
+ gitlab> help
109
+
110
+ # list groups
111
+ gitlab> groups
112
+
113
+ # protect a branch
114
+ gitlab> protect_branch 1 master
115
+ ```
116
+
95
117
  For more information, refer to [website](http://narkoz.github.io/gitlab).
96
118
 
97
119
  ## License
@@ -1,6 +1,7 @@
1
1
  require 'gitlab'
2
2
  require 'terminal-table/import'
3
3
  require_relative 'cli_helpers'
4
+ require_relative 'shell'
4
5
 
5
6
  class Gitlab::CLI
6
7
  extend Helpers
@@ -23,8 +24,10 @@ class Gitlab::CLI
23
24
  puts "Gitlab Ruby Gem #{Gitlab::VERSION}"
24
25
  when '-v', '--version'
25
26
  puts "Gitlab Ruby Gem #{Gitlab::VERSION}"
27
+ when 'shell'
28
+ Gitlab::Shell.start
26
29
  else
27
- unless Gitlab.actions.include?(cmd.to_sym)
30
+ unless valid_command?(cmd)
28
31
  puts "Unknown command. Run `gitlab help` for a list of available commands."
29
32
  exit(1)
30
33
  end
@@ -37,21 +40,8 @@ class Gitlab::CLI
37
40
 
38
41
  confirm_command(cmd)
39
42
 
40
- begin
41
- data = args.any? ? Gitlab.send(cmd, *command_args) : Gitlab.send(cmd)
42
- rescue => e
43
- puts e.message
44
- exit(1)
45
- end
46
-
47
- case data
48
- when Gitlab::ObjectifiedHash
49
- puts single_record_table(data, cmd, args)
50
- when Array
51
- puts multiple_record_table(data, cmd, args)
52
- else
53
- puts data.inspect
54
- end
43
+ data = gitlab_helper(cmd, command_args) { exit(1) }
44
+ output_table(cmd, args, data)
55
45
  end
56
46
  end
57
47
  end
@@ -25,6 +25,14 @@ class Gitlab::CLI
25
25
  end
26
26
  end
27
27
 
28
+ # Confirms command is valid.
29
+ #
30
+ # @return [Boolean]
31
+ def valid_command?(cmd)
32
+ command = cmd.is_a?(Symbol) ? cmd : cmd.to_sym
33
+ Gitlab.actions.include?(command)
34
+ end
35
+
28
36
  # Confirms command with a desctructive action.
29
37
  #
30
38
  # @return [String]
@@ -77,6 +85,20 @@ class Gitlab::CLI
77
85
  end
78
86
  end
79
87
 
88
+ # Decides which table to use.
89
+ #
90
+ # @return [String]
91
+ def output_table(cmd, args, data)
92
+ case data
93
+ when Gitlab::ObjectifiedHash
94
+ puts single_record_table(data, cmd, args)
95
+ when Array
96
+ puts multiple_record_table(data, cmd, args)
97
+ else
98
+ puts data.inspect
99
+ end
100
+ end
101
+
80
102
  # Table for a single record.
81
103
  #
82
104
  # @return [String]
@@ -137,5 +159,17 @@ class Gitlab::CLI
137
159
  end
138
160
  end
139
161
  end
162
+
163
+ # Helper function to call Gitlab commands with args.
164
+ def gitlab_helper(cmd, args=[])
165
+ begin
166
+ data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
167
+ rescue => e
168
+ puts e.message
169
+ yield if block_given?
170
+ end
171
+
172
+ data
173
+ end
140
174
  end
141
175
  end
@@ -31,6 +31,21 @@ class Gitlab::Client
31
31
  get("/projects/#{id}")
32
32
  end
33
33
 
34
+ # Gets a list of project events.
35
+ #
36
+ # @example
37
+ # Gitlab.project_events(42)
38
+ # Gitlab.project_events('gitlab')
39
+ #
40
+ # @param [Integer, String] project The ID or name of a project.
41
+ # @param [Hash] options A customizable set of options.
42
+ # @option options [Integer] :page The page number.
43
+ # @option options [Integer] :per_page The number of results per page.
44
+ # @return [Array<Gitlab::ObjectifiedHash>]
45
+ def project_events(project, options={})
46
+ get("/projects/#{project}/events", :query => options)
47
+ end
48
+
34
49
  # Creates a new project.
35
50
  #
36
51
  # @example
@@ -16,6 +16,20 @@ class Gitlab::Client
16
16
  end
17
17
  alias_method :repo_tags, :tags
18
18
 
19
+ # Creates a new project repository tag.
20
+ #
21
+ # @example
22
+ # Gitlab.create_tag(42,'new_tag','master'))
23
+ #
24
+ # @param [Integer] project The ID of a project.
25
+ # @param [String] tag_name The name of the new tag.
26
+ # @param [String] ref The ref (commit sha, branch name, or another tag) the tag will point to.
27
+ # @return [Gitlab::ObjectifiedHash]
28
+ def create_tag(project, tag_name, ref)
29
+ post("/projects/#{project}/repository/tags", body: {tag_name: tag_name, ref: ref})
30
+ end
31
+ alias_method :repo_create_tag, :create_tag
32
+
19
33
  # Gets a list of project commits.
20
34
  #
21
35
  # @example
@@ -0,0 +1,44 @@
1
+ require 'gitlab'
2
+ require 'gitlab/cli_helpers'
3
+
4
+ module Gitlab::Help
5
+ extend Gitlab::CLI::Helpers
6
+
7
+ def self.get_help(methods,cmd=nil)
8
+ help = ''
9
+
10
+ if cmd.nil? || cmd == 'help'
11
+ help = actions_table
12
+ else
13
+ ri_cmd = `which ri`.chomp
14
+
15
+ if $? == 0
16
+ namespace = methods.select {|m| m[:name] === cmd }.map {|m| m[:owner]+'.'+m[:name] }.shift
17
+
18
+ if namespace
19
+ begin
20
+ ri_output = `#{ri_cmd} -T #{namespace} 2>&1`.chomp
21
+
22
+ if $? == 0
23
+ ri_output.gsub!(/#{cmd}\((.*)\)/, cmd+' \1')
24
+ ri_output.gsub!(/Gitlab\./, 'gitlab> ')
25
+ ri_output.gsub!(/Gitlab\..+$/, '')
26
+ ri_output.gsub!(/\,/, '')
27
+ help = ri_output
28
+ else
29
+ help = "Ri docs not found for #{namespace}, please install the docs to use 'help'"
30
+ end
31
+ rescue => e
32
+ puts e.message
33
+ end
34
+ else
35
+ help = "Unknown command: #{cmd}"
36
+ end
37
+ else
38
+ help = "'ri' tool not found in your PATH, please install it to use the help."
39
+ end
40
+ end
41
+
42
+ puts help
43
+ end
44
+ end
@@ -0,0 +1,49 @@
1
+ require 'gitlab'
2
+ require 'gitlab/help'
3
+ require 'gitlab/cli_helpers'
4
+ require 'readline'
5
+
6
+ class Gitlab::Shell
7
+ extend Gitlab::CLI::Helpers
8
+
9
+ def self.start
10
+ actions = Gitlab.actions
11
+
12
+ comp = proc { |s| actions.map(&:to_s).grep(/^#{Regexp.escape(s)}/) }
13
+
14
+ Readline.completion_proc = comp
15
+ Readline.completion_append_character = ' '
16
+
17
+ client = Gitlab::Client.new(endpoint: '')
18
+
19
+ while buf = Readline.readline("gitlab> ", true)
20
+ next if buf.nil? || buf.empty?
21
+ buf = buf.split.map(&:chomp)
22
+ cmd = buf.shift
23
+ args = buf.count > 0 ? buf : []
24
+
25
+ if cmd == 'help'
26
+ methods = []
27
+
28
+ actions.each do |action|
29
+ methods << {
30
+ name: action.to_s,
31
+ owner: client.method(action).owner.to_s
32
+ }
33
+ end
34
+
35
+ args[0].nil? ? Gitlab::Help.get_help(methods) : Gitlab::Help.get_help(methods, args[0])
36
+ next
37
+ end
38
+
39
+ data = if actions.include?(cmd.to_sym)
40
+ confirm_command(cmd)
41
+ gitlab_helper(cmd, args)
42
+ else
43
+ "'#{cmd}' is not a valid command. See the 'help' for a list of valid commands."
44
+ end
45
+
46
+ output_table(cmd, args, data)
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Gitlab
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -0,0 +1 @@
1
+ [{"title":null,"project_id":2,"action_name":"opened","target_id":null,"target_type":null,"author_id":1,"data":{"before":"ac0c1aa3898d6dea54d7868ea6f9c45fd5e30c59","after":"66350dbb62a221bc619b665aef3e1e7d3b306747","ref":"refs/heads/master","user_id":1,"user_name":"Administrator","project_id":2,"repository":{"name":"gitlab-ci","url":"git@demo.gitlab.com:gitlab/gitlab-ci.git","description":"Continuous integration server for gitlabhq | Coordinator","homepage":"http://demo.gitlab.com/gitlab/gitlab-ci"},"commits":[{"id":"8cf469b039931bab37bbf025e6b69287ea3cfb0e","message":"Modify screenshot\n\nSigned-off-by: Dmitriy Zaporozhets \u003Cdummy@gmail.com\u003E","timestamp":"2014-05-20T10:34:27+00:00","url":"http://demo.gitlab.com/gitlab/gitlab-ci/commit/8cf469b039931bab37bbf025e6b69287ea3cfb0e","author":{"name":"Dummy","email":"dummy@gmail.com"}},{"id":"66350dbb62a221bc619b665aef3e1e7d3b306747","message":"Edit some code\n\nSigned-off-by: Dmitriy Zaporozhets \u003Cdummy@gmail.com\u003E","timestamp":"2014-05-20T10:35:15+00:00","url":"http://demo.gitlab.com/gitlab/gitlab-ci/commit/66350dbb62a221bc619b665aef3e1e7d3b306747","author":{"name":"Dummy","email":"dummy@gmail.com"}}],"total_commits_count":2},"target_title":null,"created_at":"2014-05-20T10:35:26.240Z"},{"title":null,"project_id":2,"action_name":"opened","target_id":2,"target_type":"MergeRequest","author_id":1,"data":null,"target_title":" Morbi et cursus leo. Sed eget vestibulum sapien","created_at":"2014-05-20T10:24:11.917Z"}]
@@ -0,0 +1 @@
1
+ {"name": "v1.0.0","commit": {"id": "2695effb5807a22ff3d138d593fd856244e155e7","parents": [],"message": "Initial commit","authored_date": "2012-05-28T04:42:42-07:00","author_name": "John Smith","author email": "john@example.com","committer_name": "Jack Smith","committed_date": "2012-05-28T04:42:42-07:00","committer_email": "jack@example.com"},"protected": false}
@@ -30,7 +30,7 @@ describe Gitlab::Client do
30
30
 
31
31
  it "should return an array of user's issues" do
32
32
  expect(@issues).to be_an Array
33
- expect(@issues.first.closed).to be_false
33
+ expect(@issues.first.closed).to be_falsey
34
34
  expect(@issues.first.author.name).to eq("John Smith")
35
35
  end
36
36
  end
@@ -34,6 +34,26 @@ describe Gitlab::Client do
34
34
  end
35
35
  end
36
36
 
37
+ describe ".project_events" do
38
+ before do
39
+ stub_get("/projects/2/events", "project_events")
40
+ @events = Gitlab.project_events(2)
41
+ end
42
+
43
+ it "should get the correct resource" do
44
+ expect(a_get("/projects/2/events")).to have_been_made
45
+ end
46
+
47
+ it "should return an array of events" do
48
+ expect(@events).to be_an Array
49
+ expect(@events.size).to eq(2)
50
+ end
51
+
52
+ it "should return the action name of the event" do
53
+ expect(@events.first.action_name).to eq("opened")
54
+ end
55
+ end
56
+
37
57
  describe ".create_project" do
38
58
  before do
39
59
  stub_post("/projects", "project")
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Gitlab::Client do
4
4
  it { should respond_to :repo_tags }
5
+ it { should respond_to :repo_create_tag }
5
6
  it { should respond_to :repo_branches }
6
7
  it { should respond_to :repo_branch }
7
8
  it { should respond_to :repo_commits }
@@ -24,6 +25,21 @@ describe Gitlab::Client do
24
25
  end
25
26
  end
26
27
 
28
+ describe ".create_tag" do
29
+ before do
30
+ stub_post("/projects/3/repository/tags", "tag")
31
+ @tag = Gitlab.create_tag(3, 'v1.0.0', '2695effb5807a22ff3d138d593fd856244e155e7')
32
+ end
33
+
34
+ it "should get the correct resource" do
35
+ expect(a_post("/projects/3/repository/tags")).to have_been_made
36
+ end
37
+
38
+ it "should return information about a new repository tag" do
39
+ expect(@tag.name).to eq("v1.0.0")
40
+ end
41
+ end
42
+
27
43
  describe ".commits" do
28
44
  before do
29
45
  stub_get("/projects/3/repository/commits", "project_commits").
@@ -17,7 +17,7 @@ describe Gitlab::ObjectifiedHash do
17
17
  end
18
18
 
19
19
  it "should have an alias #to_h" do
20
- expect(@oh.respond_to?(:to_h)).to be_true
20
+ expect(@oh.respond_to?(:to_h)).to be_truthy
21
21
  end
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -114,8 +114,10 @@ files:
114
114
  - lib/gitlab/client/users.rb
115
115
  - lib/gitlab/configuration.rb
116
116
  - lib/gitlab/error.rb
117
+ - lib/gitlab/help.rb
117
118
  - lib/gitlab/objectified_hash.rb
118
119
  - lib/gitlab/request.rb
120
+ - lib/gitlab/shell.rb
119
121
  - lib/gitlab/version.rb
120
122
  - spec/fixtures/branch.json
121
123
  - spec/fixtures/branches.json
@@ -145,6 +147,7 @@ files:
145
147
  - spec/fixtures/project_commit_diff.json
146
148
  - spec/fixtures/project_commits.json
147
149
  - spec/fixtures/project_delete_key.json
150
+ - spec/fixtures/project_events.json
148
151
  - spec/fixtures/project_for_user.json
149
152
  - spec/fixtures/project_fork_link.json
150
153
  - spec/fixtures/project_hook.json
@@ -161,6 +164,7 @@ files:
161
164
  - spec/fixtures/system_hook.json
162
165
  - spec/fixtures/system_hook_test.json
163
166
  - spec/fixtures/system_hooks.json
167
+ - spec/fixtures/tag.json
164
168
  - spec/fixtures/team_member.json
165
169
  - spec/fixtures/team_members.json
166
170
  - spec/fixtures/unprotect_branch.json
@@ -235,6 +239,7 @@ test_files:
235
239
  - spec/fixtures/project_commit_diff.json
236
240
  - spec/fixtures/project_commits.json
237
241
  - spec/fixtures/project_delete_key.json
242
+ - spec/fixtures/project_events.json
238
243
  - spec/fixtures/project_for_user.json
239
244
  - spec/fixtures/project_fork_link.json
240
245
  - spec/fixtures/project_hook.json
@@ -251,6 +256,7 @@ test_files:
251
256
  - spec/fixtures/system_hook.json
252
257
  - spec/fixtures/system_hook_test.json
253
258
  - spec/fixtures/system_hooks.json
259
+ - spec/fixtures/tag.json
254
260
  - spec/fixtures/team_member.json
255
261
  - spec/fixtures/team_members.json
256
262
  - spec/fixtures/unprotect_branch.json