Class: Github

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/github.rb

Overview

TODO - this is actually a github class

Instance Method Summary collapse

Constructor Details

#initialize(repo, branch, github_token = ENV['GITHUB_TOKEN']) ⇒ Github

TODO make this a singleton TODO add repo, and branch to cache keys



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/helpers/github.rb', line 8

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

Instance Method Details

#clientObject



24
25
26
27
28
29
30
31
32
# File 'lib/helpers/github.rb', line 24

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

#commit(sha) ⇒ Object



62
63
64
65
66
# File 'lib/helpers/github.rb', line 62

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

#commits_before(to) ⇒ Object



77
78
79
# File 'lib/helpers/github.rb', line 77

def commits_before(to)

end

#commits_between(from, to) ⇒ Object



74
75
76
# File 'lib/helpers/github.rb', line 74

def commits_between(from,to)

end

#commits_since(since) ⇒ Object



68
69
70
71
72
# File 'lib/helpers/github.rb', line 68

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

#hooksObject



34
35
36
37
38
# File 'lib/helpers/github.rb', line 34

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

#ref(tag) ⇒ Object



56
57
58
59
60
# File 'lib/helpers/github.rb', line 56

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

#releasesObject



40
41
42
43
44
# File 'lib/helpers/github.rb', line 40

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

#sprintly_product_idObject



46
47
48
49
50
51
52
53
54
# File 'lib/helpers/github.rb', line 46

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