lib/helpers/github.rb in overview-0.0.5.pre.22 vs lib/helpers/github.rb in overview-0.0.6.pre.24
- old
+ new
@@ -1,81 +1,85 @@
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
+module Helpers
- APICache.store = Moneta.new(:YAML, :file => "#{self.class.name}_cache")
- APICache.logger.level = Logger::INFO
- #APICache.store = nil
- end
+ 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
+ if !@github_token || @github_token.empty?
+ $stderr.puts 'github_token missing. Unable to authenticate with Github. Aborting...'
+ exit 1
+ end
+ @repo = repo
+ @branch = branch
+ @logger = Logging.logger[self]
+ @logger.add_appenders \
+ Logging.appenders.stdout,
+ Logging.appenders.file('overview.log')
+ @logger.level = :info
- 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
+ APICache.store = Moneta.new(:YAML, :file => "#{self.class.name}_cache")
+ APICache.logger.level = Logger::INFO
+ #APICache.store = nil
end
- @client
- end
- def hooks
- @hooks = client.hooks(@repo) unless @hooks
- @logger.info "Retrieved hooks for #{@repo}" if @hooks
- @hooks
- end
+ def client
+ if !@client
- def releases
- #APICache.get("releases") do
- client.releases(@repo)
- #end
- end
+ @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 as #{@client.user[:login]}"
+ end
+ @client
+ 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
+ def hooks
+ @hooks = client.hooks(@repo) unless @hooks
+ @logger.info "Retrieved hooks for #{@repo}" if @hooks
+ @hooks
end
- end
- def ref(tag)
- #APICache.get("ref_#{tag}") do
- client.ref(@repo, "tags/" + tag)
- #end
- end
+ def releases
+ #APICache.get("releases") do
+ client.releases(@repo)
+ #end
+ end
- def commit(sha)
- #APICache.get("commit_#{sha}") do
- client.commit(@repo, sha)
- #end
- end
+ def sprintly_product_id
+ 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
- def commits_since(since)
- #APICache.get("commit_since_#{since}") do
- client.commits_since(@repo, since, @branch)
- #end
- end
+ def ref(tag)
+ #APICache.get("ref_#{tag}") do
+ client.ref(@repo, "tags/" + tag)
+ #end
+ end
- def commits_between(from,to)
+ def commit(sha)
+ #APICache.get("commit_#{sha}") do
+ client.commit(@repo, sha)
+ #end
+ end
- end
- def commits_before(to)
+ 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
end