Class: Capistrano::Committed::Output

Inherits:
Mustache
  • Object
show all
Defined in:
lib/capistrano/committed/output.rb

Constant Summary collapse

@@template_format =
'txt'

Instance Method Summary collapse

Instance Method Details

#commitsObject



129
130
131
132
133
134
# File 'lib/capistrano/committed/output.rb', line 129

def commits
  return unless context.current[:type] == :pull_request
  return if context.current[:commits].nil?
  return if context.current[:commits].empty?
  context.current[:commits].flatten
end

#get_output_path(file) ⇒ Object



11
12
13
# File 'lib/capistrano/committed/output.rb', line 11

def get_output_path(file)
  format('%s/output/%s', File.dirname(__FILE__), file)
end

#get_output_template_path(format = 'txt', set_template_format = true) ⇒ Object



15
16
17
18
# File 'lib/capistrano/committed/output.rb', line 15

def get_output_template_path(format = 'txt', set_template_format = true)
  @@template_format = format if set_template_format
  get_output_path(format('output_%s.mustache', format))
end

#has_commitsObject



136
137
138
# File 'lib/capistrano/committed/output.rb', line 136

def has_commits
  !commits.nil?
end


95
96
97
# File 'lib/capistrano/committed/output.rb', line 95

def has_issue_links
  !issue_links.empty?
end

#has_item_linesObject



77
78
79
# File 'lib/capistrano/committed/output.rb', line 77

def has_item_lines
  !item_lines.empty?
end

#has_item_subtitleObject



62
63
64
# File 'lib/capistrano/committed/output.rb', line 62

def has_item_subtitle
  !item_subtitle.nil?
end


91
92
93
# File 'lib/capistrano/committed/output.rb', line 91

def issue_link
  format_link(context.current)
end


81
82
83
84
85
86
87
88
89
# File 'lib/capistrano/committed/output.rb', line 81

def issue_links
  return unless context.current[:info]
  case context.current[:type]
  when :commit
    ::Capistrano::Committed.get_issue_urls(context.current[:info][:commit][:message])
  when :pull_request
    ::Capistrano::Committed.get_issue_urls(context.current[:info][:title] + context.current[:info][:body])
  end
end

#item_created_byObject



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/capistrano/committed/output.rb', line 109

def item_created_by
  return unless context.current[:info]
  case context.current[:type]
  when :commit
    t('committed.output.committed_by', login: context.current[:info][:committer][:login])
  when :pull_request
    t('committed.output.merged_by', login: context.current[:info][:merged_by][:login])
  else

  end
end

#item_created_onObject



99
100
101
102
103
104
105
106
107
# File 'lib/capistrano/committed/output.rb', line 99

def item_created_on
  return unless context.current[:info]
  case context.current[:type]
  when :commit
    t('committed.output.committed_on', time: context.current[:info][:commit][:committer][:date])
  when :pull_request
    t('committed.output.merged_on', time: context.current[:info][:merged_at])
  end
end

#item_linesObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/capistrano/committed/output.rb', line 66

def item_lines
  return unless context.current[:info]
  case context.current[:type]
  when :commit
    message = context.current[:info][:commit][:message]
  when :pull_request
    message = context.current[:info][:body]
  end
  message.nil? ? [] : message.chomp.delete("\r").split("\n")
end


121
122
123
124
125
126
127
# File 'lib/capistrano/committed/output.rb', line 121

def item_link
  case context.current[:type]
  when :commit, :pull_request
    return unless context.current[:info]
    format_link(context.current[:info][:html_url])
  end
end

#item_subtitleObject



56
57
58
59
60
# File 'lib/capistrano/committed/output.rb', line 56

def item_subtitle
  return unless context.current[:type] == :pull_request
  return unless context.current[:info]
  context.current[:info][:title]
end

#item_titleObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/capistrano/committed/output.rb', line 44

def item_title
  return unless context.current[:info]
  case context.current[:type]
  when :commit
    t('committed.output.commit_sha',
      sha: context.current[:info][:sha])
  when :pull_request
    t('committed.output.pull_request_number',
      number: context.current[:info][:number])
  end
end

#itemsObject



39
40
41
42
# File 'lib/capistrano/committed/output.rb', line 39

def items
  return unless context.current[:entries]
  Hash[context.current[:entries].sort_by { |date, _entries| date }.reverse].values.flatten
end

#release_headerObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/capistrano/committed/output.rb', line 24

def release_header
  case context.current[:release]
  when :next
    t('committed.output.next_release')
  when :previous
    t('committed.output.previous_release',
      time: context.current[:date])
  else
    t('committed.output.current_release',
      release_time: Time.parse(context.current[:release]).iso8601,
      sha: context.current[:sha],
      commit_time: context.current[:date])
  end
end

#template_formatObject



20
21
22
# File 'lib/capistrano/committed/output.rb', line 20

def template_format
  @@template_format
end