123456789_123456789_123456789_123456789_123456789_

Module: Octokit::Client::Releases

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/octokit/client/releases.rb

Overview

Methods for the Releases API

Instance Method Summary

Instance Method Details

#content_type_from_file(file) (private)

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 153

def content_type_from_file(file)
  require 'mime/types'
  if mime_type = MIME::Types.type_for(file.path).first
    mime_type.content_type
  end
rescue LoadError
  msg = 'Please pass content_type or install mime-types gem to guess content type from file'
  raise Octokit::MissingContentType, msg
end

#create_release(repo, tag_name, options = {}) ⇒ Sawyer::Resource

Create a release

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • tag_name (String)

    Git tag from which to create release

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

    a customizable set of options

Options Hash (options):

  • :target_commitish (String)

    Specifies the commitish value that determines where the Git tag is created from.

  • :name (String)

    Name for the release

  • :body (String)

    Content for release notes

  • :draft (Boolean)

    Mark this release as a draft

  • :prerelease (Boolean)

    Mark this release as a pre-release

Returns:

  • (Sawyer::Resource)

    The release

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 30

def create_release(repo, tag_name, options = {})
  opts = options.merge(tag_name: tag_name)
  post "#{Repository.path repo}/releases", opts
end

#delete_release(url, options = {}) ⇒ Boolean

Delete a release

Parameters:

  • url (String)

    URL for the release as returned from .releases

Returns:

  • (Boolean)

    Success or failure

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 65

def delete_release(url, options = {})
  boolean_from_response(:delete, url, options)
end

#delete_release_asset(asset_url, options = {}) ⇒ Boolean

Delete a release asset

Parameters:

  • asset_url (String)

    URL for the asset as returned from .release_assets

Returns:

  • (Boolean)

    Success or failure

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 128

def delete_release_asset(asset_url, options = {})
  boolean_from_response(:delete, asset_url, options)
end

#edit_release(url, options = {})

Alias for #update_release.

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 58

alias edit_release update_release

#edit_release_asset(asset_url, options = {})

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 121

alias edit_release_asset update_release_asset

#latest_release(repo, options = {}) ⇒ Sawyer::Resource

Get the latest release

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

Returns:

  • (Sawyer::Resource)

    The release

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 147

def latest_release(repo, options = {})
  get "#{Repository.path repo}/releases/latest", options
end

#list_releases(repo, options = {})

Alias for #releases.

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 17

alias list_releases releases

#release(url, options = {}) ⇒ Sawyer::Resource

Get a release

Parameters:

  • url (String)

    URL for the release as returned from .releases

Returns:

  • (Sawyer::Resource)

    The release

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 40

def release(url, options = {})
  get url, options
end

#release_asset(asset_url, options = {}) ⇒ Sawyer::Resource

Get a single release asset

Parameters:

  • asset_url (String)

    URL for the asset as returned from .release_assets

Returns:

  • (Sawyer::Resource)

    The release asset

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 107

def release_asset(asset_url, options = {})
  get(asset_url, options)
end

#release_assets(release_url, options = {}) ⇒ Array<Sawyer::Resource>

List release assets

Parameters:

  • release_url (String)

    URL for the release as returned from .releases

Returns:

  • (Array<Sawyer::Resource>)

    A list of release assets

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 74

def release_assets(release_url, options = {})
  paginate release(release_url).rels[:assets].href, options
end

#release_for_tag(repo, tag_name, options = {}) ⇒ Sawyer::Resource

Get the release for a given tag

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • tag_name (String)

    the name for a tag

Returns:

  • (Sawyer::Resource)

    The release

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 138

def release_for_tag(repo, tag_name, options = {})
  get "#{Repository.path repo}/releases/tags/#{tag_name}", options
end

#releases(repo, options = {}) ⇒ Array<Sawyer::Resource> Also known as: #list_releases

List releases for a repository

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

Returns:

  • (Array<Sawyer::Resource>)

    A list of releases

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 14

def releases(repo, options = {})
  paginate "#{Repository.path repo}/releases", options
end

#update_release(url, options = {}) ⇒ Sawyer::Resource Also known as: #edit_release

Update a release

Parameters:

  • url (String)

    URL for the release as returned from .releases

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

    a customizable set of options

Options Hash (options):

  • :tag_name (String)

    Git tag from which to create release

  • :target_commitish (String)

    Specifies the commitish value that determines where the Git tag is created from.

  • :name (String)

    Name for the release

  • :body (String)

    Content for release notes

  • :draft (Boolean)

    Mark this release as a draft

  • :prerelease (Boolean)

    Mark this release as a pre-release

Returns:

  • (Sawyer::Resource)

    The release

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 55

def update_release(url, options = {})
  patch url, options
end

#update_release_asset(asset_url, options = {}) ⇒ Sawyer::Resource Also known as: #edit_release_asset

Update a release asset

Parameters:

  • asset_url (String)

    URL for the asset as returned from .release_assets

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

    a customizable set of options

Options Hash (options):

  • :name (String)

    The name for the file

  • :label (String)

    The download text for the file

Returns:

  • (Sawyer::Resource)

    The release asset

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 118

def update_release_asset(asset_url, options = {})
  patch(asset_url, options)
end

#upload_asset(release_url, path_or_file, options = {}) ⇒ Sawyer::Resource

Upload a release asset

Parameters:

  • release_url (String)

    URL for the release as returned from .releases

  • path_or_file (String)

    Path to file to upload

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

    a customizable set of options

Options Hash (options):

  • :content_type (String)

    The MIME type for the file to upload

  • :name (String)

    The name for the file

Returns:

  • (Sawyer::Resource)

    The release asset

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/releases.rb', line 86

def upload_asset(release_url, path_or_file, options = {})
  file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, 'rb')
  options[:content_type] ||= content_type_from_file(file)
  raise Octokit::MissingContentType if options[:content_type].nil?

  unless name = options[:name]
    name = File.basename(file.path)
  end
  upload_url = release(release_url).rels[:upload].href_template.expand(name: name)

  request :post, upload_url, file.read, parse_query_and_convenience_headers(options)
ensure
  file&.close
end