Class: DeployLog::Github::Helper

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

Constant Summary collapse

LINE_FORMAT =
"%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n -- %s\n\n"

Instance Method Summary collapse

Constructor Details

#initialize(user_repo) ⇒ Helper

Returns a new instance of Helper.



10
11
12
13
# File 'lib/deploy_log/github/helper.rb', line 10

def initialize(user_repo)
  @api = Api.new(user_repo)
  @cache = DeployLog::Cache.new('github-deploys-%s.log', repo: user_repo)
end

Instance Method Details

#pulls_in_timeframe(date_start, date_end) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/deploy_log/github/helper.rb', line 15

def pulls_in_timeframe(date_start, date_end)
  @cache.create(date_start, date_end)
  return @cache.contents if @cache.exists?

  pool = timeframe_pool(date_start, date_end)
  message = "#{pool.size} PR(s) merged from #{date_start} to #{date_end}"

  @cache.write_object(pool, message) do |item|
    format(LINE_FORMAT,
      item.title,
      item.html_url,
      item.user.,
      item.head.ref,
      user_who_merged(item.number),
      formatted_time(item.merged_at, true),
      item.diff_url,
      committers_for(item.number).join("\n -- ")
    )
  end

  @cache.contents
end

#search_pulls_by(value, field = :title) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/deploy_log/github/helper.rb', line 38

def search_pulls_by(value, field = :title)
  @cache.create(field, value)
  return @cache.contents if @cache.exists?

  pool = search_pool(field, value)
  message = "#{pool.size} PR(s) matched"

  @cache.write_object(pool, message) do |item|
    format(LINE_FORMAT,
      item.title,
      item.html_url,
      item.user.,
      item.head.ref,
      user_who_merged(item.number),
      formatted_time(item.merged_at, true),
      item.diff_url,
      committers_for(item.number).join("\n -- ")
    )
  end

  @cache.contents
end