Skip to content

Commit

Permalink
support merge requests API
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Nov 22, 2012
1 parent fb5761a commit 2ef4d48
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class Client < API
include Gitlab::Client::Snippets
include Gitlab::Client::Projects
include Gitlab::Client::Repositories
include Gitlab::Client::MergeRequests
end
end
32 changes: 32 additions & 0 deletions lib/gitlab/client/merge_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Gitlab::Client
# Defines methods related to merge requests.
module MergeRequests
# Gets a list of project merge requests.
#
# @example
# Gitlab.merge_requests(5)
# Gitlab.merge_requests('gitlab', :per_page => 40)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_requests(project, options={})
get("/projects/#{project}/merge_requests", :query => options)
end

# Gets a single merge request.
#
# @example
# Gitlab.merge_request(5, 36)
# Gitlab.merge_request('gitlab', 42)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of a merge request.
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_request(project, id)
get("/projects/#{project}/merge_request/#{id}")
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/merge_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":1,"target_branch":"master","source_branch":"api","project_id":3,"title":"New feature","closed":false,"merged":false,"author":{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":2,"email":"jack@example.com","name":"Jack Smith","blocked":false,"created_at":"2012-10-19T05:56:14Z"}}
1 change: 1 addition & 0 deletions spec/fixtures/merge_requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"target_branch":"master","source_branch":"api","project_id":3,"title":"New feature","closed":false,"merged":false,"author":{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":2,"email":"jack@example.com","name":"Jack Smith","blocked":false,"created_at":"2012-10-19T05:56:14Z"}}]
35 changes: 35 additions & 0 deletions spec/gitlab/client/merge_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe Gitlab::Client do
describe ".merge_requests" do
before do
stub_get("/projects/3/merge_requests", "merge_requests")
@merge_requests = Gitlab.merge_requests(3)
end

it "should get the correct resource" do
a_get("/projects/3/merge_requests").should have_been_made
end

it "should return an array of project's merge requests" do
@merge_requests.should be_an Array
@merge_requests.first.project_id.should == 3
end
end

describe ".merge_request" do
before do
stub_get("/projects/3/merge_request/1", "merge_request")
@merge_request = Gitlab.merge_request(3, 1)
end

it "should get the correct resource" do
a_get("/projects/3/merge_request/1").should have_been_made
end

it "should return information about a merge request" do
@merge_request.project_id.should == 3
@merge_request.assignee.name.should == "Jack Smith"
end
end
end

0 comments on commit 2ef4d48

Please sign in to comment.