capistrano-committed 0.0.7 → 0.0.8

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: 5fe7f70c9b07f59c5bc350622702aa0aa9ab7fec
4
- data.tar.gz: 21b3b32dcc4195be1bd68cd5cff667ad6f4301ab
3
+ metadata.gz: 53f9838f0ee36a0fc450a0d4c554aacb0f2c8eff
4
+ data.tar.gz: e51d3b4e484f15f51d0a3261a99b8cb23c2903e6
5
5
  SHA512:
6
- metadata.gz: f4677d783f58853501d7705bde6e459916c642d467fe79f83ff02bd6fc814bbbf266b6c566a62fc1c72fef9a78f78ff1ebbe235e7286fa59081a26bee08544ab
7
- data.tar.gz: bcc8b8781b1b674e5a026b42acc9cb7fd15ef96bdbc99de0bd93662b7581c6f78a4a694924130c3ae48ea497efff30b13c4f9502c10696efc803ea9d5c6462b9
6
+ metadata.gz: d25d95dba27120f8cbabc51390886b284787ae1d839c49762da5356bccfbd7a2c60bb890550be10c836be934380211e7de005a7a18e306db329949ec42edd8e5
7
+ data.tar.gz: beac303f7200b7d85ae0303706d3cb619031bd15b7c952fceaa6dfabd954dcb4b06aff0e87ce1f79c5f4643aa7e64550543a3caa167bc67c9b37da3f6347bdcf
data/README.md CHANGED
@@ -93,9 +93,14 @@ set :committed_revision_limit, 10
93
93
  # How many days beyond the last revision we fetch should we look for commits
94
94
  set :committed_commit_buffer, 1
95
95
 
96
- # Where to upload the report - '%s' is replaced with `current_path` if present.
97
- # `nil` will stop the report from uploading at all, and print to STDOUT instead.
98
- set :committed_output_path, '%s/public/committed.txt'
96
+ # Where to upload the text report - '%s' is replaced with `current_path` if
97
+ # present. `nil` will stop the report from uploading at all, and print to STDOUT
98
+ # instead.
99
+ set :committed_output_text_path, '%s/public/committed.txt'
100
+
101
+ # Where to upload the html report - '%s' is replaced with `current_path` if
102
+ # present. `nil` will stop the report from uploading at all.
103
+ set :committed_output_html_path, '%s/public/committed.html'
99
104
 
100
105
  # This is a regexp pattern that describes issue numbers in commit titles and
101
106
  # descriptions. This example matches JIRA numbers enclosed in square braces -
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "capistrano", '~> 3.4'
23
23
  spec.add_dependency "github_api", "~> 0.13.0"
24
+ spec.add_dependency "mustache", "~> 1.0"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.10"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,11 +1,23 @@
1
1
  require 'capistrano/committed/version'
2
2
  require 'capistrano/committed/i18n'
3
3
  require 'capistrano/committed/github_api'
4
+ require 'capistrano/committed/output'
4
5
 
5
6
  module Capistrano
6
7
  module Committed
7
8
  class << self
8
- def revision_search_regex(revision_line)
9
+ @@settings = {}
10
+
11
+ def import_settings(settings, merge = nil)
12
+ merge.nil? ? @@settings = settings : @@settings.merge!(settings)
13
+ end
14
+
15
+ def get_setting(setting, variable = nil)
16
+ variable.nil? ? @@settings[setting] : variable
17
+ end
18
+
19
+ def revision_search_regex(revision_line = nil)
20
+ revision_line = get_setting(:revision_line, revision_line)
9
21
  check_type __callee__, 'revision_line', revision_line.is_a?(String)
10
22
 
11
23
  search = Regexp.escape(revision_line)
@@ -13,15 +25,21 @@ module Capistrano
13
25
  Regexp.new(search)
14
26
  end
15
27
 
16
- def get_revisions_from_lines(lines, search, branch, limit)
28
+ def get_revisions_from_lines(lines, search = nil, branch = nil, limit = nil)
17
29
  check_type __callee__, 'lines', lines.is_a?(Array)
18
30
  lines.each_with_index { |line, index|
19
31
  check_type __callee__,
20
32
  format('lines[%d]', index),
21
33
  line.is_a?(String)
22
34
  }
35
+
36
+ search = revision_search_regex if search.nil?
23
37
  check_type __callee__, 'search', search.is_a?(Regexp)
38
+
39
+ branch = get_setting(:branch, branch)
24
40
  check_type __callee__, 'branch', (branch.is_a?(Symbol) || branch.is_a?(String))
41
+
42
+ limit = get_setting(:revision_limit, limit)
25
43
  check_type __callee__, 'limit', limit.is_a?(Integer)
26
44
 
27
45
  revisions = {}
@@ -42,10 +60,14 @@ module Capistrano
42
60
  pad_revisions(revisions)
43
61
  end
44
62
 
45
- def add_dates_to_revisions(revisions, github, git_user, git_repo)
63
+ def add_dates_to_revisions(revisions, github, git_user = nil, git_repo = nil)
46
64
  check_type __callee__, 'revisions', revisions.is_a?(Hash)
47
65
  check_type __callee__, 'github', github.is_a?(Capistrano::Committed::GithubApi)
66
+
67
+ git_user = get_setting(:user, git_user)
48
68
  check_type __callee__, 'git_user', git_user.is_a?(String)
69
+
70
+ git_repo = get_setting(:repo, git_repo)
49
71
  check_type __callee__, 'git_repo', git_repo.is_a?(String)
50
72
 
51
73
  revisions.each do |release, revision|
@@ -72,114 +94,46 @@ module Capistrano
72
94
  days * 24 * 60 * 60
73
95
  end
74
96
 
75
- def add_buffer_to_time(time, buffer_in_days)
97
+ def add_buffer_to_time(time, buffer_in_days = nil)
76
98
  check_type __callee__, 'time', time.is_a?(Time)
99
+
100
+ buffer_in_days = get_setting(:commit_buffer, buffer_in_days)
77
101
  check_type __callee__, 'buffer_in_days', buffer_in_days.is_a?(Numeric)
78
102
 
79
103
  (time - days_to_seconds(buffer_in_days)).iso8601
80
104
  end
81
105
 
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
106
+ def get_issue_urls(message, issue_match = nil, issue_postprocess = nil, issue_url = nil)
107
+ check_type __callee__, 'message', message.is_a?(String)
145
108
 
146
- def get_issue_urls(issue_pattern, postprocess, url_pattern, message)
109
+ issue_match = get_setting(:issue_match, issue_match)
147
110
  check_type __callee__,
148
- 'issue_pattern',
149
- (issue_pattern.is_a?(String) || issue_pattern.is_a?(Regexp))
111
+ 'issue_match',
112
+ (issue_match.is_a?(String) || issue_match.is_a?(Regexp))
150
113
 
151
- check_type __callee__, 'postprocess', postprocess.is_a?(Array)
152
- postprocess.each { |method|
114
+ issue_postprocess = get_setting(:issue_postprocess, issue_postprocess)
115
+ check_type __callee__, 'issue_postprocess', issue_postprocess.is_a?(Array)
116
+ issue_postprocess.each { |method|
153
117
  check_type __callee__,
154
- format('postprocess[:%s]', method.to_s),
118
+ format('issue_postprocess[:%s]', method.to_s),
155
119
  method.is_a?(Symbol)
156
120
  }
157
121
 
158
- check_type __callee__, 'url_pattern', url_pattern.is_a?(String)
159
- check_type __callee__, 'message', message.is_a?(String)
122
+ issue_url = get_setting(:issue_url, issue_url)
123
+ check_type __callee__, 'issue_url', issue_url.is_a?(String)
160
124
 
161
- matches = message.scan(Regexp.new(issue_pattern))
125
+ matches = message.scan(Regexp.new(issue_match))
162
126
  return [] unless matches
163
127
  matches.map! { |match|
164
128
  issue = match[0]
165
- postprocess.each { |method|
129
+ issue_postprocess.each { |method|
166
130
  issue = issue.send(method)
167
131
  }
168
- format(url_pattern, issue)
132
+ format(issue_url, issue)
169
133
  }
170
134
  matches.uniq
171
135
  end
172
136
 
173
- def format_issue_urls(urls, pad = '')
174
- return [] if urls.nil? || urls.empty?
175
- output = []
176
- output << format('%s %s', pad, t('committed.output.issue_links'))
177
- urls.each do |url|
178
- output << format('%s - %s', pad, url)
179
- end
180
- output << format('%s', pad)
181
- end
182
-
183
137
  private
184
138
  def check_type(method, param, condition)
185
139
  fail TypeError, t('committed.error.helpers.valid_param',
@@ -194,9 +148,9 @@ module Capistrano
194
148
  # Sort revisions by release date
195
149
  revisions = Hash[revisions.sort { |a, b| b[1][:release] <=> a[1][:release] }]
196
150
  # Add the "previous" revision
197
- revisions.merge!(previous: { entries: {} })
151
+ revisions.merge!(previous: { release: :previous, entries: {} })
198
152
  # Add the "next" revision
199
- revisions = {next: { entries: {} }}.merge(revisions)
153
+ revisions = {next: { release: :next, entries: {} }}.merge(revisions)
200
154
  end
201
155
  revisions
202
156
  end
@@ -16,6 +16,7 @@ en = {
16
16
  string_or_nil: '`:%{variable}` variable is not a string or `nil`.',
17
17
  string_or_regexp_or_nil: '`:%{variable}` variable is not a string or `Regexp` object or `nil`.'
18
18
  },
19
+ deprecated: '`%{deprecated}` variable is deprecated. Use `%{replacement}` instead.',
19
20
  runtime: {
20
21
  revisions_empty: 'The %{branch} branch has never been deployed to the %{stage} stage. No log has been generated.',
21
22
  revision_commit_missing: 'No commit data has been found for the %{branch} branch on the %{stage} stage. No log has been generated.',
@@ -23,6 +24,7 @@ en = {
23
24
  }
24
25
  },
25
26
  output: {
27
+ page_title: 'Git Deployment Report for %{repo}',
26
28
  next_release: 'Next release',
27
29
  previous_release: 'Commits before %{time} are omitted from the report ¯\_(ツ)_/¯',
28
30
  current_release: 'Release on %{release_time} from commit %{sha} at %{commit_time}',
@@ -0,0 +1,147 @@
1
+ require 'mustache'
2
+
3
+ module Capistrano
4
+ module Committed
5
+ class Output < Mustache
6
+ @@template_format = 'txt'
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)
10
+
11
+ def get_output_path(file)
12
+ format('%s/output/%s', File.dirname(__FILE__), file)
13
+ end
14
+
15
+ def get_output_template_path(format = 'txt', set_template_format = true)
16
+ @@template_format = format if set_template_format
17
+ get_output_path(format('output_%s.mustache', format))
18
+ end
19
+
20
+ def release_header
21
+ case context.current[:release]
22
+ when :next
23
+ t('committed.output.next_release')
24
+ when :previous
25
+ t('committed.output.previous_release',
26
+ time: context.current[:date])
27
+ else
28
+ t('committed.output.current_release',
29
+ release_time: Time.parse(context.current[:release]).iso8601,
30
+ sha: context.current[:sha],
31
+ commit_time: context.current[:date])
32
+ end
33
+ end
34
+
35
+ def items
36
+ return unless context.current[:entries]
37
+ Hash[context.current[:entries].sort_by { |date, _entries| date }.reverse].values.flatten
38
+ end
39
+
40
+ def item_title
41
+ return unless context.current[:info]
42
+ case context.current[:type]
43
+ when :commit
44
+ t('committed.output.commit_sha',
45
+ sha: context.current[:info][:sha])
46
+ when :pull_request
47
+ t('committed.output.pull_request_number',
48
+ number: context.current[:info][:number])
49
+ end
50
+ end
51
+
52
+ def item_subtitle
53
+ return unless context.current[:type] == :pull_request
54
+ return unless context.current[:info]
55
+ context.current[:info][:title]
56
+ end
57
+
58
+ def has_item_subtitle
59
+ !item_subtitle.nil?
60
+ end
61
+
62
+ def item_lines
63
+ return unless context.current[:info]
64
+ case context.current[:type]
65
+ when :commit
66
+ context.current[:info][:commit][:message].chomp.delete("\r").split("\n")
67
+ when :pull_request
68
+ context.current[:info][:body].chomp.delete("\r").split("\n")
69
+ end
70
+ end
71
+
72
+ def has_item_lines
73
+ !item_lines.empty?
74
+ end
75
+
76
+ def issue_links
77
+ return unless context.current[:info]
78
+ case context.current[:type]
79
+ when :commit
80
+ ::Capistrano::Committed.get_issue_urls(context.current[:info][:commit][:message])
81
+ when :pull_request
82
+ ::Capistrano::Committed.get_issue_urls(context.current[:info][:title] + context.current[:info][:body])
83
+ end
84
+ end
85
+
86
+ def issue_link
87
+ format_link(context.current)
88
+ end
89
+
90
+ def has_issue_links
91
+ !issue_links.empty?
92
+ end
93
+
94
+ def item_created_on
95
+ return unless context.current[:info]
96
+ case context.current[:type]
97
+ when :commit
98
+ t('committed.output.committed_on', time: context.current[:info][:commit][:committer][:date])
99
+ when :pull_request
100
+ t('committed.output.merged_on', time: context.current[:info][:merged_at])
101
+ end
102
+ end
103
+
104
+ def item_created_by
105
+ return unless context.current[:info]
106
+ case context.current[:type]
107
+ when :commit
108
+ t('committed.output.committed_by', login: context.current[:info][:committer][:login])
109
+ when :pull_request
110
+ t('committed.output.merged_by', login: context.current[:info][:merged_by][:login])
111
+ else
112
+
113
+ end
114
+ end
115
+
116
+ def item_link
117
+ case context.current[:type]
118
+ when :commit, :pull_request
119
+ return unless context.current[:info]
120
+ format_link(context.current[:info][:html_url])
121
+ end
122
+ end
123
+
124
+ def commits
125
+ return unless context.current[:type] == :pull_request
126
+ return if context.current[:commits].nil?
127
+ return if context.current[:commits].empty?
128
+ context.current[:commits].flatten
129
+ end
130
+
131
+ def has_commits
132
+ !commits.nil?
133
+ end
134
+
135
+ private
136
+
137
+ def format_link(url)
138
+ case @@template_format
139
+ when 'html'
140
+ format('<a href="%s">%s</a>', url, url)
141
+ when 'txt'
142
+ url
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6
+ <title>{{page_title}}</title>
7
+ </head>
8
+ <body>
9
+ <pre>
10
+ {{>output_txt}}
11
+ </pre>
12
+ </body>
13
+ </html>
@@ -0,0 +1,63 @@
1
+ {{page_title}}
2
+ {{#revisions}}
3
+
4
+ ==============================================================================================
5
+ {{release_header}}
6
+ ==============================================================================================
7
+ {{#items}}
8
+
9
+ * {{item_title}}
10
+ {{#has_item_subtitle}}
11
+ {{item_subtitle}}
12
+ {{/has_item_subtitle}}
13
+ {{#has_item_lines}}
14
+
15
+ {{#item_lines}}
16
+ > {{.}}
17
+ {{/item_lines}}
18
+ {{#has_issue_links}}
19
+
20
+ Issue links:
21
+ {{#issue_links}}
22
+ - {{{issue_link}}}
23
+ {{/issue_links}}
24
+ {{/has_issue_links}}
25
+ {{/has_item_lines}}
26
+
27
+ {{item_created_on}}
28
+ {{item_created_by}}
29
+
30
+ {{{item_link}}}
31
+
32
+ {{#has_commits}}
33
+ {{#commits}}
34
+ ------------------------------------------------------------------------------------------
35
+ |
36
+ | * {{item_title}}
37
+ {{#has_item_lines}}
38
+ |
39
+ {{#item_lines}}
40
+ | > {{.}}
41
+ {{/item_lines}}
42
+ {{#has_issue_links}}
43
+ |
44
+ | Issue links:
45
+ {{#issue_links}}
46
+ | - {{{issue_link}}}
47
+ {{/issue_links}}
48
+ {{/has_issue_links}}
49
+ {{/has_item_lines}}
50
+ |
51
+ | {{item_created_on}}
52
+ | {{item_created_by}}
53
+ |
54
+ | {{{item_link}}}
55
+ |
56
+ {{/commits}}
57
+ ------------------------------------------------------------------------------------------
58
+
59
+ {{/has_commits}}
60
+ ----------------------------------------------------------------------------------------------
61
+ {{/items}}
62
+
63
+ {{/revisions}}
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Committed
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
  end
5
5
  end
@@ -33,10 +33,20 @@ namespace :committed do
33
33
  variable: 'committed_commit_buffer') unless
34
34
  fetch(:committed_commit_buffer).is_a?(Integer)
35
35
 
36
+ fail TypeError, t('committed.error.deprecated',
37
+ deprecated: 'committed_output_path',
38
+ replacement: 'committed_output_text_path') if
39
+ fetch(:committed_output_path).is_a?(String)
40
+
41
+ fail TypeError, t('committed.error.prerequisites.string_or_nil',
42
+ variable: 'committed_output_text_path') unless
43
+ fetch(:committed_output_text_path).is_a?(String) ||
44
+ fetch(:committed_output_text_path).nil?
45
+
36
46
  fail TypeError, t('committed.error.prerequisites.string_or_nil',
37
- variable: 'committed_output_path') unless
38
- fetch(:committed_output_path).is_a?(String) ||
39
- fetch(:committed_output_path).nil?
47
+ variable: 'committed_output_html_path') unless
48
+ fetch(:committed_output_html_path).is_a?(String) ||
49
+ fetch(:committed_output_html_path).nil?
40
50
 
41
51
  fail TypeError, t('committed.error.prerequisites.string_or_regexp_or_nil',
42
52
  variable: 'committed_issue_match') unless
@@ -88,17 +98,30 @@ namespace :committed do
88
98
  invoke 'committed:check_prerequisites'
89
99
  invoke 'committed:check_report_prerequisites'
90
100
 
101
+ ::Capistrano::Committed.import_settings({
102
+ branch: fetch(:branch),
103
+ user: fetch(:committed_user),
104
+ repo: fetch(:committed_repo),
105
+ revision_line: fetch(:committed_revision_line),
106
+ github_config: fetch(:committed_github_config),
107
+ revision_limit: fetch(:committed_revision_limit),
108
+ commit_buffer: fetch(:committed_commit_buffer),
109
+ output_text_path: fetch(:committed_output_text_path),
110
+ output_html_path: fetch(:committed_output_html_path),
111
+ issue_match: fetch(:committed_issue_match),
112
+ issue_postprocess: fetch(:committed_issue_postprocess),
113
+ issue_url: fetch(:committed_issue_url),
114
+ deployments: fetch(:committed_deployments),
115
+ deployment_id: fetch(:committed_deployment_id)
116
+ })
117
+
91
118
  # Only do this on the primary web server
92
119
  on primary :web do
93
120
  # Get the Capistrano revision log
94
121
  lines = capture(:cat, revision_log).split("\n").reverse
95
122
 
96
- # Build the regex to search for revision data in the log, by default this
97
- # is the localised string from Capistrano
98
- search = ::Capistrano::Committed.revision_search_regex(fetch(:committed_revision_line))
99
-
100
123
  # Build the revisions hash
101
- revisions = ::Capistrano::Committed.get_revisions_from_lines(lines, search, fetch(:branch), fetch(:committed_revision_limit))
124
+ revisions = ::Capistrano::Committed.get_revisions_from_lines(lines)
102
125
 
103
126
  # No revisions, no log
104
127
  if revisions.empty?
@@ -112,7 +135,7 @@ namespace :committed do
112
135
  github = ::Capistrano::Committed::GithubApi.new(fetch(:committed_github_config))
113
136
 
114
137
  # Get the actual date of the commit referenced to by the revision
115
- revisions = ::Capistrano::Committed.add_dates_to_revisions(revisions, github, fetch(:committed_user), fetch(:committed_repo))
138
+ revisions = ::Capistrano::Committed.add_dates_to_revisions(revisions, github)
116
139
 
117
140
  # Get the earliest revision date
118
141
  earliest_date = ::Capistrano::Committed.get_earliest_date_from_revisions(revisions)
@@ -126,7 +149,7 @@ namespace :committed do
126
149
  end
127
150
 
128
151
  # Go back an extra N days
129
- earliest_date = ::Capistrano::Committed.add_buffer_to_time(earliest_date, fetch(:committed_commit_buffer))
152
+ earliest_date = ::Capistrano::Committed.add_buffer_to_time(earliest_date)
130
153
  revisions[:previous][:date] = earliest_date
131
154
 
132
155
  # Get all the commits on this branch
@@ -175,10 +198,17 @@ namespace :committed do
175
198
 
176
199
  # Push pull request data in to the revision entries hash
177
200
  key = revisions.keys[revision_index]
201
+ sub_commits = []
202
+ pull_request[:commits].each do |c|
203
+ sub_commits << {
204
+ type: :commit,
205
+ info: c
206
+ }
207
+ end
178
208
  revisions[key][:entries][pull_request[:info][:merged_at]] = [{
179
209
  type: :pull_request,
180
210
  info: pull_request[:info],
181
- commits: pull_request[:commits]
211
+ commits: sub_commits
182
212
  }]
183
213
 
184
214
  # Delete commits which are in this pull request from the hash of commits
@@ -210,100 +240,38 @@ namespace :committed do
210
240
  }
211
241
  end
212
242
 
213
- # Loop through the revisions to create the output
214
- output = []
215
- revisions.each do |release, revision|
216
- # Build the revision header
217
- output += ::Capistrano::Committed.format_revision_header(release,
218
- revision)
219
-
220
- # Loop through the entries in this revision
221
- items = Hash[revision[:entries].sort_by { |date, _entries| date }.reverse]
222
- items.each do |_date, entries|
223
- entries.each do |entry|
224
- case entry[:type]
225
- when :pull_request
226
- # These are pull requests that are included in this revision
227
-
228
- # Print out the pull request number and title
229
- output << format(' * %s',
230
- t('committed.output.pull_request_number',
231
- number: entry[:info][:number]))
232
- output << format(' %s', entry[:info][:title])
233
- output << ''
234
-
235
- # Print out each line of the pull request description
236
- lines = entry[:info][:body].chomp.split("\n")
237
- unless lines.empty?
238
- output << format(' %s', lines.join("\n "))
239
- output << ''
240
- end
241
-
242
- # Get any issue numbers referred to in the commit info and print
243
- # links to them
244
- urls = ::Capistrano::Committed.get_issue_urls(fetch(:committed_issue_match),
245
- fetch(:committed_issue_postprocess),
246
- fetch(:committed_issue_url),
247
- entry[:info][:title] + entry[:info][:body])
248
- output += ::Capistrano::Committed.format_issue_urls(urls)
249
-
250
- # Merger details
251
- output << format(' %s',
252
- t('committed.output.merged_on',
253
- time: entry[:info][:merged_at]))
254
- output << format(' %s',
255
- t('committed.output.merged_by',
256
- login: entry[:info][:merged_by][:login]))
257
- output << ''
258
-
259
- # Print a link to the pull request on GitHub
260
- output << format(' %s', entry[:info][:html_url])
261
- output << ''
262
-
263
- # Loop through the commits in this pull request
264
- unless entry[:commits].nil?
265
- entry[:commits].each do |commit|
266
- output << (' ' + ('-' * 90))
267
- output << ' |'
268
- output += ::Capistrano::Committed.format_commit(commit,
269
- ' |',
270
- fetch(:committed_issue_match),
271
- fetch(:committed_issue_postprocess),
272
- fetch(:committed_issue_url))
273
- end
274
- output << (' ' + ('-' * 90))
275
- output << ''
276
- end
277
-
278
- when :commit
279
- # These are commits that are included in this revision, but are
280
- # not in any pull requests
281
- output += ::Capistrano::Committed.format_commit(entry[:info],
282
- '',
283
- fetch(:committed_issue_match),
284
- fetch(:committed_issue_postprocess),
285
- fetch(:committed_issue_url))
286
- end
287
-
288
- output << ('-' * 94)
289
- output << ''
290
- end
291
- end
243
+ # Send the text output to screen, or to a file on the server
292
244
 
293
- output << ''
294
- end
245
+ # Create the mustache instance and plug in the revisions
246
+ output = ::Capistrano::Committed::Output.new()
247
+ output[:revisions] = revisions.values
248
+ output[:page_title] = t('committed.output.page_title',
249
+ repo: format('%s/%s', fetch(:committed_user), fetch(:committed_repo)))
295
250
 
296
- # Send the output to screen, or to a file on the server
297
- if fetch(:committed_output_path).nil?
251
+ # Send the text output to a file on the server
252
+ if fetch(:committed_output_text_path).nil?
298
253
  # Just print to STDOUT
299
- puts output
254
+ puts output.render
300
255
  else
301
256
  # Determine the output path and upload the output there
302
- output_path = format(fetch(:committed_output_path), current_path)
303
- upload! StringIO.new(output.join("\n")), output_path
257
+ output_text_path = format(fetch(:committed_output_text_path), current_path)
258
+ upload! StringIO.new(output.render), output_text_path
259
+
260
+ # Make sure the report is world readable
261
+ execute(:chmod, 'a+r', output_text_path)
262
+ end
263
+
264
+ # Send the html output to a file on the server
265
+ unless fetch(:committed_output_html_path).nil?
266
+ # Switch to the HTML template
267
+ output.template_file = output.get_output_template_path('html')
268
+
269
+ # Determine the output path and upload the output there
270
+ output_html_path = format(fetch(:committed_output_html_path), current_path)
271
+ upload! StringIO.new(output.render), output_html_path
304
272
 
305
273
  # Make sure the report is world readable
306
- execute(:chmod, 'a+r', output_path)
274
+ execute(:chmod, 'a+r', output_html_path)
307
275
  end
308
276
  end
309
277
  end
@@ -319,7 +287,8 @@ namespace :load do
319
287
  set :committed_github_config, -> { {} }
320
288
  set :committed_revision_limit, -> { 10 }
321
289
  set :committed_commit_buffer, -> { 1 }
322
- set :committed_output_path, -> { '%s/public/committed.txt' }
290
+ set :committed_output_text_path, -> { '%s/public/committed.txt' }
291
+ set :committed_output_html_path, -> { '%s/public/committed.html' }
323
292
  set :committed_issue_match, -> { '\[\s?([a-zA-Z0-9]+\-[0-9]+)\s?\]' }
324
293
  set :committed_issue_postprocess, -> { [] }
325
294
  set :committed_issue_url, -> { 'https://example.jira.com/browse/%s' }
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.7
4
+ version: 0.0.8
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-05-17 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: mustache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +120,9 @@ files:
106
120
  - lib/capistrano/committed.rb
107
121
  - lib/capistrano/committed/github_api.rb
108
122
  - lib/capistrano/committed/i18n.rb
123
+ - lib/capistrano/committed/output.rb
124
+ - lib/capistrano/committed/output/output_html.mustache
125
+ - lib/capistrano/committed/output/output_txt.mustache
109
126
  - lib/capistrano/committed/version.rb
110
127
  - lib/capistrano/tasks/committed.rake
111
128
  homepage: https://github.com/sambauers/capistrano-committed