class Gemnasium::GitlabService::Pusher

Push all dependency files of a git repo to Gemnasium.

Constants

DependencyFile

Attributes

branch_name[R]
client[R]
commit_sha[R]
project_slug[R]
repo_path[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/gemnasium/gitlab_service/pusher.rb, line 16
def initialize(options = {})
  @repo_path = options.fetch(:repo)
  @commit_sha = options.fetch(:after)
  @branch_name = options.fetch(:ref).to_s.sub(/\Arefs\/(heads|tags)\//, '')
  @project_slug = options.fetch(:token)
  @client ||= options.fetch(:client){ Gemnasium::GitlabService::Client.new(options) }
end

Public Instance Methods

call() click to toggle source

Push all dependency files

# File lib/gemnasium/gitlab_service/pusher.rb, line 26
def call
  if dependency_files.any?
    client.upload_files(
      dependency_files, project_slug,
      branch_name, commit_sha
    )
  end
end

Private Instance Methods

convert_entry(entry) click to toggle source

Convert a commit entry for the Gemnasium client

# File lib/gemnasium/gitlab_service/pusher.rb, line 62
def convert_entry(entry)
  path = path_for_entry entry
  blob = repo.lookup entry.last[:oid]
  DependencyFile.new path, blob.oid, blob.text
end
dependency_files() click to toggle source

Return the dependency files as an array

# File lib/gemnasium/gitlab_service/pusher.rb, line 39
def dependency_files
  @dependency_files = (
    walker.inject([]) do |files, entry|
      files << convert_entry(entry) if is_entry_supported?(entry)
      files
    end
  )
end
is_entry_supported?(entry) click to toggle source

Tell whether or not a commit entry is a supported dependency file

# File lib/gemnasium/gitlab_service/pusher.rb, line 70
def is_entry_supported?(entry)
  path_for_entry(entry).match supported_path_regexp
end
path_for_entry(entry) click to toggle source

Extract file path from a git entry

# File lib/gemnasium/gitlab_service/pusher.rb, line 76
def path_for_entry(entry)
  entry[0..-2].join('/') + entry.last[:name]
end
repo() click to toggle source

Return a Rugged::Repository

# File lib/gemnasium/gitlab_service/pusher.rb, line 56
def repo
  @repo ||= Rugged::Repository.new(repo_path)
end
supported_path_regexp() click to toggle source

Return regexp that matches the path of a supported dependency file

# File lib/gemnasium/gitlab_service/pusher.rb, line 82
def supported_path_regexp
  /(Gemfile|Gemfile\.lock|.*\.gemspec|package\.json|npm-shrinkwrap\.json|setup\.py|requires\.txt|requirements\.txt|requirements\.pip|requirements.*\.txt|composer\.json|composer\.lock|bower\.json)$/
end
walker() click to toggle source

Return a Rugged::Walker that goes through the entries of the commit

# File lib/gemnasium/gitlab_service/pusher.rb, line 50
def walker
  repo.lookup(commit_sha).tree.walk(:postorder)
end