Class: Torque
- Inherits:
-
Object
- Object
- Torque
- 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/file_system.rb,
lib/torque/date_settings.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, FileSystem, InvalidProjectError, InvalidTokenError, Mailer, MissingOutputDirectoryError, MissingProjectError, MissingTokenError, MissingTorqueInfoFileError, Pivotal, PivotalAPIError, PivotalHTMLParser, Project, ProjectManager, RecordPathnameSettings, Settings, Story, TorqueInfoParser, Version
Instance Method Summary collapse
-
#email_notes(notes_string, project_name, mailer = nil) ⇒ Object
Emails notes_string to the email list specified in the torque info file.
-
#execute ⇒ Object
The method run by Torque on the command line.
-
#generate_notes(project_html, project_name) ⇒ Object
Returns a string comprising the release notes document.
-
#initialize(options, settings = nil, fs = nil) ⇒ Torque
constructor
Creates a new instance of Torque.
Constructor Details
#initialize(options, settings = nil, fs = nil) ⇒ Torque
Creates a new instance of Torque
22 23 24 25 26 27 |
# File 'lib/torque.rb', line 22 def initialize(, settings=nil, fs=nil) @fs = fs || FileSystem.new @settings = settings || Settings.new(, @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
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 87 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 |
#execute ⇒ Object
The method run by Torque on the command line. Generates the notes, writes them to file, optionally emails them
125 126 127 128 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 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/torque.rb', line 125 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 "Generating release notes: " \ + (@settings.custom_date_range ? "Custom " : "") \ + @settings.accept_from.strftime(@date_format) + " - " \ + @settings.accept_to.strftime(@date_format) \ + "..." project_html = Pivotal.new(@settings.token).get_project_stories(@settings.project) notes_string = generate_notes(project_html, project_name) # 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 all specified addresses email_notes(notes_string, project_name) if(@settings.email) end |
#generate_notes(project_html, project_name) ⇒ Object
Returns a string comprising the release notes document
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 |
# File 'lib/torque.rb', line 34 def generate_notes(project_html, project_name) notes_string = "" # Parses stories from html, filters them by date and returns them in an array stories = PivotalHTMLParser.new.process_project_date_filter(project_html, @settings.accept_from, @settings.accept_to) # 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 @settings.custom_date_range notes_string += "(custom "+@settings.accept_from.strftime(@date_format)+" - "+@settings.accept_to.strftime(@date_format)+")\n" else notes_string += "("+@settings.accept_from.strftime(@date_format)+" - "+@settings.accept_to.strftime(@date_format)+")\n" end notes_string += "\nThese notes were generated with Torque, a Pivotal Tracker command line utility" notes_string += "\n" notes_string += "\n" # Adds each story stories.sort! { |s1, s2| -(s1.date_accepted <=> s2.date_accepted) } stories.length.times do |i| story = stories[i] notes_string += "#{story.story_id}\n" notes_string += "#{story.name}\n" notes_string += "Accepted on "+story.date_accepted.strftime(@date_format)+"\n" notes_string += "https://www.pivotaltracker.com/story/show/#{story.story_id}\n" print_if_verbose "[Torque] (#{story.date_accepted.strftime(@date_format)}) #{story.name}" descArray = story.description.split("\n") descArray.length.times do |i| notes_string += "\t"+descArray[i]+"\n" end notes_string += "\n" end print_if_verbose "[Torque]" print_if_verbose "[Torque] Added #{stories.length} stories" notes_string end |