Class: Torque

Inherits:
Object
  • Object
show all
Defined in:
lib/torque.rb,
lib/torque/story.rb,
lib/torque/mailer.rb,
lib/torque/pivotal.rb,
lib/torque/version.rb,
lib/torque/settings.rb,
lib/torque/iteration.rb,
lib/torque/file_system.rb,
lib/torque/field_filter.rb,
lib/torque/date_settings.rb,
lib/torque/format_string.rb,
lib/torque/project/project.rb,
lib/torque/torque_info_parser.rb,
lib/torque/pivotal_html_parser.rb,
lib/torque/error/pivotal_api_error.rb,
lib/torque/project/project_manager.rb,
lib/torque/record_pathname_settings.rb,
lib/torque/error/invalid_token_error.rb,
lib/torque/error/missing_token_error.rb,
lib/torque/error/invalid_project_error.rb,
lib/torque/error/missing_project_error.rb,
lib/torque/error/missing_output_directory_error.rb,
lib/torque/error/missing_torque_info_file_error.rb

Overview

The central class for Torque. Takes in a hash of options, generates release notes from online data, writes them to file and emails them

Defined Under Namespace

Classes: DateSettings, FieldFilter, FileSystem, FormatString, InvalidProjectError, InvalidTokenError, Iteration, Mailer, MissingOutputDirectoryError, MissingProjectError, MissingTokenError, MissingTorqueInfoFileError, Pivotal, PivotalAPIError, PivotalHTMLParser, Project, ProjectManager, RecordPathnameSettings, Settings, Story, TorqueInfoParser, Version

Instance Method Summary collapse

Constructor Details

#initialize(options, settings = nil, fs = nil) ⇒ Torque

Returns a new instance of Torque.

Parameters:

  • options

    A hash of the settings to use for

  • settings (defaults to: nil)

    An instance of Torque::Settings (default: Torque::Settings.new)

  • settings (defaults to: nil)

    An instance of Torque::FileSystem (default: Torque::FileSystem.new)



20
21
22
23
24
25
# File 'lib/torque.rb', line 20

def initialize(options, settings=nil, fs=nil)
  @fs = fs || FileSystem.new
  @settings = settings || Settings.new(options, @fs)

  @date_format = "%Y/%m/%d"
end

Instance Method Details

#email_notes(notes_string, project_name, mailer = nil) ⇒ Object

Emails notes_string to the email list specified in the torque info file

Parameters:

  • notes_string

    A string representation of the generated release notes

  • project_name

    The name of the current project

  • mailer (defaults to: nil)

    An instance of Torque::Mailer (default: Torque::Mailer.new(@settings.email_address, @settings.email_password) )



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/torque.rb', line 129

def email_notes(notes_string, project_name, mailer=nil)
  print_if_not_silent "Emailing notes..."

  mailer ||= Mailer.new(@settings.email_address, @settings.email_password)

  if @settings.email_address.blank?
    print_if_not_silent "Emailing notes failed: No sender email address found. (Set this with 'torque email')"
  elsif @settings.email_password.blank?
    print_if_not_silent "Emailing notes failed: No sender email password found. (Set this with 'torque email')"
  elsif(@settings.email_to.length == 0)
    print_if_not_silent "No email addresses found. (Add them with 'torque email')"
  else
  
    address_list = ""
    @settings.email_to.each_with_index {
      |address, i|

      if i!=0
        address_list << ", "
      end
      address_list << address
    }

    subject_line = \
      "Release Notes: Project #{@settings.project} - '#{project_name}' (" \
      + (@settings.custom_date_range ? "Custom " : "") \
      + "#{@settings.accept_from.strftime('%Y/%m/%d')} - " \
      + "#{@settings.accept_to.strftime('%Y/%m/%d')}" \
      + ")"

    mailer.send_notes(notes_string, subject_line, address_list)

    print_if_not_silent "Emailed notes to #{address_list}"
  end
end

#executeObject

The method run by Torque on the command line. Generates the notes, writes them to file, optionally emails them

Returns:

  • The generated notes



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/torque.rb', line 169

def execute

  # Determines the current project

  torque_info = TorqueInfoParser.new(@settings.torque_info_path)
  project_manager = ProjectManager.new(torque_info)
  
  project_manager.load_project_list
  project_name = project_manager.current_project.name

  # Generates the notes

  print_if_not_silent "Current project: #{@settings.project} - '#{project_name}'"

  print_if_not_silent "Filter: \"#{@settings.filter_string}\"" if @settings.filters_on

  if @settings.iterations
    print_if_not_silent "Generating release notes: Last #{@settings.iterations} iterations..."

  else
    print_if_not_silent "Generating release notes: " \
      + (@settings.custom_date_range ? "Custom " : "") \
      + @settings.accept_from.strftime(@date_format) + " - " \
      + @settings.accept_to.strftime(@date_format) \
      + "..."
  end

  pivotal = Pivotal.new(@settings.token)
  if @settings.iterations
    project_html = pivotal.get_project_iterations(@settings.project, @settings.iterations)
  else
    project_html = pivotal.get_project_stories(@settings.project)
  end
  
  iterations_on = (!@settings.iterations.nil?)
  notes_string = generate_notes(project_html, project_name, iterations_on)

  # Writes the notes to file

  root_dir_path = Pathname.new(@settings.root_dir)
  rel_notes_path = Pathname.new(@settings.current_notes_path).relative_path_from(root_dir_path)
  print_if_not_silent "- Writing notes > #{rel_notes_path}"

  @fs.file_write("#{@settings.current_notes_path}", notes_string)

  # Creates a record of the notes file

  rel_record_path = Pathname.new(@settings.record_path).relative_path_from(root_dir_path)
  print_if_not_silent "- Copying notes > #{rel_record_path}"

  begin
    @fs.file_write("#{@settings.record_path}", notes_string)
  rescue => e
    err_str = "WARNING: Unable to make a record of the release notes file. Could not locate records "
    err_str += "directory \"#{File.expand_path(@settings.record_path)}\""
    print_if_not_silent err_str
  end

  print_if_not_silent "Notes generated!"

  # Emails the release notes to the mailing list 
  
  email_notes(notes_string, project_name) if(@settings.email)

end

#generate_notes(project_html, project_name, iterations_on = false) ⇒ Object

Returns A string comprising the release notes document.

Parameters:

  • project_html

    An html string containing all the project’s stories

  • project_name

    The name of the current project

  • iterations_on (defaults to: false)

    True if the stories are organized into iterations, else false

Returns:

  • A string comprising the release notes document



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/torque.rb', line 33

def generate_notes(project_html, project_name, iterations_on=false)

  notes_string = ""

  # Adds the header
  notes_string += Date.today.strftime(@date_format)+"\n"
  notes_string += "Release Notes\n"
  notes_string += "Project #{@settings.project} - '#{project_name}'\n"

  if iterations_on
    # Past iterations header
    notes_string += "Last "
    notes_string += (@settings.iterations == 1 \
                    ? "iteration"
                    : "#{@settings.iterations} iterations"
                    )
    notes_string += "\n"

  elsif @settings.custom_date_range
    # Custom date range header
    notes_string += "(custom "+@settings.accept_from.strftime(@date_format)+" - "+@settings.accept_to.strftime(@date_format)+")\n"
  
  else
    # Default date range header
    notes_string += "("+@settings.accept_from.strftime(@date_format)+" - "+@settings.accept_to.strftime(@date_format)+")\n"
  end
  
  if @settings.filters_on
    # Filters header
    notes_string += "Filter '#{@settings.filter_string}'\n"
  end

  notes_string += "\n"
  notes_string += "These notes were generated with Torque, a Pivotal Tracker command line utility\n"
  notes_string += "\n"

  html_parser = PivotalHTMLParser.new
  html_parser.add_date_filter(@settings.accept_from, @settings.accept_to) unless @settings.iterations
  html_parser.add_field_filters(@settings.filters) if @settings.filters_on

  if iterations_on
    # Adds each iteration
    
    iteration_list = html_parser.process_project_iterations(project_html)

    iteration_list = Iteration.sort_list(iteration_list)
    iteration_list.each do |iteration|
      notes_string += "-- Iteration #{iteration.number} --\n"
      notes_string += "\n"

      print_if_verbose "[Torque]"
      print_if_verbose "[Torque] -- Iteration #{iteration.number} --"

      iteration.sort_stories
      iteration.stories.each do |story|
        notes_string += @settings.format_string.apply(story)
        notes_string += "\n"
        notes_string += "\n"

        print_if_verbose "[Torque] (#{story.date_accepted.strftime(@date_format)}) #{story.name}"
      end
    end

    num_stories = 0
    iteration_list.each {|iteration| num_stories += iteration.stories.length}

    print_if_verbose "[Torque]"
    print_if_verbose "[Torque] Added #{num_stories} stories"

  else
    # Adds each story
    
    stories = html_parser.process_project(project_html)

    stories = Story.sort_list(stories)
    stories.each do |story|
      notes_string += @settings.format_string.apply(story)
      notes_string += "\n"
      notes_string += "\n"

      print_if_verbose "[Torque] (#{story.date_accepted.strftime(@date_format)}) #{story.name}"
    end

    print_if_verbose "[Torque]"
    print_if_verbose "[Torque] Added #{stories.length} stories"
  end

  notes_string
end