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

Inherits:
Base
  • Object
show all
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 inherited from Base

worker_type

Methods included from Mixin::Services

extended, included

Methods included from Logging

init, #logger

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



19
20
21
22
23
24
25
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 19

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]
  super(options)
end

Instance Attribute Details

#organizationString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 12

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 34

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(repo.name, .version,
                self.class.worker_type, repo.full_name, priority)
            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)


68
69
70
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 68

def (remote)
  (remote.name, "v#{remote.version}")
end

#to_sString

Returns:

  • (String)


28
29
30
# File 'lib/berkshelf/api/cache_builder/worker/github.rb', line 28

def to_s
  friendly_name(organization)
end