deploy_log 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccbe91ec7a739d08b9f41ea94337f3b7df8bef343ee66ad3583950207e2a985f
4
- data.tar.gz: c0f482427799350c9f665a802f8f650fb32a4e2d23395b70f02373ccc3e80ff1
3
+ metadata.gz: ef93d5a2afbcc419b9f158b649025ead5cbed923937f8f3fd45fdacbb666e807
4
+ data.tar.gz: ab722cf7af7ce6b961b86e7710052f5baa314db360b26a341cbe966aaf9852f6
5
5
  SHA512:
6
- metadata.gz: 151e8cb216f20ce041c40ba81d38c84a644f30c731a73882bbadb8cf13ddea34e452ea3ffa6dd593bb0e3d8e68e9398144d328cceca4e3c3d61eed1c4f84f170
7
- data.tar.gz: 8d08ec5d7934525c7e0e88c931d134935c2200e17e6a40a1378615dcaec4ef0dea530e7e8edd64cde0d4c3263d456770186ab2b8e7d34138c11b69e992471117
6
+ metadata.gz: fa1a856e43ad6c276ab50536de857027a8c8aaf45d1b9f7de4eff22fce267d333d41e1fda2d13b16ac6cf99140a3f2769acef8c0812722235b6e7d83989dd3c3
7
+ data.tar.gz: d955a037e8b3c149a79a03aa6dc48265bf696623eec01b4d132250b04e2d5cfdd96ae023b4627becb8a83a6fb9914447a3941c8596dd5cc4de65ffe23241e1a9
data/bin/deploy_log CHANGED
@@ -31,7 +31,7 @@ OptionParser.new do |opt|
31
31
  end
32
32
 
33
33
  opt.on('-c', '--clean', 'Pull data from api, ignore cache') do
34
- system('rm -f /tmp/github-deploys-*.log')
34
+ FileUtils.rm '/tmp/github-deploys-*.log'
35
35
  Notify.info 'Cleared cache'
36
36
  exit
37
37
  end
@@ -13,14 +13,14 @@ module DeployLog
13
13
 
14
14
  finish = Date.today.to_time + (24 * 60 * 60) - 1 if finish.nil?
15
15
 
16
- @github.pulls_in_timeframe(start, finish)
16
+ render @github.pulls_in_timeframe(start, finish)
17
17
  end
18
18
 
19
19
  def merged_today
20
20
  start = Date.today.to_time # 12:00AM this morning
21
21
  finish = Date.today.to_time + (24 * 60 * 60) - 1 # 11:59PM tonight
22
22
 
23
- @github.pulls_in_timeframe(start, finish)
23
+ render @github.pulls_in_timeframe(start, finish)
24
24
  end
25
25
 
26
26
  def merged_on(start)
@@ -28,7 +28,7 @@ module DeployLog
28
28
 
29
29
  finish = start + 24 * 60 * 60 - 1
30
30
 
31
- @github.pulls_in_timeframe(start, finish)
31
+ render @github.pulls_in_timeframe(start, finish)
32
32
  end
33
33
 
34
34
  def merged_during_week(week_num)
@@ -36,15 +36,21 @@ module DeployLog
36
36
 
37
37
  week = @calendar.week(week_num.to_i)
38
38
 
39
- @github.pulls_in_timeframe(week[:first], week[:last])
39
+ render @github.pulls_in_timeframe(week[:first], week[:last])
40
40
  end
41
41
 
42
42
  def pr_title(title)
43
- @github.search_pulls_by(title, :title)
43
+ render @github.search_pulls_by(title, :title)
44
44
  end
45
45
 
46
46
  def pr_for_branch(branch)
47
- @github.search_pulls_by(branch, :ref)
47
+ render @github.search_pulls_by(branch, :ref)
48
+ end
49
+
50
+ private
51
+
52
+ def render(data)
53
+ puts data
48
54
  end
49
55
  end
50
56
  end
@@ -5,6 +5,8 @@ require 'fileutils'
5
5
 
6
6
  module DeployLog
7
7
  module Github
8
+ class FileNotFound < StandardError; end
9
+
8
10
  class Helper
9
11
  LINE_FORMAT = "%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n -- %s\n\n"
10
12
 
@@ -14,8 +16,8 @@ module DeployLog
14
16
  end
15
17
 
16
18
  def pulls_in_timeframe(date_start = nil, date_end = nil)
17
- cache = cache_file(date_start, date_end)
18
- return cache[:contents] if should_show_cache(cache)
19
+ cache_path = cache(date_start, date_end)
20
+ return cat(cache_path) if should_show_cache(cache_path)
19
21
 
20
22
  @client.auto_paginate = true
21
23
  list = @client.pull_requests(@repo_location,
@@ -26,7 +28,7 @@ module DeployLog
26
28
 
27
29
  prs_covered = 0
28
30
 
29
- File.open(cache[:path], 'w+') do |f|
31
+ File.open(cache_path, 'w+') do |f|
30
32
  list.each do |pr|
31
33
  next unless (date_start..date_end).cover? pr.merged_at
32
34
 
@@ -52,12 +54,12 @@ module DeployLog
52
54
 
53
55
  return ::Notify.warning("No pull requests have been merged in the requested date range (#{date_start} - #{date_end})") if prs_covered.zero?
54
56
 
55
- cache[:contents]
57
+ cat(cache_path)
56
58
  end
57
59
 
58
60
  def search_pulls_by(value, field = :title)
59
- cache = cache_file(value, field)
60
- return cache[:contents] if should_show_cache(cache)
61
+ cache_path = cache_file(value, field)
62
+ return cat(cache_path) if should_show_cache(cache_path)
61
63
 
62
64
  list = @client.pull_requests(@repo_location,
63
65
  :state => :all,
@@ -65,7 +67,7 @@ module DeployLog
65
67
  )
66
68
  prs_covered = 0
67
69
 
68
- File.open(cache[:path], 'w+') do |f|
70
+ File.open(cache_path, 'w+') do |f|
69
71
  list.each do |pr|
70
72
  next unless nested_hash_value(pr, field).match?(/#{value}\b/)
71
73
 
@@ -91,7 +93,7 @@ module DeployLog
91
93
 
92
94
  return ::Notify.warning("No pull requests match the requested term (#{value})") if prs_covered.zero?
93
95
 
94
- cache[:contents]
96
+ cat(cache_path)
95
97
  end
96
98
 
97
99
  private
@@ -108,18 +110,21 @@ module DeployLog
108
110
  end
109
111
  end
110
112
 
111
- def cache_file(*args)
113
+ def cache(*args)
112
114
  hash = Digest::MD5.hexdigest(@repo_location + args.join('|'))
113
115
  path = FileUtils.touch "/tmp/github-deploys-#{hash}.log"
114
116
 
115
- {
116
- contents: system("cat #{path.first}"),
117
- path: path.first
118
- }
117
+ path.first
118
+ end
119
+
120
+ def should_show_cache(cache_file_path)
121
+ File.exist?(cache_file_path) && !File.size(cache_file_path).zero?
119
122
  end
120
123
 
121
- def should_show_cache(cache)
122
- File.exist?(cache[:path]) && !File.size(cache[:path]).zero?
124
+ def cat(path)
125
+ raise FileNotFound unless should_show_cache(path)
126
+
127
+ File.read(path)
123
128
  end
124
129
 
125
130
  def formatted_time(time, use_local_time = false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeployLog
4
- VERSION = '0.2.5'
4
+ VERSION = '0.2.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler