gitlab 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gitlab
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/NARKOZ/gitlab.png)](http://travis-ci.org/NARKOZ/gitlab)
4
+
3
5
  Gitlab is a Ruby wrapper for the [GitLab API](https://github.com/gitlabhq/gitlabhq/tree/master/doc/api#gitlab-api).
4
6
 
5
7
  ## Installation
@@ -65,5 +65,31 @@ class Gitlab::Client
65
65
  def edit_issue(project, id, options={})
66
66
  put("/projects/#{project}/issues/#{id}", :body => options)
67
67
  end
68
+
69
+ # Closes an issue.
70
+ #
71
+ # @example
72
+ # Gitlab.close_issue(3, 42)
73
+ # Gitlab.close_issue('gitlab', 42)
74
+ #
75
+ # @param [Integer, String] project The ID or code name of a project.
76
+ # @param [Integer] id The ID of an issue.
77
+ # @return [Gitlab::ObjectifiedHash] Information about closed issue.
78
+ def close_issue(project, id)
79
+ put("/projects/#{project}/issues/#{id}", :body => {:closed => 1})
80
+ end
81
+
82
+ # Reopens an issue.
83
+ #
84
+ # @example
85
+ # Gitlab.reopen_issue(3, 42)
86
+ # Gitlab.reopen_issue('gitlab', 42)
87
+ #
88
+ # @param [Integer, String] project The ID or code name of a project.
89
+ # @param [Integer] id The ID of an issue.
90
+ # @return [Gitlab::ObjectifiedHash] Information about reopened issue.
91
+ def reopen_issue(project, id)
92
+ put("/projects/#{project}/issues/#{id}", :body => {:closed => 0})
93
+ end
68
94
  end
69
95
  end
@@ -85,13 +85,13 @@ class Gitlab::Client
85
85
  # @param [Integer] access_level The access level to project.
86
86
  # @return [Array<Gitlab::ObjectifiedHash>] Information about added team member.
87
87
  def add_team_member(project, id, access_level)
88
- post("/projects/#{project}/members/#{id}", :body => {:access_level => access_level})
88
+ post("/projects/#{project}/members", :body => {:user_id => id, :access_level => access_level})
89
89
  end
90
90
 
91
91
  # Updates a team member's project access level.
92
92
  #
93
93
  # @example
94
- # Gitlab.team_members('gitlab', 3, 20)
94
+ # Gitlab.edit_team_member('gitlab', 3, 20)
95
95
  #
96
96
  # @param [Integer, String] project The ID or code name of a project.
97
97
  # @param [Integer] id The ID of a user.
@@ -128,10 +128,23 @@ class Gitlab::Client
128
128
  get("/projects/#{project}/hooks", :query => options)
129
129
  end
130
130
 
131
+ # Gets a project hook.
132
+ #
133
+ # @example
134
+ # Gitlab.project_hook(42, 5)
135
+ # Gitlab.project_hook('gitlab', 5)
136
+ #
137
+ # @param [Integer, String] project The ID or code name of a project.
138
+ # @param [Integer] id The ID of a hook.
139
+ # @return [Gitlab::ObjectifiedHash]
140
+ def project_hook(project, id)
141
+ get("/projects/#{project}/hooks/#{id}")
142
+ end
143
+
131
144
  # Adds a new hook to the project.
132
145
  #
133
146
  # @example
134
- # Gitlab.project_hooks(42, 'https://api.example.net/v1/webhooks/ci')
147
+ # Gitlab.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci')
135
148
  #
136
149
  # @param [Integer, String] project The ID or code name of a project.
137
150
  # @param [String] url The hook URL.
@@ -140,6 +153,19 @@ class Gitlab::Client
140
153
  post("/projects/#{project}/hooks", :body => {:url => url})
141
154
  end
142
155
 
156
+ # Updates a project hook URL.
157
+ #
158
+ # @example
159
+ # Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')
160
+ #
161
+ # @param [Integer, String] project The ID or code name of a project.
162
+ # @param [Integer] id The ID of the hook.
163
+ # @param [String] url The hook URL.
164
+ # @return [Gitlab::ObjectifiedHash] Information about updated hook.
165
+ def edit_project_hook(project, id, url)
166
+ put("/projects/#{project}/hooks/#{id}", :body => {:url => url})
167
+ end
168
+
143
169
  # Deletes a hook from project.
144
170
  #
145
171
  # @example
@@ -15,7 +15,7 @@ class Gitlab::Client
15
15
  def tags(project, options={})
16
16
  get("/projects/#{project}/repository/tags", :query => options)
17
17
  end
18
- alias :repo_tags :tags
18
+ alias_method :repo_tags, :tags
19
19
 
20
20
  # Gets a list of project repositiory branches.
21
21
  #
@@ -31,7 +31,7 @@ class Gitlab::Client
31
31
  def branches(project, options={})
32
32
  get("/projects/#{project}/repository/branches", :query => options)
33
33
  end
34
- alias :repo_branches :branches
34
+ alias_method :repo_branches, :branches
35
35
 
36
36
  # Gets information about a repository branch.
37
37
  #
@@ -45,7 +45,7 @@ class Gitlab::Client
45
45
  def branch(project, branch)
46
46
  get("/projects/#{project}/repository/branches/#{branch}")
47
47
  end
48
- alias :repo_branch :branch
48
+ alias_method :repo_branch, :branch
49
49
 
50
50
  # Gets a list of project commits.
51
51
  #
@@ -62,6 +62,6 @@ class Gitlab::Client
62
62
  def commits(project, options={})
63
63
  get("/projects/#{project}/repository/commits", :query => options)
64
64
  end
65
- alias :repo_commits :commits
65
+ alias_method :repo_commits, :commits
66
66
  end
67
67
  end
@@ -1,6 +1,21 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to snippets.
3
3
  module Snippets
4
+ # Gets a list of project's snippets.
5
+ #
6
+ # @example
7
+ # Gitlab.snippets(42)
8
+ # Gitlab.snippets('gitlab')
9
+ #
10
+ # @param [Integer, String] project The ID or code name of a project.
11
+ # @param [Hash] options A customizable set of options.
12
+ # @option options [Integer] :page The page number.
13
+ # @option options [Integer] :per_page The number of results per page.
14
+ # @return [Gitlab::ObjectifiedHash]
15
+ def snippets(project, options={})
16
+ get("/projects/#{project}/snippets", :query => options)
17
+ end
18
+
4
19
  # Gets information about a snippet.
5
20
  #
6
21
  # @example
@@ -27,6 +27,23 @@ class Gitlab::Client
27
27
  id.to_i.zero? ? get("/user") : get("/users/#{id}")
28
28
  end
29
29
 
30
+ # Creates a new user.
31
+ # Requires authentication from an admin account.
32
+ #
33
+ # @param [String] email The email of a user.
34
+ # @param [String] password The password of a user.
35
+ # @param [Hash] options A customizable set of options.
36
+ # @option options [String] :name The name of a user. Defaults to email.
37
+ # @option options [String] :skype The skype of a user.
38
+ # @option options [String] :linkedin The linkedin of a user.
39
+ # @option options [String] :twitter The twitter of a user.
40
+ # @option options [Integer] :projects_limit The limit of projects for a user.
41
+ # @return [Gitlab::ObjectifiedHash] Information about created user.
42
+ def create_user(email, password, options={})
43
+ body = {:email => email, :password => password, :name => email}.merge(options)
44
+ post("/users", :body => body)
45
+ end
46
+
30
47
  # Creates a new user session.
31
48
  #
32
49
  # @example
@@ -4,70 +4,77 @@ module Gitlab
4
4
  # @private
5
5
  class Request
6
6
  include HTTParty
7
- format :json
7
+ format :json
8
8
  headers 'Accept' => 'application/json'
9
- parser Proc.new {|body| make_objectified_hash(body)}
9
+ parser Proc.new {|body| parse(body)}
10
10
 
11
- # Parses the response body.
12
- def self.make_objectified_hash(body)
13
- begin
14
- response = MultiJson.respond_to?(:adapter) ? MultiJson.load(body) : MultiJson.decode(body)
15
- rescue MultiJson::DecodeError
16
- raise Error::Parsing.new "Couldn't parse a response body"
17
- end
11
+ # Converts the response body to an ObjectifiedHash.
12
+ def self.parse(body)
13
+ body = decode(body)
18
14
 
19
- if response.is_a? Hash
20
- ObjectifiedHash.new response
21
- elsif response.is_a? Array
22
- response.collect! {|e| ObjectifiedHash.new(e)}
15
+ if body.is_a? Hash
16
+ ObjectifiedHash.new body
17
+ elsif body.is_a? Array
18
+ body.collect! {|e| ObjectifiedHash.new(e)}
23
19
  else
24
20
  raise Error::Parsing.new "Couldn't parse a response body"
25
21
  end
26
22
  end
27
23
 
24
+ # Decodes a JSON response into Ruby object.
25
+ def self.decode(response)
26
+ begin
27
+ if MultiJson.respond_to?(:adapter)
28
+ MultiJson.load response
29
+ else
30
+ MultiJson.decode response
31
+ end
32
+ rescue MultiJson::DecodeError
33
+ raise Error::Parsing.new "The response is not a valid JSON"
34
+ end
35
+ end
36
+
28
37
  def get(path, options={})
29
- validate_response self.class.get(path, options)
38
+ validate self.class.get(path, options)
30
39
  end
31
40
 
32
41
  def post(path, options={})
33
- validate_response self.class.post(path, options)
42
+ validate self.class.post(path, options)
34
43
  end
35
44
 
36
45
  def put(path, options={})
37
- validate_response self.class.put(path, options)
46
+ validate self.class.put(path, options)
38
47
  end
39
48
 
40
49
  def delete(path)
41
- validate_response self.class.delete(path)
50
+ validate self.class.delete(path)
42
51
  end
43
52
 
44
- def set_request_defaults(endpoint, private_token)
45
- raise Error::MissingCredentials.new("Please set an endpoint") unless endpoint
46
- raise Error::MissingCredentials.new("Please set a private_token") unless private_token
47
-
48
- self.class.base_uri endpoint
49
- self.class.default_params :private_token => private_token
50
- end
51
-
52
- def validate_response(response)
53
+ # Checks the response code for common errors.
54
+ # Returns parsed response for successful requests.
55
+ def validate(response)
56
+ message = "Server responsed with code #{response.code}"
53
57
  case response.code
54
- when 400
55
- raise Error::BadRequest.new "Server responsed with code #{response.code}"
56
- when 401
57
- raise Error::Unauthorized.new "Server responsed with code #{response.code}"
58
- when 403
59
- raise Error::Forbidden.new "Server responsed with code #{response.code}"
60
- when 404
61
- raise Error::NotFound.new "Server responsed with code #{response.code}"
62
- when 500
63
- raise Error::InternalServerError.new "Server responsed with code #{response.code}"
64
- when 502
65
- raise Error::BadGateway.new "Server responsed with code #{response.code}"
66
- when 503
67
- raise Error::ServiceUnavailable.new "Server responsed with code #{response.code}"
58
+ when 400; raise Error::BadRequest.new message
59
+ when 401; raise Error::Unauthorized.new message
60
+ when 403; raise Error::Forbidden.new message
61
+ when 404; raise Error::NotFound.new message
62
+ when 500; raise Error::InternalServerError.new message
63
+ when 502; raise Error::BadGateway.new message
64
+ when 503; raise Error::ServiceUnavailable.new message
68
65
  end
69
66
 
70
67
  response.parsed_response
71
68
  end
69
+
70
+ # Sets a base_uri and private_token parameter for requests.
71
+ # @raise [Error::MissingCredentials] if endpoint or private_token not set.
72
+ def set_request_defaults(endpoint, private_token)
73
+ raise Error::MissingCredentials.new("Please set an endpoint to API") unless endpoint
74
+ raise Error::MissingCredentials.new("Please set a private_token for user") unless private_token
75
+
76
+ self.class.base_uri endpoint
77
+ self.class.default_params :private_token => private_token
78
+ end
72
79
  end
73
80
  end
@@ -1,3 +1,3 @@
1
1
  module Gitlab
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1 @@
1
+ [{"id":1,"title":"Rails Console ActionMailer","file_name":"mailer_test.rb","author":{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-09-17T09:41:56Z"},"expires_at":"2012-09-24T00:00:00Z","updated_at":"2012-09-17T09:51:42Z","created_at":"2012-09-17T09:51:42Z"}]
@@ -85,4 +85,38 @@ describe Gitlab::Client do
85
85
  @issue.assignee.name.should == "Jack Smith"
86
86
  end
87
87
  end
88
+
89
+ describe ".close_issue" do
90
+ before do
91
+ stub_put("/projects/3/issues/33", "issue")
92
+ @issue = Gitlab.close_issue(3, 33)
93
+ end
94
+
95
+ it "should get the correct resource" do
96
+ a_put("/projects/3/issues/33").
97
+ with(:body => {:closed => '1'}).should have_been_made
98
+ end
99
+
100
+ it "should return information about an closed issue" do
101
+ @issue.project_id.should == 3
102
+ @issue.assignee.name.should == "Jack Smith"
103
+ end
104
+ end
105
+
106
+ describe ".reopen_issue" do
107
+ before do
108
+ stub_put("/projects/3/issues/33", "issue")
109
+ @issue = Gitlab.reopen_issue(3, 33)
110
+ end
111
+
112
+ it "should get the correct resource" do
113
+ a_put("/projects/3/issues/33").
114
+ with(:body => {:closed => '0'}).should have_been_made
115
+ end
116
+
117
+ it "should return information about an reopened issue" do
118
+ @issue.project_id.should == 3
119
+ @issue.assignee.name.should == "Jack Smith"
120
+ end
121
+ end
88
122
  end
@@ -83,13 +83,13 @@ describe Gitlab::Client do
83
83
 
84
84
  describe ".add_team_member" do
85
85
  before do
86
- stub_post("/projects/3/members/1", "team_member")
86
+ stub_post("/projects/3/members", "team_member")
87
87
  @team_member = Gitlab.add_team_member(3, 1, 40)
88
88
  end
89
89
 
90
90
  it "should get the correct resource" do
91
- a_post("/projects/3/members/1").
92
- with(:body => {:access_level => '40'}).should have_been_made
91
+ a_post("/projects/3/members").
92
+ with(:body => {:user_id => '1', :access_level => '40'}).should have_been_made
93
93
  end
94
94
 
95
95
  it "should return information about an added team member" do
@@ -144,6 +144,21 @@ describe Gitlab::Client do
144
144
  end
145
145
  end
146
146
 
147
+ describe ".project_hook" do
148
+ before do
149
+ stub_get("/projects/1/hooks/1", "project_hook")
150
+ @hook = Gitlab.project_hook(1, 1)
151
+ end
152
+
153
+ it "should get the correct resource" do
154
+ a_get("/projects/1/hooks/1").should have_been_made
155
+ end
156
+
157
+ it "should return information about a hook" do
158
+ @hook.url.should == "https://api.example.net/v1/webhooks/ci"
159
+ end
160
+ end
161
+
147
162
  describe ".add_project_hook" do
148
163
  before do
149
164
  stub_post("/projects/1/hooks", "project_hook")
@@ -160,6 +175,22 @@ describe Gitlab::Client do
160
175
  end
161
176
  end
162
177
 
178
+ describe ".edit_project_hook" do
179
+ before do
180
+ stub_put("/projects/1/hooks/1", "project_hook")
181
+ @hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci")
182
+ end
183
+
184
+ it "should get the correct resource" do
185
+ body = {:url => "https://api.example.net/v1/webhooks/ci"}
186
+ a_put("/projects/1/hooks/1").with(:body => body).should have_been_made
187
+ end
188
+
189
+ it "should return information about an edited hook" do
190
+ @hook.url.should == "https://api.example.net/v1/webhooks/ci"
191
+ end
192
+ end
193
+
163
194
  describe ".delete_project_hook" do
164
195
  before do
165
196
  stub_delete("/projects/1/hooks/1", "project_hook")
@@ -65,7 +65,7 @@ describe Gitlab::Client do
65
65
  with(:query => {:ref_name => "api"}).should have_been_made
66
66
  end
67
67
 
68
- it "should return an array of respository commits" do
68
+ it "should return an array of repository commits" do
69
69
  @commits.should be_an Array
70
70
  @commits.first.id.should == "f7dd067490fe57505f7226c3b54d3127d2f7fd46"
71
71
  end
@@ -1,6 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gitlab::Client do
4
+ describe ".snippets" do
5
+ before do
6
+ stub_get("/projects/3/snippets", "snippets")
7
+ @snippets = Gitlab.snippets(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ a_get("/projects/3/snippets").should have_been_made
12
+ end
13
+
14
+ it "should return an array of project's snippets" do
15
+ @snippets.should be_an Array
16
+ @snippets.first.file_name.should == "mailer_test.rb"
17
+ end
18
+ end
19
+
4
20
  describe ".snippet" do
5
21
  before do
6
22
  stub_get("/projects/3/snippets/1", "snippet")
@@ -49,6 +49,22 @@ describe Gitlab::Client do
49
49
  end
50
50
  end
51
51
 
52
+ describe ".create_user" do
53
+ before do
54
+ stub_post("/users", "user")
55
+ @user = Gitlab.create_user("email", "pass")
56
+ end
57
+
58
+ it "should get the correct resource" do
59
+ body = {:email => "email", :password => "pass", :name => "email"}
60
+ a_post("/users").with(:body => body).should have_been_made
61
+ end
62
+
63
+ it "should return information about a created user" do
64
+ @user.email.should == "john@example.com"
65
+ end
66
+ end
67
+
52
68
  describe ".session" do
53
69
  before do
54
70
  stub_post("/session", "session")
@@ -99,11 +115,11 @@ describe Gitlab::Client do
99
115
  describe ".create_ssh_key" do
100
116
  before do
101
117
  stub_post("/user/keys", "key")
102
- @key = Gitlab.create_ssh_key('title', 'body')
118
+ @key = Gitlab.create_ssh_key("title", "body")
103
119
  end
104
120
 
105
121
  it "should get the correct resource" do
106
- body = {:title => 'title', :key => 'body'}
122
+ body = {:title => "title", :key => "body"}
107
123
  a_post("/user/keys").with(:body => body).should have_been_made
108
124
  end
109
125
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-21 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -120,6 +120,7 @@ files:
120
120
  - spec/fixtures/projects.json
121
121
  - spec/fixtures/session.json
122
122
  - spec/fixtures/snippet.json
123
+ - spec/fixtures/snippets.json
123
124
  - spec/fixtures/team_member.json
124
125
  - spec/fixtures/team_members.json
125
126
  - spec/fixtures/user.json
@@ -146,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  segments:
148
149
  - 0
149
- hash: -751626136500933347
150
+ hash: 2246136145939191408
150
151
  required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  none: false
152
153
  requirements:
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  version: '0'
156
157
  segments:
157
158
  - 0
158
- hash: -751626136500933347
159
+ hash: 2246136145939191408
159
160
  requirements: []
160
161
  rubyforge_project:
161
162
  rubygems_version: 1.8.24
@@ -180,6 +181,7 @@ test_files:
180
181
  - spec/fixtures/projects.json
181
182
  - spec/fixtures/session.json
182
183
  - spec/fixtures/snippet.json
184
+ - spec/fixtures/snippets.json
183
185
  - spec/fixtures/team_member.json
184
186
  - spec/fixtures/team_members.json
185
187
  - spec/fixtures/user.json