Sha256: afc48539d5c270ad31300aa8559cd3b6cc48f014603a25abffb0b201dee6e9b4

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

require 'api_cache'
require 'moneta'
require 'octokit'
#TODO - this is actually a github class
class Github
  #TODO make this a singleton
  #TODO add repo, and branch to cache keys
  def initialize(repo, branch, github_token=ENV['GITHUB_TOKEN'])
    #TODO: inherit from base class
    @github_token = github_token
    @repo = repo
    @branch = branch
    @logger = Logging.logger[self]
    @logger.add_appenders \
        Logging.appenders.stdout,
        Logging.appenders.file('overview.log')
    @logger.level = :info

    APICache.store = Moneta.new(:YAML, :file => "#{self.class.name}_cache")
    APICache.logger.level = Logger::INFO
    #APICache.store = nil
  end

  def client
    if !@client
      @client = Octokit::Client.new(:access_token => @github_token)
      @client.auto_paginate = true
      @client.default_media_type = "application/vnd.github.moondragon+json"
      @logger.info "Connected to Github" if @client
    end
    @client
  end

  def hooks
      @hooks = client.hooks(@repo) unless @hooks
      @logger.info "Retrieved hooks for #{@repo}" if @hooks
      @hooks
  end

  def releases
    #APICache.get("releases") do
      client.releases(@repo)
    #end
  end

  def sprintly_product_id
    #TODO this could also return a CLI flag or env variable
    APICache.get("sprintly_product_id_#{@repo}", :fail => [], :timeout => 30) do
      @logger.info "Not using cache"
      product_id = hooks.map { |h| h.config.product_id }.compact.first
      @logger.info "Sprint.ly product_id = #{product_id}" if product_id
      product_id
    end
  end

  def ref(tag)
    #APICache.get("ref_#{tag}") do
      client.ref(@repo, "tags/" + tag)
    #end
  end

  def commit(sha)
    #APICache.get("commit_#{sha}") do
      client.commit(@repo, sha)
    #end
  end

  def commits_since(since)
    #APICache.get("commit_since_#{since}") do
      client.commits_since(@repo, since, @branch)
    #end
  end

  def commits_between(from,to)

  end
  def commits_before(to)

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
overview-0.0.5.pre.22 lib/helpers/github.rb
overview-0.0.4.17 lib/helpers/github.rb
overview-0.0.4.14 lib/helpers/github.rb
overview-0.0.4.12 lib/helpers/github.rb