Method: Gitlab::Client::Repositories#file_contents

Defined in:
lib/gitlab/client/repositories.rb

#file_contents(project, filepath, ref = 'master') ⇒ String Also known as: repo_file_contents

Get the contents of a file

Examples:

Gitlab.file_contents(42, 'Gemfile')
Gitlab.repo_file_contents(3, 'Gemfile', 'ed899a2f4b50b4370feeea94676502b42383c746')

Parameters:

  • project (Integer)

    The ID of a project.

  • filepath (String)

    The relative path of the file in the repository

  • ref (String) (defaults to: 'master')

    The name of a repository branch or tag or if not given the default branch.

Returns:

  • (String)


15
16
17
18
19
20
21
# File 'lib/gitlab/client/repositories.rb', line 15

def file_contents(project, filepath, ref='master')
  ref = URI.encode(ref, /\W/)
  get "/projects/#{project}/repository/blobs/#{ref}?filepath=#{filepath}",
      format: nil,
      headers: { Accept: 'text/plain' },
      parser: ::Gitlab::Request::Parser
end