Class: Chef::Taste::Changelog::GithubChangelog

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/taste/changelog.rb

Overview

The class for computing the changelog for cookbooks hosted in Github.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, from_version, to_version) ⇒ GithubChangelog

Constructor

Parameters:

  • repo (String)

    the Github repo

  • from_version (String)

    the version to compare from

  • to_version (String)

    the version to compare to



72
73
74
75
76
# File 'lib/chef/taste/changelog.rb', line 72

def initialize(repo, from_version, to_version)
  @repo = repo
  @from_version = from_version
  @to_version = to_version
end

Instance Attribute Details

#from_versionObject (readonly)

The version to compare from



59
60
61
# File 'lib/chef/taste/changelog.rb', line 59

def from_version
  @from_version
end

#repoObject (readonly)

The Github repository



56
57
58
# File 'lib/chef/taste/changelog.rb', line 56

def repo
  @repo
end

#to_versionObject (readonly)

The version to compare to



62
63
64
# File 'lib/chef/taste/changelog.rb', line 62

def to_version
  @to_version
end

Instance Method Details

#compare_url(from_tag, to_tag) ⇒ String

Returns the compare URL for comparing two tags on Github

Parameters:

  • from_tag (String)

    the tag to compare from

  • to_tag (String)

    the tag to compare to

Returns:

  • (String)

    the Github URL to compare given two tags



101
102
103
# File 'lib/chef/taste/changelog.rb', line 101

def compare_url(from_tag, to_tag)
  "https://github.com/#{repo}/compare/#{from_tag}...#{to_tag}"
end

#computeString

Computes the changelog URL for Github repositories

Returns:

  • (String)

    the computed changelog URL



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/chef/taste/changelog.rb', line 82

def compute
  tags = Octokit.tags(repo)
  from_tag = nil
  to_tag = nil
  tags.each do |tag|
    tag_name = tag.name
    from_tag = tag_name if tag_name =~ /v?#{from_version}/
    to_tag = tag_name if tag_name =~ /v?#{to_version}/
  end
  compare_url(from_tag, to_tag) if from_tag && to_tag
end