Class: Stove::Plugin::GitHub

Inherits:
Base
  • Object
show all
Defined in:
lib/stove/plugins/github.rb

Instance Attribute Summary

Attributes inherited from Base

#cookbook, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, onload

Methods included from Mixin::Filterable

#after, #before

Methods included from Mixin::Optionable

extended, included

Methods included from Mixin::Validatable

#validate

Constructor Details

This class inherits a constructor from Stove::Plugin::Base

Instance Method Details

#changesetObject



52
53
54
# File 'lib/stove/plugins/github.rb', line 52

def changeset
  @changeset ||= cookbook.changeset.split("\n")[2..-1].join("\n").strip
end

#clientObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stove/plugins/github.rb', line 39

def client
  return @client if @client

  config = {}.tap do |h|
    h[:middleware]   = middleware
    h[:access_token] = Config[:github][:access_token]
    h[:api_endpoint] = Config[:github][:api_endpoint] if Config[:github][:api_endpoint]
  end

  @client = Octokit::Client.new(config)
  @client
end

#filenameObject



60
61
62
# File 'lib/stove/plugins/github.rb', line 60

def filename
  @filename ||= "#{cookbook.name}-#{cookbook.version}.tar.gz"
end

#middlewareObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/stove/plugins/github.rb', line 64

def middleware
  Faraday::Builder.new do |builder|
    # Handle any common errors
    builder.use Stove::Middleware::Exceptions
    builder.use Octokit::Response::RaiseError

    # Log all requests and responses (useful for development)
    builder.response :logger, log

    # Raise errors on 40x and 50x responses
    builder.response :raise_error

    # Use the default adapter (Net::HTTP)
    builder.adapter :net_http
  end
end

#repo_urlString

The URL for this repository on GitHub. This method automatically translates SSH and git:// URLs to https:// URLs.

Returns:

  • (String)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/stove/plugins/github.rb', line 87

def repo_url
  return @repo_url if @repo_url

  path = File.join('.git', 'config')
  log.debug("Calculating repo_url from `#{path}'")

  config = File.read(path)
  log.debug("Config contents:\n#{config}")

  config =~ /\[remote "#{options[:remote]}"\]\n\s+url = (.+)$/
  log.debug("Match: #{$1.inspect}")

  @repo_url = $1.to_s
                .strip
                .gsub(/\.git$/, '')
                .gsub(/^\S+@(\S+):/, 'https://\1/')
                .gsub('git://', 'https://')
  @repo_url
end

#repositoryObject



56
57
58
# File 'lib/stove/plugins/github.rb', line 56

def repository
  @repository ||= Octokit::Repository.from_url(repo_url)
end