Class: GemHadar::GitHub::ReleaseCreator
- Inherits:
-
Object
- Object
- GemHadar::GitHub::ReleaseCreator
- Defined in:
- lib/gem_hadar/github.rb
Class Attribute Summary collapse
-
.github_api_url ⇒ Object
Returns the value of attribute github_api_url.
Instance Method Summary collapse
-
#initialize(owner:, repo:, token:, api_version: '2022-11-28') ⇒ ReleaseCreator
constructor
A new instance of ReleaseCreator.
- #perform(tag_name:, target_commitish:, body:, name: tag_name, draft: false, prerelease: false) ⇒ Object
Constructor Details
#initialize(owner:, repo:, token:, api_version: '2022-11-28') ⇒ ReleaseCreator
Returns a new instance of ReleaseCreator.
13 14 15 16 17 18 |
# File 'lib/gem_hadar/github.rb', line 13 def initialize(owner:, repo:, token:, api_version: '2022-11-28') @owner = owner @repo = repo @token = token @api_version = api_version end |
Class Attribute Details
.github_api_url ⇒ Object
Returns the value of attribute github_api_url.
9 10 11 |
# File 'lib/gem_hadar/github.rb', line 9 def github_api_url @github_api_url end |
Instance Method Details
#perform(tag_name:, target_commitish:, body:, name: tag_name, draft: false, prerelease: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gem_hadar/github.rb', line 20 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 |