Module: Octokit::Client::Releases

Included in:
Octokit::Client
Defined in:
lib/octokit/client/releases.rb

Overview

Methods for the Releases API

Instance Method Summary collapse

Instance Method Details

#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:



30
31
32
33
# 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:



65
66
67
# 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:



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

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

#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:



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

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

#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:



40
41
42
# 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:



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

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:



74
75
76
# 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:



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

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:



14
15
16
# 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:



55
56
57
# 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:



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

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:



86
87
88
89
90
91
92
93
94
95
96
97
98
# 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.new 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 if file
end