Class: Releasinator::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/publisher.rb

Instance Method Summary collapse

Constructor Details

#initialize(releasinator_config) ⇒ Publisher

Returns a new instance of Publisher.



8
9
10
# File 'lib/publisher.rb', line 8

def initialize(releasinator_config)
  @releasinator_config = releasinator_config
end

Instance Method Details

#publish(repo_url, release) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# 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