Method: GitHub::Client::Contents#update_file

Defined in:
lib/github_api_v3/client/contents.rb

#update_file(owner, repo, options = {}) ⇒ Hash Also known as: edit_file

Update a file in a repository.

Requires authentication.

Examples:

client = GitHub.client(:login => 'caseyscarborough', :access_token => '7a329f6057f13c496ecf7fd777ceb9e79ae285')
client.update_file(
  'caseyscarborough',
  'github',
  :path      => 'lib/update_file.txt',
  :message   => 'Update lib/update_file.txt.',
  :content   => 'This is a test file.',
  :sha       => '329688480d39049927147c162b9d2deaf885005f',
  :committer => { :name => 'Casey Scarborough', :email => '[email protected]' }
)

Parameters:

  • owner (String)

    The repository owner.

  • repo (String)

    The repository name.

  • options (Hash) (defaults to: {})

    File update parameters.

Options Hash (options):

  • :path (String) — default: required

    The file path.

  • :message (String) — default: required

    The commit message.

  • :content (String) — default: required

    The new file content.

  • :sha (String) — default: required

    The blob SHA of the file being replaced.

  • :branch (String)

    The branch name, defaults to default branch (usually master).

  • :committer (Hash)

    The committer’s information. If not present, the authenticated user’s information is used. It should contain the committer’s name and email, shown in the example.

Returns:

  • (Hash)

    File content information.

See Also:



92
93
94
95
# File 'lib/github_api_v3/client/contents.rb', line 92

def update_file(owner, repo, options={})
  options[:content] = Base64.strict_encode64(options[:content])
  put "/repos/#{owner}/#{repo}/contents/#{options[:path]}", body: options
end