class Releasinator::Publisher

Public Class Methods

new(releasinator_config) click to toggle source
# File lib/publisher.rb, line 8
def initialize(releasinator_config)
  @releasinator_config = releasinator_config
end

Public Instance Methods

publish(repo_url, release) click to toggle source
# File lib/publisher.rb, line 12
def publish(repo_url, release)
  github_repo = GitHubRepo.new(repo_url)

  begin
    # https://github.com/octokit/octokit.rb/blob/master/spec/octokit/client/releases_spec.rb#L18
    github_release = github_repo.client.create_release "#{github_repo.org}/#{github_repo.repo}",
      release.version,
      :name => release.version,
      :body => release.changelog
    puts github_release.inspect if @releasinator_config[:trace]
  rescue => error
    #This will fail if the user does not have push permissions.
    Printer.fail(error.inspect)
    abort()
  end
end
publish_pull_request(repo_url, release, product_name, base, head) click to toggle source
# File lib/publisher.rb, line 41
def publish_pull_request(repo_url, release, product_name, base, head)
  begin
    github_repo = GitHubRepo.new(repo_url)
    github_pull_request = github_repo.client.create_pull_request "#{github_repo.org}/#{github_repo.repo}",
      base,
      head,
      "Update #{product_name} to #{release.version}",
      release.changelog
    puts github_pull_request.inspect if @releasinator_config[:trace]
  rescue => error
    #This will fail if there's already a pull request
    Printer.fail(error.inspect)
    abort()
  end
end
upload_asset(repo_url, release, path_or_file, content_type) click to toggle source
# File lib/publisher.rb, line 29
def upload_asset(repo_url, release, path_or_file, content_type)
  begin
    github_repo = GitHubRepo.new(repo_url)
    github_release = github_repo.client.release_for_tag "#{github_repo.org}/#{github_repo.repo}", release.version
    github_repo.client.upload_asset github_release.url, path_or_file, :content_type => content_type
  rescue => error
    #This will fail if it cannot upload the files
    Printer.fail(error.inspect)
    abort()
  end
end