module Octokit::Client::Contents

def archive_link(repo, options = {})

Other tags:
    Example: Get archive link for octokit/octokit.rb -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#get-archive-link -

Returns:
  • (String) - Location of the download

Options Hash: (**options)
  • :ref (String) -- Optional valid Git reference, defaults to master.
  • format (String) -- Either tarball (default) or zipball.

Parameters:
  • repo (Integer, String, Repository, Hash) -- A GitHub repository.
def archive_link(repo, options = {})
  repo_ref = ERB::Util.url_encode(options.delete(:ref))
  format = (options.delete :format) || 'tarball'
  url = "#{Repository.path repo}/#{format}/#{repo_ref}"
  response = client_without_redirects.head(url, options)
  response.headers['Location']
end

def contents(repo, options = {})

Other tags:
    Example: Lists the contents of lib /octokit.rb on a particular branch -
    Example: List the contents of lib/octokit.rb -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#get-contents -

Returns:
  • (Sawyer::Resource) - The contents of a file or list of the files in the folder

Options Hash: (**options)
  • :ref (String) -- name of the Commit/Branch/Tag. Defaults to “master”.
  • :path (String) -- A folder or file path

Parameters:
  • repo (Integer, String, Repository, Hash) -- A GitHub repository
def contents(repo, options = {})
  options = options.dup
  repo_path = options.delete :path
  url = "#{Repository.path repo}/contents/#{repo_path}"
  get url, options
end

def create_contents(*args)

Other tags:
    Example: Add content at lib/octokit.rb -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#create-a-file -

Returns:
  • (Sawyer::Resource) - The contents and commit info for the addition

Options Hash: (**options)
  • :file (String) -- Path or Ruby File object for content
  • :branch (String) -- The branch on which to add the content

Parameters:
  • optional () -- content [String] The content for the file
  • message (String) -- A commit message for adding the content
  • path (String) -- A path for the new content
  • repo (Integer, String, Repository, Hash) -- A GitHub repository

Overloads:
  • create_contents(repo, path, message, content = nil, options = {})
def create_contents(*args)
  args    = args.map { |item| item&.dup }
  options = args.last.is_a?(Hash) ? args.pop : {}
  repo    = args.shift
  path    = args.shift
  message = args.shift
  content = args.shift
  if content.nil? && file = options.delete(:file)
    case file
    when String
      if File.exist?(file)
        file = File.open(file, 'r')
        content = file.read
        file.close
      end
    when File, Tempfile
      content = file.read
      file.close
    end
  end
  raise ArgumentError, 'content or :file option required' if content.nil?
  options[:content] = [content].pack('m0') # Base64.strict_encode64
  options[:message] = message
  url = "#{Repository.path repo}/contents/#{path}"
  put url, options
end

def delete_contents(repo, path, message, sha, options = {})

Other tags:
    Example: Delete content at lib/octokit.rb -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#delete-a-file -

Returns:
  • (Sawyer::Resource) - The commit info for the delete

Options Hash: (**options)
  • :branch (String) -- The branch on which to delete the content

Parameters:
  • sha (String) -- The _blob sha_ of the content to delete
  • message (String) -- A commit message for deleting the content
  • path (String) -- A path for the content to delete
  • repo (Integer, String, Repository, Hash) -- A GitHub repository
def delete_contents(repo, path, message, sha, options = {})
  options[:message] = message
  options[:sha] = sha
  url = "#{Repository.path repo}/contents/#{path}"
  delete url, options
end

def readme(repo, options = {})

Other tags:
    Example: Get the readme file for a particular branch of the repo -
    Example: Get the readme file for a repo -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#get-the-readme -

Returns:
  • (Sawyer::Resource) - The detail of the readme

Options Hash: (**options)
  • :ref (String) -- name of the Commit/Branch/Tag. Defaults to “master”.

Parameters:
  • repo (Integer, String, Repository, Hash) -- A GitHub repository
def readme(repo, options = {})
  get "#{Repository.path repo}/readme", options
end

def update_contents(*args)

Other tags:
    Example: Update content at lib/octokit.rb -

Other tags:
    See: https://developer.github.com/v3/repos/contents/#update-a-file -

Returns:
  • (Sawyer::Resource) - The contents and commit info for the update

Options Hash: (**options)
  • :file (String) -- Path or Ruby File object for content
  • :branch (String) -- The branch on which to update the content

Parameters:
  • content (String) -- The content for the file
  • sha (String) -- The _blob sha_ of the content to update
  • message (String) -- A commit message for updating the content
  • path (String) -- A path for the content to update
  • repo (Integer, String, Repository, Hash) -- A GitHub repository

Overloads:
  • update_contents(repo, path, message, sha, content = nil, options = {})
def update_contents(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  repo    = args.shift
  path    = args.shift
  message = args.shift
  sha     = args.shift
  content = args.shift
  options.merge!(sha: sha)
  create_contents(repo, path, message, content, options)
end