class GemHadar::GitHub::ReleaseCreator

def perform(tag_name:, target_commitish:, body:, name: tag_name, draft: false, prerelease: false)

Raises:
  • (RuntimeError) - if the GitHub API request fails with a non-success status code

Returns:
  • (JSON::GenericObject) - the parsed response data from the GitHub API containing

Parameters:
  • prerelease (Boolean) -- whether to mark the release as a pre-release (defaults to false)
  • draft (Boolean) -- whether to create a draft release (defaults to false)
  • name (String) -- the name of the release (defaults to tag_name)
  • body (String) -- the release notes or description content
  • target_commitish (String) -- the commit SHA or branch name to use for the release
  • tag_name (String) -- the name of the tag to associate with the release
def perform(tag_name:, target_commitish:, body:, name: tag_name, draft: false, prerelease: false)
  uri = URI("#{self.class.github_api_url}/repos/#@owner/#@repo/releases")
  headers = {
    "Accept"               => "application/vnd.github+json",
    "Authorization"        => "Bearer #@token",
    "Content-Type"         => "application/json",
    "X-GitHub-Api-Version" => @api_version,
    "User-Agent"           => [ GemHadar.name, GemHadar::VERSION ] * ?/,
  }
  data = {
    tag_name:,
    target_commitish:,
    body:,
    name:,
    draft:,
    prerelease:,
  }.compact
  response = Net::HTTP.post(uri, JSON(data), headers)
  case response
  when Net::HTTPSuccess
    JSON.parse(response.body, object_class: JSON::GenericObject)
  else
    error_data =
      begin
        JSON.pretty_generate(JSON.parse(response.body))
      rescue
        response.body
      end
    raise "Failed to create release. Status: #{response.code}\n\n#{error_data}"
  end
end