Skip to content

Commit 6bc99b0

Browse files
committed
Added feature to retrive repo info using repo id.
Currently, we can retrieve repo info using owner name and repo name. Added support to retrieve repo info using repo id.
1 parent 2632ae3 commit 6bc99b0

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

lib/github_api/client/repos.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ def get(*args)
166166
end
167167
alias :find :get
168168

169+
# Get a repository
170+
#
171+
# @example
172+
# github = Github.new
173+
# github.repos.get_by_id 'repo-id'
174+
# github.repos.get_by_id id: 'repo-id'
175+
# github.repos(id: 'repo-id').get_by_id
176+
#
177+
def get_by_id(*args)
178+
arguments(args, required: [:id])
179+
180+
get_request("/repositories/#{arguments.id}", arguments.params)
181+
end
182+
alias :find_by_id :get_by_id
183+
169184
# Create a new repository for the autheticated user.
170185
#
171186
# @param [Hash] params
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Repos, '#get_by_id' do
6+
let(:user) { 'peter-murach' }
7+
let(:repo) { 'github' }
8+
let(:repo_id) { '2456210' }
9+
let(:request_path) { "/repositories/#{repo_id}" }
10+
11+
before {
12+
stub_get(request_path).to_return(:body => body, :status => status,
13+
:headers => {:content_type => "application/json; charset=utf-8"})
14+
}
15+
16+
after { reset_authentication_for subject }
17+
18+
context "resource found" do
19+
let(:body) { fixture('repos/repo.json') }
20+
let(:status) { 200 }
21+
22+
it { should respond_to(:find_by_id) }
23+
24+
it "should raise error when no parameters" do
25+
expect { subject.get_by_id }.to raise_error(ArgumentError)
26+
end
27+
28+
it "should find resources" do
29+
subject.get_by_id repo_id
30+
a_get(request_path).should have_been_made
31+
end
32+
33+
it "should return repository mash" do
34+
repository = subject.get_by_id repo_id
35+
repository.should be_a Github::ResponseWrapper
36+
end
37+
38+
it "should get repository information" do
39+
repository = subject.get_by_id repo_id
40+
repository.name.should == 'Hello-World'
41+
end
42+
end
43+
44+
it_should_behave_like 'request failure' do
45+
let(:requestable) { subject.get_by_id repo_id }
46+
end
47+
end # get_by_id

0 commit comments

Comments
 (0)