Skip to content

Commit

Permalink
implement .file_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdambrosio committed Dec 4, 2014
1 parent 104ebbd commit e4ceb18
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/gitlab/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ def commit_diff(project, sha)
end
alias_method :repo_commit_diff, :commit_diff

# Get the contents of a file
#
# @example
# Gitlab.file_contents(42, 'Gemfile')
# Gitlab.repo_file_contents(3, 'Gemfile', 'ed899a2f4b50b4370feeea94676502b42383c746')
#
# @param [Integer] project The ID of a project.
# @param [String] filepath The relative path of the file in the repository
# @param [String] ref The name of a repository branch or tag or if not given the default branch.
# @return [String]
def file_contents(project, filepath, ref = 'master')
get "/projects/#{project}/repository/blobs/#{ref}?filepath=#{filepath}",
format: nil,
headers: { Accept: 'text/plain' },
parser: ::Gitlab::Request::Parser
end
alias_method :repo_file_contents, :file_contents

# Gets a list of comments for a commit.
#
# @example
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/raw_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'rails', '4.1.2'
15 changes: 15 additions & 0 deletions spec/gitlab/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
end
end

describe ".file_contents" do
before do
stub_get("/projects/3/repository/blobs/master?filepath=Gemfile", "raw_file")
@file_contents = Gitlab.file_contents(3, "Gemfile")
end

it "should get the correct resource" do
expect(a_get("/projects/3/repository/blobs/master?filepath=Gemfile")).to have_been_made
end

it "should return file contents" do
expect(@file_contents).to eq("source 'https://rubygems.org'\ngem 'rails', '4.1.2'\n")
end
end

describe ".create_tag" do
context "lightweight" do
before do
Expand Down

0 comments on commit e4ceb18

Please sign in to comment.