capistrano-committed 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0a4cbd5d40c614432cafb96c384335df53c9a32
4
- data.tar.gz: cacda04b507f455bcf753ee2f8c2f91b578d417b
3
+ metadata.gz: 5fe7f70c9b07f59c5bc350622702aa0aa9ab7fec
4
+ data.tar.gz: 21b3b32dcc4195be1bd68cd5cff667ad6f4301ab
5
5
  SHA512:
6
- metadata.gz: b3b0241825e0bb3ad169e2560dc39a80e4d6505f00304c0db8361d06107772e1c32e52e1f5a1f1f06ede442765a0ef2f32ddda3bcc5b3921493a4f79aebec635
7
- data.tar.gz: a337d0a2b55eee5fb85adffebd8f21d6ee865d3f2bb8efdaaa6817175d2c6a9a5ea89bd0938f8cff5496e5ed126d9107802492cd3052b81502e3435f92efb169
6
+ metadata.gz: f4677d783f58853501d7705bde6e459916c642d467fe79f83ff02bd6fc814bbbf266b6c566a62fc1c72fef9a78f78ff1ebbe235e7286fa59081a26bee08544ab
7
+ data.tar.gz: bcc8b8781b1b674e5a026b42acc9cb7fd15ef96bdbc99de0bd93662b7581c6f78a4a694924130c3ae48ea497efff30b13c4f9502c10696efc803ea9d5c6462b9
data/.codeclimate.yml CHANGED
@@ -6,15 +6,20 @@ engines:
6
6
  - ruby
7
7
  fixme:
8
8
  enabled: true
9
- exclude_fingerprints:
10
- - ee0a31701f95b21db4aff40647a56a3d
11
- - b86af833d6b2b1fa18da63471e2278d9
12
- - cdc1cac1f5cb7afe72dca9f9bca8a237
13
9
  rubocop:
14
10
  enabled: true
15
11
  ratings:
16
12
  paths:
17
13
  - "**.rb"
18
14
  - "**.rake"
15
+ - "Rakefile"
19
16
  exclude_paths:
17
+ - bin/**/*
18
+ - icons/**/*
20
19
  - spec/**/*
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".travis.yml"
24
+ - "LICENSE.md"
25
+ - "README.md"
data/README.md CHANGED
@@ -101,8 +101,7 @@ set :committed_output_path, '%s/public/committed.txt'
101
101
  # descriptions. This example matches JIRA numbers enclosed in square braces -
102
102
  # e.g. "[ABC-12345]" with the part inside the braces being captured "ABC-12345".
103
103
  # Setting this to `nil` will disable issue matching altogether. Note that this
104
- # setting should specify a string, not a Ruby Regexp object. Specifying a Regexp
105
- # object might work, but it is not tested.
104
+ # setting should specify a string, not a Ruby Regexp object.
106
105
  set :committed_issue_match, '\[\s?([a-zA-Z0-9]+\-[0-9]+)\s?\]'
107
106
 
108
107
  # This is an array of methods which should be applied to matched issue numbers
@@ -118,7 +117,8 @@ set :committed_issue_postprocess, -> { [] }
118
117
  # disable issue matching altogether.
119
118
  set :committed_issue_url, 'https://example.jira.com/browse/%s'
120
119
 
121
- # Register deployments in GitHub via the GitHub Deployments API
120
+ # Register deployments in GitHub via the GitHub Deployments API (not
121
+ # implemented yet)
122
122
  set :committed_deployments, false
123
123
  ```
124
124
 
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "capistrano-committed"
8
8
  spec.version = Capistrano::Committed::VERSION
9
9
  spec.authors = ["Sam Bauers"]
10
- spec.email = ["sam@redant.com.au"]
10
+ spec.email = ["sam@wopr.com.au"]
11
11
  spec.license = 'MIT'
12
12
 
13
13
  spec.summary = %q{Tells you what Capistrano 3 is going to deploy based on GitHub commits since the last release.}
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Committed
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -5,6 +5,144 @@ require 'capistrano/committed/github_api'
5
5
  module Capistrano
6
6
  module Committed
7
7
  class << self
8
+ def revision_search_regex(revision_line)
9
+ check_type __callee__, 'revision_line', revision_line.is_a?(String)
10
+
11
+ search = Regexp.escape(revision_line)
12
+ search = search.gsub('%\{', '(?<').gsub('\}', '>.+)')
13
+ Regexp.new(search)
14
+ end
15
+
16
+ def get_revisions_from_lines(lines, search, branch, limit)
17
+ check_type __callee__, 'lines', lines.is_a?(Array)
18
+ lines.each_with_index { |line, index|
19
+ check_type __callee__,
20
+ format('lines[%d]', index),
21
+ line.is_a?(String)
22
+ }
23
+ check_type __callee__, 'search', search.is_a?(Regexp)
24
+ check_type __callee__, 'branch', (branch.is_a?(Symbol) || branch.is_a?(String))
25
+ check_type __callee__, 'limit', limit.is_a?(Integer)
26
+
27
+ revisions = {}
28
+ lines.each do |line|
29
+ matches = search.match(line)
30
+ next if matches.nil?
31
+ next unless matches[:branch].to_s == branch.to_s
32
+ revisions[matches[:release]] = {
33
+ branch: matches[:branch],
34
+ sha: matches[:sha],
35
+ release: matches[:release],
36
+ user: matches[:user],
37
+ entries: {}
38
+ }
39
+ # Only store a certain number of revisions
40
+ break if revisions.count == limit
41
+ end
42
+ pad_revisions(revisions)
43
+ end
44
+
45
+ def add_dates_to_revisions(revisions, github, git_user, git_repo)
46
+ check_type __callee__, 'revisions', revisions.is_a?(Hash)
47
+ check_type __callee__, 'github', github.is_a?(Capistrano::Committed::GithubApi)
48
+ check_type __callee__, 'git_user', git_user.is_a?(String)
49
+ check_type __callee__, 'git_repo', git_repo.is_a?(String)
50
+
51
+ revisions.each do |release, revision|
52
+ next if release == :next || release == :previous
53
+ commit = github.get_commit(git_user,
54
+ git_repo,
55
+ revision[:sha])
56
+ unless commit.nil?
57
+ revisions[release][:date] = commit[:commit][:committer][:date]
58
+ end
59
+ end
60
+ revisions
61
+ end
62
+
63
+ def get_earliest_date_from_revisions(revisions)
64
+ check_type __callee__, 'revisions', revisions.is_a?(Hash)
65
+
66
+ revisions.values.map{ |r| Time.parse(r[:date]) unless r[:date].nil? }.compact.min
67
+ end
68
+
69
+ def days_to_seconds(days)
70
+ check_type __callee__, 'days', days.is_a?(Numeric)
71
+
72
+ days * 24 * 60 * 60
73
+ end
74
+
75
+ def add_buffer_to_time(time, buffer_in_days)
76
+ check_type __callee__, 'time', time.is_a?(Time)
77
+ check_type __callee__, 'buffer_in_days', buffer_in_days.is_a?(Numeric)
78
+
79
+ (time - days_to_seconds(buffer_in_days)).iso8601
80
+ end
81
+
82
+ def format_revision_header(release, revision)
83
+ check_type __callee__, 'release', (release.is_a?(Symbol) || release.is_a?(String))
84
+ check_type __callee__, 'revision', revision.is_a?(Hash)
85
+
86
+ output = ['']
87
+ output << ('=' * 94)
88
+ case release
89
+ when :next
90
+ output << t('committed.output.next_release')
91
+ when :previous
92
+ output << t('committed.output.previous_release',
93
+ time: revision[:date])
94
+ else
95
+ output << t('committed.output.current_release',
96
+ release_time: Time.parse(revision[:release]).iso8601,
97
+ sha: revision[:sha],
98
+ commit_time: revision[:date])
99
+ end
100
+ output << ('=' * 94)
101
+ output << ''
102
+ end
103
+
104
+ def format_commit(commit, pad, issue_pattern, postprocess, url_pattern)
105
+ check_type __callee__, 'commit', commit.is_a?(Hash)
106
+ check_type __callee__, 'pad', pad.is_a?(String)
107
+ # issue_pattern, postprocess, and url_pattern get type checked by `get_issue_urls`
108
+
109
+ # Print the commit ref
110
+ output = [format('%s * %s',
111
+ pad,
112
+ t('committed.output.commit_sha', sha: commit[:sha]))]
113
+ output << pad
114
+
115
+ # Print the commit message
116
+ lines = commit[:commit][:message].chomp.split("\n")
117
+ unless lines.empty?
118
+ lines.each do |line|
119
+ output << format('%s > %s', pad, line)
120
+ end
121
+ output << pad
122
+
123
+ # Get any issue numbers referred to in the commit message
124
+ # and print links to them
125
+ urls = get_issue_urls(issue_pattern,
126
+ postprocess,
127
+ url_pattern,
128
+ commit[:commit][:message])
129
+ output += format_issue_urls(urls, pad)
130
+ end
131
+
132
+ # Committer details
133
+ output << format('%s %s',
134
+ pad,
135
+ t('committed.output.committed_on', time: commit[:commit][:committer][:date]))
136
+ output << format('%s %s',
137
+ pad,
138
+ t('committed.output.committed_by', login: commit[:committer][:login]))
139
+ output << pad
140
+
141
+ # Print a link to the commit in GitHub
142
+ output << format('%s %s', pad, commit[:html_url])
143
+ output << pad
144
+ end
145
+
8
146
  def get_issue_urls(issue_pattern, postprocess, url_pattern, message)
9
147
  check_type __callee__,
10
148
  'issue_pattern',
@@ -22,13 +160,14 @@ module Capistrano
22
160
 
23
161
  matches = message.scan(Regexp.new(issue_pattern))
24
162
  return [] unless matches
25
- matches.map { |match|
163
+ matches.map! { |match|
26
164
  issue = match[0]
27
165
  postprocess.each { |method|
28
166
  issue = issue.send(method)
29
167
  }
30
168
  format(url_pattern, issue)
31
169
  }
170
+ matches.uniq
32
171
  end
33
172
 
34
173
  def format_issue_urls(urls, pad = '')
@@ -47,6 +186,20 @@ module Capistrano
47
186
  method: method,
48
187
  param: param) unless condition
49
188
  end
189
+
190
+ def pad_revisions(revisions)
191
+ check_type __callee__, 'revisions', revisions.is_a?(Hash)
192
+
193
+ unless revisions.empty?
194
+ # Sort revisions by release date
195
+ revisions = Hash[revisions.sort { |a, b| b[1][:release] <=> a[1][:release] }]
196
+ # Add the "previous" revision
197
+ revisions.merge!(previous: { entries: {} })
198
+ # Add the "next" revision
199
+ revisions = {next: { entries: {} }}.merge(revisions)
200
+ end
201
+ revisions
202
+ end
50
203
  end
51
204
  end
52
205
  end
@@ -95,27 +95,10 @@ namespace :committed do
95
95
 
96
96
  # Build the regex to search for revision data in the log, by default this
97
97
  # is the localised string from Capistrano
98
- search = fetch(:committed_revision_line)
99
- search = Regexp.escape(search)
100
- search = search.gsub('%\{', '(?<').gsub('\}', '>.+)')
101
- search = Regexp.new(search)
98
+ search = ::Capistrano::Committed.revision_search_regex(fetch(:committed_revision_line))
102
99
 
103
100
  # Build the revisions hash
104
- revisions = {}
105
- lines.each do |line|
106
- matches = search.match(line)
107
- next if matches.nil?
108
- next unless matches[:branch].to_s == fetch(:branch).to_s
109
- revisions[matches[:sha]] = {
110
- branch: matches[:branch],
111
- sha: matches[:sha],
112
- release: matches[:release],
113
- user: matches[:user],
114
- entries: {}
115
- }
116
- # Only store a certain number of revisions
117
- break if revisions.count == fetch(:committed_revision_limit)
118
- end
101
+ revisions = ::Capistrano::Committed.get_revisions_from_lines(lines, search, fetch(:branch), fetch(:committed_revision_limit))
119
102
 
120
103
  # No revisions, no log
121
104
  if revisions.empty?
@@ -125,29 +108,14 @@ namespace :committed do
125
108
  return
126
109
  end
127
110
 
128
- # Sort revisions by release date
129
- revisions = revisions.sort_by { |_sha, matches| matches[:release] }.to_h
130
- # Add the "next" revision
131
- revisions.merge!(next: { entries: {} })
132
- # Reverse the order of revisions in the hash (most recent first)
133
- revisions = revisions.to_a.reverse.to_h
134
- revisions.merge!(previous: { entries: {} })
135
-
136
111
  # Initialize the GitHub API client
137
112
  github = ::Capistrano::Committed::GithubApi.new(fetch(:committed_github_config))
138
113
 
139
114
  # Get the actual date of the commit referenced to by the revision
140
- earliest_date = nil
141
- revisions.each do |sha, _revision|
142
- next if sha == :next || sha == :previous
143
- commit = github.get_commit(fetch(:committed_user),
144
- fetch(:committed_repo),
145
- sha)
146
- unless commit.nil?
147
- earliest_date = commit[:commit][:committer][:date]
148
- revisions[sha][:date] = earliest_date
149
- end
150
- end
115
+ revisions = ::Capistrano::Committed.add_dates_to_revisions(revisions, github, fetch(:committed_user), fetch(:committed_repo))
116
+
117
+ # Get the earliest revision date
118
+ earliest_date = ::Capistrano::Committed.get_earliest_date_from_revisions(revisions)
151
119
 
152
120
  # No commit data on revisions, no log
153
121
  if earliest_date.nil?
@@ -157,9 +125,8 @@ namespace :committed do
157
125
  return
158
126
  end
159
127
 
160
- # Go back an extra N day
161
- buffer = fetch(:committed_commit_buffer) * 24 * 60 * 60
162
- earliest_date = (Time.parse(earliest_date) - buffer).iso8601
128
+ # Go back an extra N days
129
+ earliest_date = ::Capistrano::Committed.add_buffer_to_time(earliest_date, fetch(:committed_commit_buffer))
163
130
  revisions[:previous][:date] = earliest_date
164
131
 
165
132
  # Get all the commits on this branch
@@ -245,27 +212,14 @@ namespace :committed do
245
212
 
246
213
  # Loop through the revisions to create the output
247
214
  output = []
248
- revisions.each do |sha, revision|
215
+ revisions.each do |release, revision|
249
216
  # Build the revision header
250
- output << ''
251
- output << ('=' * 94)
252
- case sha
253
- when :next
254
- output << t('committed.output.next_release')
255
- when :previous
256
- output << t('committed.output.previous_release',
257
- time: revision[:date])
258
- else
259
- output << t('committed.output.current_release',
260
- release_time: Time.parse(revision[:release]).iso8601,
261
- sha: revision[:sha],
262
- commit_time: revision[:date])
263
- end
264
- output << ('=' * 94)
265
- output << ''
217
+ output += ::Capistrano::Committed.format_revision_header(release,
218
+ revision)
266
219
 
267
220
  # Loop through the entries in this revision
268
- revision[:entries].sort_by { |date, _entries| date }.reverse.to_h.each do |_date, entries|
221
+ items = Hash[revision[:entries].sort_by { |date, _entries| date }.reverse]
222
+ items.each do |_date, entries|
269
223
  entries.each do |entry|
270
224
  case entry[:type]
271
225
  when :pull_request
@@ -311,41 +265,11 @@ namespace :committed do
311
265
  entry[:commits].each do |commit|
312
266
  output << (' ' + ('-' * 90))
313
267
  output << ' |'
314
-
315
- # Print the commit ref
316
- output << format(' | * %s',
317
- t('committed.output.commit_sha',
318
- sha: commit[:sha]))
319
- output << ' |'
320
-
321
- # Print the commit message
322
- lines = commit[:commit][:message].chomp.split("\n")
323
- unless lines.empty?
324
- output << format(' | > %s', lines.join("\n | > "))
325
- output << ' |'
326
-
327
- # Get any issue numbers referred to in the commit message
328
- # and print links to them
329
- urls = ::Capistrano::Committed.get_issue_urls(fetch(:committed_issue_match),
268
+ output += ::Capistrano::Committed.format_commit(commit,
269
+ ' |',
270
+ fetch(:committed_issue_match),
330
271
  fetch(:committed_issue_postprocess),
331
- fetch(:committed_issue_url),
332
- commit[:commit][:message])
333
- output += ::Capistrano::Committed.format_issue_urls(urls,
334
- ' |')
335
- end
336
-
337
- # Committer details
338
- output << format(' | %s',
339
- t('committed.output.committed_on',
340
- time: commit[:commit][:committer][:date]))
341
- output << format(' | %s',
342
- t('committed.output.committed_by',
343
- login: commit[:committer][:login]))
344
- output << ' |'
345
-
346
- # Print a link to the commit in GitHub
347
- output << format(' | %s', commit[:html_url])
348
- output << ' |'
272
+ fetch(:committed_issue_url))
349
273
  end
350
274
  output << (' ' + ('-' * 90))
351
275
  output << ''
@@ -354,40 +278,11 @@ namespace :committed do
354
278
  when :commit
355
279
  # These are commits that are included in this revision, but are
356
280
  # not in any pull requests
357
-
358
- # Print the commit ref
359
- output << format(' * %s',
360
- t('committed.output.commit_sha',
361
- sha: entry[:info][:sha]))
362
- output << ''
363
-
364
- # Print the commit message
365
- lines = entry[:info][:commit][:message].chomp.split("\n")
366
- unless lines.empty?
367
- output << format(' > %s', lines.join("\n > "))
368
- output << ''
369
-
370
- # Get any issue numbers referred to in the commit message and
371
- # print links to them
372
- urls = ::Capistrano::Committed.get_issue_urls(fetch(:committed_issue_match),
281
+ output += ::Capistrano::Committed.format_commit(entry[:info],
282
+ '',
283
+ fetch(:committed_issue_match),
373
284
  fetch(:committed_issue_postprocess),
374
- fetch(:committed_issue_url),
375
- entry[:info][:commit][:message])
376
- output += ::Capistrano::Committed.format_issue_urls(urls)
377
- end
378
-
379
- # Committer details
380
- output << format(' %s',
381
- t('committed.output.committed_on',
382
- time: entry[:info][:commit][:committer][:date]))
383
- output << format(' %s',
384
- t('committed.output.committed_by',
385
- login: entry[:info][:committer][:login]))
386
- output << ''
387
-
388
- # Print a link to the commit in GitHub
389
- output << format(' %s', entry[:info][:html_url])
390
- output << ''
285
+ fetch(:committed_issue_url))
391
286
  end
392
287
 
393
288
  output << ('-' * 94)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-committed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Bauers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -83,7 +83,7 @@ dependencies:
83
83
  description: Tells you what Capistrano 3 is going to deploy based on GitHub commits
84
84
  since the last release.
85
85
  email:
86
- - sam@redant.com.au
86
+ - sam@wopr.com.au
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []