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



77
78
79
80
81
# File 'lib/chef/taste/changelog.rb', line 77

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



64
65
66
# File 'lib/chef/taste/changelog.rb', line 64

def from_version
  @from_version
end

#repoObject (readonly)

The Github repository



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

def repo
  @repo
end

#to_versionObject (readonly)

The version to compare to



67
68
69
# File 'lib/chef/taste/changelog.rb', line 67

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



106
107
108
# File 'lib/chef/taste/changelog.rb', line 106

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



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chef/taste/changelog.rb', line 87

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