deploy_log 0.1.2 → 0.1.3

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: 209a362b0d17aa8ebf906ba958a966746950aecdf195b54e4ef3216720bf3510
4
- data.tar.gz: 8a66ad9e3fd0a10fa5dcecd44bd6ab1d746f6be490a9cb3ec05ea2a01792dabb
3
+ metadata.gz: 23d0960ccf7f887e89ae3a12161c82448f92475f41c765c589a133a11a168682
4
+ data.tar.gz: 8069578f9c142ced9585b07d4757938fa2dd91305dec5c9a15ba2d8ebe4cb2a0
5
5
  SHA512:
6
- metadata.gz: 29db8decd8a200239eaa0774325da737bd0e942c9c22b557dd93da5270d5fb045b2fdfdedebd5a0cfcab64e45a36737c3010510591bdf5e37d12d60c499e1c98
7
- data.tar.gz: a9d4b303397602eeae5f4ce555f6cc438f4c031472e0e484f5d03e02f9e2e5d06201ddbe84538469b3087c070da845b7cec7b6acb4587e56184156d90a183e0f
6
+ metadata.gz: 2e82325ee4fd877a8bea8a3b31b42f68a6a47fff4d94fad123c0787375537a2bede5b3809627fef6f0298971a21182150103bd41fa922e87effdad7d3519977e
7
+ data.tar.gz: 0c137aa45ae14b8a82dcfea66d9716f9bbf703bb971bcbe08108d2d71403fc0719e05463f5bfafa8135c18008ab52d1f0a869a1860e0d835e3c07510601e73c8
data/bin/deploy_log CHANGED
@@ -1,10 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'notifaction'
5
- require 'octokit'
6
- require 'optionparser'
7
- require 'time'
8
4
  require 'deploy_log'
9
5
 
10
6
  start, finish, title, branch = nil
@@ -32,7 +28,7 @@ OptionParser.new do |opt|
32
28
  end
33
29
  end.parse!
34
30
 
35
- model = GithubDeploys.new
31
+ model = DeployLog::Github::Deploys.new
36
32
  model.merged_between(start, finish) if start && finish
37
33
  model.pr_title(title) if title
38
34
  model.pr_for_branch(branch) if branch
data/lib/deploy_log.rb CHANGED
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'notifaction'
4
+ require 'octokit'
5
+ require 'optionparser'
6
+ require 'time'
1
7
  require 'deploy_log/version'
2
- require 'deploy_log/github_helper'
3
- require 'deploy_log/github_deploys'
8
+ require 'deploy_log/github/helper'
9
+ require 'deploy_log/github/deploys'
4
10
 
5
11
  module DeployLog
6
12
  class Error < StandardError; end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeployLog
4
+ module Github
5
+ class Deploys
6
+ def initialize
7
+ @github = Helper.new(ARGV.first)
8
+ end
9
+
10
+ def merged_between(start, finish)
11
+ unless start && finish
12
+ Notify.error("Start and end dates (--start= and --end=) are required")
13
+ end
14
+
15
+ @github.pulls_in_timeframe(start, finish)
16
+ end
17
+
18
+ def merged_today
19
+ start = Date.today.to_time # 12:00AM this morning
20
+ finish = Date.today.to_time + (24 * 60 * 60) - 1 # 11:59PM tonight
21
+
22
+ @github.pulls_in_timeframe(start, finish)
23
+ end
24
+
25
+ def merged_on(start)
26
+ unless start
27
+ Notify.error("Start date (--start=) is required")
28
+ end
29
+
30
+ finish = start + 24 * 60 * 60 - 1
31
+
32
+ @github.pulls_in_timeframe(start, finish)
33
+ end
34
+
35
+ def pr_title(title)
36
+ @github.search_pulls_by(title, :title)
37
+ end
38
+
39
+ def pr_for_branch(branch)
40
+ @github.search_pulls_by(branch, :ref)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit'
4
+
5
+ module DeployLog
6
+ module Github
7
+ class Helper
8
+ def initialize(user_repo)
9
+ @client = ::Octokit::Client.new(login: ENV['GITHUB_USER'], password: ENV['GITHUB_TOKEN'])
10
+ @repo_location = user_repo
11
+ end
12
+
13
+ def pulls_in_timeframe(date_start = nil, date_end = nil)
14
+ @client.auto_paginate = true
15
+ list = @client.pull_requests(@repo_location,
16
+ state: :closed,
17
+ per_page: 500,
18
+ sort: 'long-running'
19
+ )
20
+
21
+ pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n\n"
22
+ prs_covered = 0
23
+
24
+ File.open('/tmp/github-deploys.log', 'w+') do |f|
25
+ list.each do |pr|
26
+ next unless (date_start..date_end).cover? pr.merged_at
27
+
28
+ prs_covered += 1
29
+
30
+ f.write(
31
+ sprintf(
32
+ pr_format_str,
33
+ pr.title,
34
+ pr.html_url,
35
+ pr.user.login,
36
+ pr.head.ref,
37
+ user_who_merged(pr.number),
38
+ formatted_time(pr.merged_at),
39
+ pr.diff_url
40
+ )
41
+ )
42
+ end
43
+
44
+ f.write("============================================================\n#{prs_covered} PR(s) merged from #{date_start} to #{date_end}\n============================================================\n")
45
+ end
46
+
47
+ return ::Notify.warning("No pull requests have been merged in the requested date range (#{date_start} - #{date_end})") if prs_covered.zero?
48
+
49
+ system('cat /tmp/github-deploys.log')
50
+ end
51
+
52
+ def search_pulls_by(value, field = :title)
53
+ list = @client.pull_requests(@repo_location,
54
+ :state => :all,
55
+ :per_page => 100
56
+ )
57
+ # pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Changes: %s\n\n"
58
+ pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n\n"
59
+ prs_covered = 0
60
+
61
+ File.open('/tmp/github-deploys.log', 'w+') do |f|
62
+ list.each do |pr|
63
+ next unless nested_hash_value(pr, field).match?(/#{value}\b/)
64
+
65
+ prs_covered += 1
66
+
67
+ f.write(
68
+ sprintf(
69
+ pr_format_str,
70
+ pr.title,
71
+ pr.html_url,
72
+ pr.user.login,
73
+ pr.head.ref,
74
+ user_who_merged(pr.number),
75
+ formatted_time(pr.merged_at),
76
+ pr.diff_url
77
+ )
78
+ )
79
+ end
80
+
81
+ f.write("============================================================\n#{prs_covered} PR(s) matched\n============================================================\n")
82
+ end
83
+
84
+ return ::Notify.warning("No pull requests match the requested term (#{value})") if prs_covered.zero?
85
+
86
+ system('cat /tmp/github-deploys.log')
87
+ end
88
+
89
+ private
90
+
91
+ def user_who_merged(pr_number)
92
+ pr = @client.pull_request(@repo_location, pr_number)
93
+ pr.merged_by.login
94
+ end
95
+
96
+ def formatted_time(time, correct_utc = false)
97
+ time = Time.now if time.nil?
98
+ time = time.localtime if correct_utc
99
+ time.strftime('%e/%-m/%Y @ %I:%M:%S%P')
100
+ end
101
+
102
+ def nested_hash_value(obj, key)
103
+ if obj.respond_to?(:key?) && obj.key?(key)
104
+ obj[key]
105
+ elsif obj.respond_to?(:each)
106
+ r = nil
107
+ obj.find{ |*a| r=nested_hash_value(a.last,key) }
108
+ r
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,3 +1,3 @@
1
1
  module DeployLog
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -100,8 +100,8 @@ files:
100
100
  - bin/setup
101
101
  - deploy_log.gemspec
102
102
  - lib/deploy_log.rb
103
- - lib/deploy_log/github_deploys.rb
104
- - lib/deploy_log/github_helper.rb
103
+ - lib/deploy_log/github/deploys.rb
104
+ - lib/deploy_log/github/helper.rb
105
105
  - lib/deploy_log/version.rb
106
106
  homepage: https://github.com/aapis/deploy_log
107
107
  licenses:
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GithubDeploys
4
- def initialize
5
- @github = GithubHelper.new(ARGV.first)
6
- end
7
-
8
- def merged_between(start, finish)
9
- unless start && finish
10
- Notify.error("Start and end dates (--start= and --end=) are required")
11
- end
12
-
13
- @github.pulls_in_timeframe(start, finish)
14
- end
15
-
16
- def merged_today
17
- start = Date.today.to_time # 12:00AM this morning
18
- finish = Date.today.to_time + (24 * 60 * 60) - 1 # 11:59PM tonight
19
-
20
- @github.pulls_in_timeframe(start, finish)
21
- end
22
-
23
- def merged_on(start)
24
- unless start
25
- Notify.error("Start date (--start=) is required")
26
- end
27
-
28
- finish = start + 24 * 60 * 60 - 1
29
-
30
- @github.pulls_in_timeframe(start, finish)
31
- end
32
-
33
- def pr_title(title)
34
- @github.search_pulls_by(title, :title)
35
- end
36
-
37
- def pr_for_branch(branch)
38
- @github.search_pulls_by(branch, :ref)
39
- end
40
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
-
4
- class GithubHelper
5
- def initialize(user_repo)
6
- @client = Octokit::Client.new(login: ENV['GITHUB_USER'], password: ENV['GITHUB_TOKEN'])
7
- @repo_location = user_repo
8
- end
9
-
10
- def pulls_in_timeframe(date_start = nil, date_end = nil)
11
- @client.auto_paginate = true
12
- list = @client.pull_requests(@repo_location,
13
- state: :closed,
14
- per_page: 500,
15
- sort: 'long-running'
16
- )
17
-
18
- pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n\n"
19
- prs_covered = 0
20
-
21
- File.open('/tmp/github-deploys.log', 'w+') do |f|
22
- list.each do |pr|
23
- next unless (date_start..date_end).cover? pr.merged_at
24
-
25
- prs_covered += 1
26
-
27
- f.write(
28
- sprintf(
29
- pr_format_str,
30
- pr.title,
31
- pr.html_url,
32
- pr.user.login,
33
- pr.head.ref,
34
- user_who_merged(pr.number),
35
- formatted_time(pr.merged_at),
36
- pr.diff_url
37
- )
38
- )
39
- end
40
-
41
- f.write("============================================================\n#{prs_covered} PR(s) merged from #{date_start} to #{date_end}\n============================================================\n")
42
- end
43
-
44
- return Notify.warning("No pull requests have been merged in the requested date range (#{date_start} - #{date_end})") if prs_covered.zero?
45
-
46
- system('cat /tmp/github-deploys.log')
47
- end
48
-
49
- def search_pulls_by(value, field = :title)
50
- list = @client.pull_requests(@repo_location,
51
- :state => :all,
52
- :per_page => 100
53
- )
54
- pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Changes: %s\n\n"
55
- prs_covered = 0
56
-
57
- File.open('/tmp/github-deploys.log', 'w+') do |f|
58
- list.each do |pr|
59
- next unless nested_hash_value(pr, field).match?(/#{value}\b/)
60
-
61
- prs_covered += 1
62
-
63
- f.write(
64
- sprintf(
65
- pr_format_str,
66
- pr.title,
67
- pr.html_url,
68
- pr.user.login,
69
- pr.head.ref,
70
- pr.diff_url
71
- )
72
- )
73
- end
74
-
75
- f.write("============================================================\n#{prs_covered} PR(s) matched\n============================================================\n")
76
- end
77
-
78
- return Notify.warning("No pull requests match the requested term (#{value})") if prs_covered.zero?
79
-
80
- system('cat /tmp/github-deploys.log')
81
- end
82
-
83
- private
84
-
85
- def user_who_merged(pr_number)
86
- pr = @client.pull_request(@repo_location, pr_number)
87
- pr.merged_by.login
88
- end
89
-
90
- def formatted_time(time, correct_utc = false)
91
- time = Time.now if time.nil?
92
- time = time.localtime if correct_utc
93
- time.strftime('%e/%-m/%Y @ %I:%M:%S%P')
94
- end
95
-
96
- def nested_hash_value(obj, key)
97
- if obj.respond_to?(:key?) && obj.key?(key)
98
- obj[key]
99
- elsif obj.respond_to?(:each)
100
- r = nil
101
- obj.find{ |*a| r=nested_hash_value(a.last,key) }
102
- r
103
- end
104
- end
105
- end