Class: Berkshelf::API::CacheBuilder::Worker::Github

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/berkshelf/api/cache_builder/worker/github.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #priority

Instance Method Summary collapse

Methods included from Logging

init, #logger

Methods inherited from Base

worker_type

Methods included from Mixin::Services

extended, included

Constructor Details

#initialize(options = {}) ⇒ Github

Returns a new instance of Github.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :organization (String)

    the organization to crawl for cookbooks

  • :access_token (String)

    authentication token for accessing the Github organization. This is necessary since Github throttles unauthenticated API requests



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 21

def initialize(options = {})
  @connection   = Octokit::Client.new(access_token: options[:access_token], auto_paginate: true,
    api_endpoint: options[:api_endpoint], web_endpoint: options[:web_endpoint],
    connection_options: {ssl: {verify: options[:ssl_verify].nil? ? true : options[:ssl_verify]}})
  @organization = options[:organization]

  log.warn "You have configured a GitHub endpoint to index the #{@organization} organization."
  log.warn "Using unfinalized artifacts, such as cookbooks retrieved from Git, to satisfiy your"
  log.warn "dependencies is *STRONGLY FROWNED UPON* and potentially *DANGEROUS*."
  log.warn ""
  log.warn "Please consider setting up a release process for the cookbooks you wish to retrieve from this"
  log.warn "GitHub organization where the cookbook is uploaded into a Hosted Chef organization, an internal"
  log.warn "Chef Server, or the community site, and then replace this endpoint with a chef_server endpoint."

  super(options)
end

Instance Attribute Details

#organizationString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 14

def organization
  @organization
end

Instance Method Details

#cookbooksArray<RemoteCookbook>

Returns The list of cookbooks this builder can find.

Returns:

  • (Array<RemoteCookbook>)

    The list of cookbooks this builder can find



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 45

def cookbooks
  [].tap do |cookbook_versions|
    connection.organization_repositories(organization).each do |repo|
      connection.tags(repo.full_name).each do |tag|
        if match = /^v(?<version>.*)$/.match(tag.name)
          begin
            next unless  = (repo.name, tag.name)

            if .version.to_s == match[:version].to_s
              cookbook_versions << RemoteCookbook.new(.name, .version,
                self.class.worker_type, repo.html_url, priority, {:repo_name => repo.name} )
            else
              log.warn "Version found in metadata for #{repo.name} (#{tag.name}) does not " +
                "match the tag. Got #{.version}."
            end
          rescue Semverse::InvalidVersionFormat
            log.debug "Ignoring tag #{tag.name} for: #{repo.name}. Does not conform to semver."
          rescue Octokit::NotFound
            log.debug "Ignoring tag #{tag.name} for: #{repo.name}. No raw metadata found."
          end
        else
          log.debug "Version number cannot be parsed"
        end
      end
    end
  end
end

#metadata(remote) ⇒ Ridley::Chef::Cookbook::Metadata?

Return the metadata of the given RemoteCookbook. If the metadata could not be found or parsed nil is returned.

Parameters:

Returns:

  • (Ridley::Chef::Cookbook::Metadata, nil)


79
80
81
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 79

def (remote)
  (remote.info[:repo_name], "v#{remote.version}")
end

#to_sString

Returns:

  • (String)


39
40
41
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 39

def to_s
  friendly_name(organization)
end