capistrano-committed 0.0.13 → 0.0.18

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
- SHA1:
3
- metadata.gz: 6862738c1a8b864e60223e231a5a87f01d144f98
4
- data.tar.gz: 2f8ae5945ef8d66dcc1cb7277184b632ec5e5715
2
+ SHA256:
3
+ metadata.gz: b10378b1d4ccb6c21f5aefe901978977310b2f60e3e7c7376dde006a0aeac6cd
4
+ data.tar.gz: 957d43e29b2564db78bb5e9e732c3e0ae10ed88522917b7d339bbe5fd6f4e460
5
5
  SHA512:
6
- metadata.gz: 1601cb74755e7fa02af65a8e73627d60cb8eafd60cd39a404217157adf0e0f0b16ffb5ec3d0ea528235820b87f345d4366d111cb5eb52448e2227d0626e54175
7
- data.tar.gz: '05780f41924b5e72ca1f5d709c99604a1674e855be45077284d0127de6cf8e48c6fa8ef89fa0874b165217edc4f159e93b5f5588efa7208e48855017f0cb45d3'
6
+ metadata.gz: 48d950402073213041a57a8e46b35a4f2fe03c0c57c81cc93d8ed2716cffdf7885f09a3efaa4e3283492ddb031255b0a2c4e2a93d836dd92ffa6461e2f48f9cb
7
+ data.tar.gz: f64b0bcbf2f23198758a171c2e8639051c630e3a3fc6f381520b1283417fb6ea6b8b084bc01c93b3ce9cee32eff1ff56ce4af92fc0f66e263c54f69ff3ff2d2c
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'codeclimate-test-reporter', require: nil
7
+ gem 'simplecov', require: nil
8
8
  end
data/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
  [![Test Coverage](https://codeclimate.com/github/sambauers/capistrano-committed/badges/coverage.svg)](https://codeclimate.com/github/sambauers/capistrano-committed/coverage)
10
10
  [![Code Climate](https://codeclimate.com/github/sambauers/capistrano-committed/badges/gpa.svg)](https://codeclimate.com/github/sambauers/capistrano-committed)
11
11
  [![Issue Count](https://codeclimate.com/github/sambauers/capistrano-committed/badges/issue_count.svg)](https://codeclimate.com/github/sambauers/capistrano-committed)
12
- [![Dependency Status](https://gemnasium.com/sambauers/capistrano-committed.svg)](https://gemnasium.com/sambauers/capistrano-committed)
13
12
 
14
13
  Capistrano Committed is an extension to Capistrano 3 which helps to determine what you are about to deploy.
15
14
 
@@ -1,32 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'capistrano/committed/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "capistrano-committed"
6
+ spec.name = 'capistrano-committed'
8
7
  spec.version = Capistrano::Committed::VERSION
9
- spec.authors = ["Sam Bauers"]
10
- spec.email = ["sam@wopr.com.au"]
8
+ spec.authors = ['Sam Bauers']
9
+ spec.email = ['sam@wopr.com.au']
11
10
  spec.license = 'MIT'
12
11
 
13
- spec.summary = %q{Tells you what Capistrano 3 is going to deploy based on GitHub commits since the last release.}
14
- spec.description = %q{Tells you what Capistrano 3 is going to deploy based on GitHub commits since the last release. See README.md for more info.}
15
- spec.homepage = "https://github.com/sambauers/capistrano-committed"
12
+ spec.summary = 'Tells you what Capistrano 3 is going to deploy based on GitHub commits since the last release.'
13
+ spec.description = 'Tells you what Capistrano 3 is going to deploy based on GitHub commits since the last release. See README.md for more info.'
14
+ spec.homepage = 'https://github.com/sambauers/capistrano-committed'
16
15
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
16
+ spec.files = Dir['lib/**/*', 'capistrano-committed.gemspec', 'Gemfile', '*.md']
17
+ spec.require_paths = ['lib']
21
18
 
22
- spec.required_ruby_version = '>= 2.2.7'
19
+ spec.required_ruby_version = '>= 2.3.8'
23
20
 
24
- spec.add_dependency "rack", "~> 2.0"
25
- spec.add_dependency "capistrano", "~> 3.8"
26
- spec.add_dependency "github_api", "~> 0.17"
27
- spec.add_dependency "mustache", "~> 1.0"
21
+ spec.add_dependency 'capistrano', '~> 3'
22
+ spec.add_dependency 'github_api', '~> 0.18'
23
+ spec.add_dependency 'mustache', '~> 1'
24
+ spec.add_dependency 'rack', '~> 2'
28
25
 
29
- spec.add_development_dependency "bundler", "~> 1.15"
30
- spec.add_development_dependency "rake", "~> 12.0"
31
- spec.add_development_dependency "rspec", "~> 3.6"
26
+ spec.add_development_dependency 'bundler', '~> 2'
27
+ spec.add_development_dependency 'rake', '~> 12'
28
+ spec.add_development_dependency 'rspec', '~> 3'
32
29
  end
@@ -13,7 +13,7 @@ module Capistrano
13
13
  end
14
14
 
15
15
  def get_setting(setting, variable = nil)
16
- variable.nil? ? @@settings[setting] : variable
16
+ variable.nil? ? @@settings[setting] : variable
17
17
  end
18
18
 
19
19
  def revision_search_regex(revision_line = nil)
@@ -27,11 +27,9 @@ module Capistrano
27
27
 
28
28
  def get_revisions_from_lines(lines, search = nil, branch = nil, limit = nil)
29
29
  check_type __callee__, 'lines', lines.is_a?(Array)
30
- lines.each_with_index { |line, index|
31
- check_type __callee__,
32
- format('lines[%d]', index),
33
- line.is_a?(String)
34
- }
30
+ lines.each_with_index do |line, index|
31
+ check_type __callee__, format('lines[%<index>d]', index: index), line.is_a?(String)
32
+ end
35
33
 
36
34
  search = revision_search_regex if search.nil?
37
35
  check_type __callee__, 'search', search.is_a?(Regexp)
@@ -63,30 +61,20 @@ module Capistrano
63
61
  def add_dates_to_revisions(revisions, github, git_user = nil, git_repo = nil)
64
62
  check_type __callee__, 'revisions', revisions.is_a?(Hash)
65
63
  check_type __callee__, 'github', github.is_a?(Capistrano::Committed::GithubApi)
66
-
67
- git_user = get_setting(:user, git_user)
68
- check_type __callee__, 'git_user', git_user.is_a?(String)
69
-
70
- git_repo = get_setting(:repo, git_repo)
71
- check_type __callee__, 'git_repo', git_repo.is_a?(String)
64
+ git_user = check_git_user(git_user)
65
+ git_repo = check_git_repo(git_repo)
72
66
 
73
67
  revisions.each do |release, revision|
74
- next if release == :next || release == :previous
75
- commit = github.get_commit(git_user,
76
- git_repo,
77
- revision[:sha])
78
-
79
- unless commit.nil?
80
- revisions[release][:date] = commit[:commit][:committer][:date]
81
- end
68
+ next if %i[next previous].include? release
69
+ commit = github.get_commit(git_user, git_repo, revision[:sha])
70
+ revisions[release][:date] = commit[:commit][:committer][:date] unless commit.nil?
82
71
  end
83
- revisions
84
72
  end
85
73
 
86
74
  def get_earliest_date_from_revisions(revisions)
87
75
  check_type __callee__, 'revisions', revisions.is_a?(Hash)
88
76
 
89
- revisions.values.map{ |r| Time.parse(r[:date]) unless r[:date].nil? }.compact.min
77
+ revisions.values.map { |r| Time.parse(r[:date]) unless r[:date].nil? }.compact.min
90
78
  end
91
79
 
92
80
  def days_to_seconds(days)
@@ -106,40 +94,58 @@ module Capistrano
106
94
 
107
95
  def get_issue_urls(message, issue_match = nil, issue_postprocess = nil, issue_url = nil)
108
96
  check_type __callee__, 'message', message.is_a?(String)
97
+ issue_match = check_issue_match(issue_match)
98
+ issue_postprocess = check_issue_postprocess(issue_postprocess)
99
+ issue_url = check_issue_url(issue_url)
100
+
101
+ return [] unless (matches = message.scan(Regexp.new(issue_match)))
102
+ matches.map! do |match|
103
+ postprocess_issue_url(issue_postprocess, issue_url, match[0])
104
+ end.uniq
105
+ end
109
106
 
107
+ private
108
+
109
+ def check_type(method, param, condition)
110
+ raise TypeError, t('committed.error.helpers.valid_param', method: method, param: param) unless condition
111
+ end
112
+
113
+ def check_git_user(git_user)
114
+ git_user = get_setting(:user, git_user)
115
+ check_type __callee__, 'git_user', git_user.is_a?(String)
116
+ git_user
117
+ end
118
+
119
+ def check_git_repo(git_repo)
120
+ git_repo = get_setting(:repo, git_repo)
121
+ check_type __callee__, 'git_repo', git_repo.is_a?(String)
122
+ git_repo
123
+ end
124
+
125
+ def check_issue_match(issue_match)
110
126
  issue_match = get_setting(:issue_match, issue_match)
111
- check_type __callee__,
112
- 'issue_match',
113
- (issue_match.is_a?(String) || issue_match.is_a?(Regexp))
127
+ check_type __callee__, 'issue_match', (issue_match.is_a?(String) || issue_match.is_a?(Regexp))
128
+ issue_match
129
+ end
114
130
 
131
+ def check_issue_postprocess(issue_postprocess)
115
132
  issue_postprocess = get_setting(:issue_postprocess, issue_postprocess)
116
133
  check_type __callee__, 'issue_postprocess', issue_postprocess.is_a?(Array)
117
- issue_postprocess.each { |method|
118
- check_type __callee__,
119
- format('issue_postprocess[:%s]', method.to_s),
120
- method.is_a?(Symbol)
121
- }
134
+ issue_postprocess.each do |method|
135
+ check_type __callee__, format('issue_postprocess[:%<method>s]', method: method.to_s), method.is_a?(Symbol)
136
+ end
137
+ issue_postprocess
138
+ end
122
139
 
140
+ def check_issue_url(issue_url)
123
141
  issue_url = get_setting(:issue_url, issue_url)
124
142
  check_type __callee__, 'issue_url', issue_url.is_a?(String)
125
-
126
- matches = message.scan(Regexp.new(issue_match))
127
- return [] unless matches
128
- matches.map! { |match|
129
- issue = match[0]
130
- issue_postprocess.each { |method|
131
- issue = issue.send(method)
132
- }
133
- format(issue_url, issue)
134
- }
135
- matches.uniq
143
+ issue_url
136
144
  end
137
145
 
138
- private
139
- def check_type(method, param, condition)
140
- fail TypeError, t('committed.error.helpers.valid_param',
141
- method: method,
142
- param: param) unless condition
146
+ def postprocess_issue_url(issue_postprocess, issue_url, issue)
147
+ issue_postprocess.each { |method| issue = issue.send(method) }
148
+ format(issue_url, issue)
143
149
  end
144
150
 
145
151
  def pad_revisions(revisions)
@@ -149,9 +155,9 @@ module Capistrano
149
155
  # Sort revisions by release date
150
156
  revisions = Hash[revisions.sort { |a, b| b[1][:release] <=> a[1][:release] }]
151
157
  # Add the "previous" revision
152
- revisions.merge!(previous: { release: :previous, entries: {} })
158
+ revisions[:previous] = { release: :previous, entries: {} }
153
159
  # Add the "next" revision
154
- revisions = {next: { release: :next, entries: {} }}.merge(revisions)
160
+ revisions = { next: { release: :next, entries: {} } }.merge(revisions)
155
161
  end
156
162
  revisions
157
163
  end
@@ -159,4 +165,4 @@ module Capistrano
159
165
  end
160
166
  end
161
167
 
162
- load File.expand_path('../tasks/committed.rake', __FILE__)
168
+ load File.expand_path('tasks/committed.rake', __dir__)
@@ -3,6 +3,8 @@ require 'github_api'
3
3
  module Capistrano
4
4
  module Committed
5
5
  class GithubApi
6
+ attr_reader :client
7
+
6
8
  def initialize(config_options = {})
7
9
  validate('config_options', config_options, Hash, __callee__)
8
10
 
@@ -16,10 +18,6 @@ module Capistrano
16
18
  @client = ::Github.new options
17
19
  end
18
20
 
19
- def client
20
- @client
21
- end
22
-
23
21
  def get_commit(user, repo, sha)
24
22
  validate_user_and_repo(user, repo, __callee__)
25
23
  validate('sha', sha, String, __callee__)
@@ -81,13 +79,11 @@ module Capistrano
81
79
  validate_user_and_repo(user, repo, __callee__)
82
80
  validate('id', id, Integer, __callee__)
83
81
 
84
- valid_states = %w(pending success error failure)
82
+ valid_states = %w[pending success error failure]
85
83
  state = state.to_s
86
84
  unless valid_states.include?(state)
87
- message = t('committed.error.helpers.valid_param',
88
- method: __callee__,
89
- param: 'state')
90
- fail TypeError, message
85
+ message = t('committed.error.helpers.valid_param', method: __callee__, param: 'state')
86
+ raise TypeError, message
91
87
  end
92
88
 
93
89
  api_call do
@@ -105,7 +101,7 @@ module Capistrano
105
101
  message = t('committed.error.helpers.valid_param',
106
102
  method: method,
107
103
  param: param)
108
- fail TypeError, message
104
+ raise TypeError, message
109
105
  end
110
106
 
111
107
  def validate_user_and_repo(user, repo, method)
@@ -116,11 +112,8 @@ module Capistrano
116
112
  def api_call
117
113
  yield
118
114
  rescue ::Github::Error::GithubError => e
119
- if e.is_a? ::Github::Error::ServiceError
120
- raise e, t('committed.error.helpers.github_service_error')
121
- elsif e.is_a? ::Github::Error::ClientError
122
- raise e, t('committed.error.helpers.github_client_error')
123
- end
115
+ raise e, t('committed.error.helpers.github_service_error') if e.is_a? ::Github::Error::ServiceError
116
+ raise e, t('committed.error.helpers.github_client_error') if e.is_a? ::Github::Error::ClientError
124
117
  end
125
118
  end
126
119
  end
@@ -38,7 +38,7 @@ en = {
38
38
  }
39
39
  }
40
40
 
41
- I18n.backend.store_translations(:en, { capistrano: { committed: en } })
41
+ I18n.backend.store_translations(:en, capistrano: { committed: en })
42
42
 
43
43
  if I18n.respond_to?(:enforce_available_locales=)
44
44
  I18n.enforce_available_locales = true
@@ -5,16 +5,16 @@ module Capistrano
5
5
  class Output < Mustache
6
6
  @@template_format = 'txt'
7
7
 
8
- self.template_path = format('%s/output', File.dirname(__FILE__))
9
- self.template_file = format('%s/output/output_%s.mustache', File.dirname(__FILE__), @@template_format)
8
+ self.template_path = format('%<dir>s/output', dir: File.dirname(__FILE__))
9
+ self.template_file = format('%<dir>s/output/output_%<format>s.mustache', dir: File.dirname(__FILE__), format: @@template_format)
10
10
 
11
11
  def get_output_path(file)
12
- format('%s/output/%s', File.dirname(__FILE__), file)
12
+ format('%<dir>s/output/%<file>s', dir: File.dirname(__FILE__), file: file)
13
13
  end
14
14
 
15
15
  def get_output_template_path(format = 'txt', set_template_format = true)
16
16
  @@template_format = format if set_template_format
17
- get_output_path(format('output_%s.mustache', format))
17
+ get_output_path(format('output_%<format>s.mustache', format: format))
18
18
  end
19
19
 
20
20
  def template_format
@@ -139,18 +139,18 @@ module Capistrano
139
139
  !commits.nil?
140
140
  end
141
141
 
142
- private
143
-
142
+ private
143
+
144
144
  def commit_created_on(info)
145
145
  return unless info[:commit] && info[:commit][:committer]
146
146
  t('committed.output.committed_on', time: info[:commit][:committer][:date])
147
147
  end
148
-
148
+
149
149
  def pull_request_created_on(info)
150
150
  return unless info[:merged_at]
151
151
  t('committed.output.merged_on', time: info[:merged_at])
152
152
  end
153
-
153
+
154
154
  def format_created_by(t_key, user)
155
155
  return unless user
156
156
  t(t_key, login: user[:login])
@@ -159,7 +159,7 @@ module Capistrano
159
159
  def format_link(url)
160
160
  case template_format
161
161
  when 'html'
162
- format('<a href="%s">%s</a>', url, url)
162
+ format('<a href="%<url>s">%<url>s</a>', url: url)
163
163
  when 'txt'
164
164
  url
165
165
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Committed
3
- VERSION = '0.0.13'
3
+ VERSION = '0.0.18'.freeze
4
4
  end
5
5
  end
@@ -1,64 +1,53 @@
1
1
  namespace :committed do
2
2
  task :check_prerequisites do
3
3
  # Checks all the settings to make sure they are OK - mostly just checks type
4
- { committed_user: 'user',
5
- committed_repo: 'repository' }.each do |variable, name|
6
- fail TypeError, t('committed.error.prerequisites.nil',
7
- variable: variable,
8
- name: name) if
9
- fetch(variable).nil? ||
10
- !fetch(variable).is_a?(String)
11
-
12
- fail ArgumentError, t('committed.error.prerequisites.empty',
13
- variable: variable,
14
- name: name) if
15
- fetch(variable).empty?
4
+ { committed_user: 'user', committed_repo: 'repository' }.each do |variable, name|
5
+ if fetch(variable).nil? || !fetch(variable).is_a?(String)
6
+ raise TypeError, t('committed.error.prerequisites.nil', variable: variable, name: name)
7
+ end
8
+ if fetch(variable).empty?
9
+ raise ArgumentError, t('committed.error.prerequisites.empty', variable: variable, name: name)
10
+ end
16
11
  end
17
12
 
18
- fail TypeError, t('committed.error.prerequisites.hash',
19
- variable: 'committed_github_config') unless
20
- fetch(:committed_github_config).is_a?(Hash)
13
+ unless fetch(:committed_github_config).is_a?(Hash)
14
+ raise TypeError, t('committed.error.prerequisites.hash', variable: 'committed_github_config')
15
+ end
21
16
  end
22
17
 
23
18
  task :check_report_prerequisites do
24
19
  # Checks all the settings to make sure they are OK - mostly just checks type
25
- fail TypeError, t('committed.error.prerequisites.string',
26
- variable: 'committed_revision_line') unless
27
- fetch(:committed_revision_line).is_a?(String)
28
-
29
- fail TypeError, t('committed.error.prerequisites.integer',
30
- variable: 'committed_revision_limit') unless
31
- fetch(:committed_revision_limit).is_a?(Integer)
32
-
33
- fail TypeError, t('committed.error.prerequisites.integer',
34
- variable: 'committed_commit_buffer') unless
35
- fetch(:committed_commit_buffer).is_a?(Integer)
36
-
37
- fail TypeError, t('committed.error.deprecated',
38
- deprecated: 'committed_output_path',
39
- replacement: 'committed_output_text_path') if
40
- fetch(:committed_output_path).is_a?(String)
41
-
42
- fail TypeError, t('committed.error.prerequisites.string_or_nil',
43
- variable: 'committed_output_text_path') unless
44
- fetch(:committed_output_text_path).is_a?(String) ||
45
- fetch(:committed_output_text_path).nil?
46
-
47
- fail TypeError, t('committed.error.prerequisites.string_or_nil',
48
- variable: 'committed_output_html_path') unless
49
- fetch(:committed_output_html_path).is_a?(String) ||
50
- fetch(:committed_output_html_path).nil?
51
-
52
- fail TypeError, t('committed.error.prerequisites.string_or_regexp_or_nil',
53
- variable: 'committed_issue_match') unless
54
- fetch(:committed_issue_match).is_a?(String) ||
55
- fetch(:committed_issue_match).is_a?(Regexp) ||
56
- fetch(:committed_issue_match).nil?
57
-
58
- fail TypeError, t('committed.error.prerequisites.string_or_nil',
59
- variable: 'committed_issue_url') unless
60
- fetch(:committed_issue_url).is_a?(String) ||
61
- fetch(:committed_issue_url).nil?
20
+ unless fetch(:committed_revision_line).is_a?(String)
21
+ raise TypeError, t('committed.error.prerequisites.string', variable: 'committed_revision_line')
22
+ end
23
+
24
+ unless fetch(:committed_revision_limit).is_a?(Integer)
25
+ raise TypeError, t('committed.error.prerequisites.integer', variable: 'committed_revision_limit')
26
+ end
27
+
28
+ unless fetch(:committed_commit_buffer).is_a?(Integer)
29
+ raise TypeError, t('committed.error.prerequisites.integer', variable: 'committed_commit_buffer')
30
+ end
31
+
32
+ if fetch(:committed_output_path).is_a?(String)
33
+ raise TypeError, t('committed.error.deprecated', deprecated: 'committed_output_path', replacement: 'committed_output_text_path')
34
+ end
35
+
36
+ unless fetch(:committed_output_text_path).is_a?(String) || fetch(:committed_output_text_path).nil?
37
+ raise TypeError, t('committed.error.prerequisites.string_or_nil', variable: 'committed_output_text_path')
38
+ end
39
+
40
+ unless fetch(:committed_output_html_path).is_a?(String) || fetch(:committed_output_html_path).nil?
41
+ raise TypeError, t('committed.error.prerequisites.string_or_nil', variable: 'committed_output_html_path')
42
+ end
43
+
44
+ unless fetch(:committed_issue_match).is_a?(String) || fetch(:committed_issue_match).is_a?(Regexp) || fetch(:committed_issue_match).nil?
45
+ raise TypeError, t('committed.error.prerequisites.string_or_regexp_or_nil', variable: 'committed_issue_match')
46
+ end
47
+
48
+ unless fetch(:committed_issue_url).is_a?(String) || fetch(:committed_issue_url).nil?
49
+ raise TypeError, t('committed.error.prerequisites.string_or_nil', variable: 'committed_issue_url')
50
+ end
62
51
  end
63
52
 
64
53
  # task :register_deployment_pending do
@@ -99,7 +88,7 @@ namespace :committed do
99
88
  invoke 'committed:check_prerequisites'
100
89
  invoke 'committed:check_report_prerequisites'
101
90
 
102
- ::Capistrano::Committed.import_settings({
91
+ ::Capistrano::Committed.import_settings(
103
92
  branch: fetch(:branch),
104
93
  user: fetch(:committed_user),
105
94
  repo: fetch(:committed_repo),
@@ -114,7 +103,7 @@ namespace :committed do
114
103
  issue_url: fetch(:committed_issue_url),
115
104
  deployments: fetch(:committed_deployments),
116
105
  deployment_id: fetch(:committed_deployment_id)
117
- })
106
+ )
118
107
 
119
108
  # Only do this on the primary web server
120
109
  on primary :web do
@@ -241,10 +230,12 @@ namespace :committed do
241
230
  # Send the text output to screen, or to a file on the server
242
231
 
243
232
  # Create the mustache instance and plug in the revisions
244
- output = ::Capistrano::Committed::Output.new()
233
+ output = ::Capistrano::Committed::Output.new
245
234
  output[:revisions] = revisions.values
246
235
  output[:page_title] = t('committed.output.page_title',
247
- repo: format('%s/%s', fetch(:committed_user), fetch(:committed_repo)))
236
+ repo: format('%<user>s/%<repo>s',
237
+ user: fetch(:committed_user),
238
+ repo: fetch(:committed_repo)))
248
239
 
249
240
  # Send the text output to a file on the server
250
241
  if fetch(:committed_output_text_path).nil?