Module: PT::Action
- Included in:
- CLI
- Defined in:
- lib/pt/action.rb
Instance Method Summary collapse
- #accept_story(story) ⇒ Object
- #add_label_story(story) ⇒ Object
- #assign_story(story) ⇒ Object
- #choose_person ⇒ Object
- #comment_story(story) ⇒ Object
- #copy_story_id(story) ⇒ Object
- #copy_story_url(story) ⇒ Object
- #create_interactive_story ⇒ Object
- #deliver_story(story) ⇒ Object
- #done_story(story) ⇒ Object
- #edit_story(story) ⇒ Object
- #edit_story_task(task) ⇒ Object
- #edit_using_editor(content = nil) ⇒ Object
- #estimate_story(story) ⇒ Object
- #finish_story(story) ⇒ Object
- #open_story(story) ⇒ Object
- #open_story_from ⇒ Object
- #reject_story(story) ⇒ Object
- #save_recent_task(task_id) ⇒ Object
- #show_story(story) ⇒ Object
- #start_story(story) ⇒ Object
- #tasks_story(story) ⇒ Object
- #unstart_story(story) ⇒ Object
Instance Method Details
#accept_story(story) ⇒ Object
137 138 139 140 |
# File 'lib/pt/action.rb', line 137 def accept_story story @client.mark_task_as(story, 'accepted') congrats("Accepted") end |
#add_label_story(story) ⇒ Object
85 86 87 88 89 |
# File 'lib/pt/action.rb', line 85 def add_label_story(story) label = ask("Which label?") @client.add_label(story, label ); congrats("#{label} added, thanks!") end |
#assign_story(story) ⇒ Object
67 68 69 70 71 |
# File 'lib/pt/action.rb', line 67 def assign_story story owner = choose_person @client.assign_story(story, owner) congrats("story assigned to #{owner.initials}, thanks!") end |
#choose_person ⇒ Object
264 265 266 267 268 |
# File 'lib/pt/action.rb', line 264 def choose_person members = @client.get_members table = PersonsTable.new(members.map(&:person)) select("Please select a member to see his tasks.", table) end |
#comment_story(story) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pt/action.rb', line 73 def comment_story(story) say("Please write your comment") comment = edit_using_editor begin @client.comment_task(story, comment) congrats("Comment sent, thanks!") save_recent_task( story.id ) rescue error("Ummm, something went wrong. Comment cancelled") end end |
#copy_story_id(story) ⇒ Object
160 161 162 163 |
# File 'lib/pt/action.rb', line 160 def copy_story_id(story) `echo #{story.id} | pbcopy` congrats("Story ID copied") end |
#copy_story_url(story) ⇒ Object
165 166 167 168 |
# File 'lib/pt/action.rb', line 165 def copy_story_url(story) `echo #{story.url} | pbcopy` congrats("Story URL copied") end |
#create_interactive_story ⇒ Object
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 |
# File 'lib/pt/action.rb', line 170 def create_interactive_story # set title title = ask("Name for the new task:") # set owner if ask('Do you want to assign it now? (y/n)').downcase == 'y' members = @client.get_members table = PersonsTable.new(members.map(&:person)) owner = select("Please select a member to assign him the task.", table) owner_id = owner.id end # set story type type = HighLine.new.choose do || .prompt = 'Please set type of story:' .choice(:feature) .choice(:bug) .choice(:chore) .choice(:release) .default = :feature end description = edit_using_editor if ask('Do you want to write description now?(y/n)') == 'y' story = @client.create_story( name: title, owner_ids: [owner_id], requested_by_id: Settings[:user_id], story_type: type, description: description ) congrats("#{type} #{(' for ' + owner.name ) if owner} has been created \n #{story.url}") story end |
#deliver_story(story) ⇒ Object
131 132 133 134 135 |
# File 'lib/pt/action.rb', line 131 def deliver_story story return if story.story_type == 'chore' @client.mark_task_as(story, 'delivered') congrats("story delivered, congrats!") end |
#done_story(story) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/pt/action.rb', line 152 def done_story(story) start_story story finish_story story deliver_story story end |
#edit_story(story) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/pt/action.rb', line 204 def edit_story(story) # set title if ask("Edit title?(y/n) [#{story.name}]") { |yn| yn.limit = 1, yn.validate = /[yn]/i } == 'y' say('Edit your story name') story.name = edit_using_editor(story.name) end # set story type story.story_type = case ask('Edit Type? (f)eature (c)hore, (b)ug, enter to skip)') when 'c', 'chore' 'chore' when 'b', 'bug' 'bug' when 'f', 'feature' 'feature' end story.description = edit_using_editor(story.description) if ask('Do you want to edit description now?(y/n)') == 'y' story = story.save congrats("'#{story.name}' has been edited \n #{story.url}") story end |
#edit_story_task(task) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/pt/action.rb', line 227 def edit_story_task(task) action_class = Struct.new(:action, :key) table = ActionTable.new([ action_class.new('Complete', :complete), action_class.new('Edit', :edit) ]) action_to_execute = select('What to do with todo?', table) task.project_id = project.id task.client = project.client case action_to_execute.key when :complete then task.complete = true congrats('Todo task completed!') when :edit then new_description = ask('New task description') task.description = new_description congrats("Todo task changed to: \"#{task.description}\"") end task.save end |
#edit_using_editor(content = nil) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/pt/action.rb', line 250 def edit_using_editor(content=nil) editor = ENV.fetch('EDITOR') { 'vi' } temp_path = "/tmp/editor-#{ Process.pid }.txt" File.write(temp_path, content) if content system "#{ editor } #{ temp_path }" begin content = File.read(temp_path) File.delete(temp_path) content rescue "" end end |
#estimate_story(story) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/pt/action.rb', line 91 def estimate_story(story) if story.story_type == 'feature' estimation ||= ask("How many points you estimate for it? (#{project.point_scale})") @client.estimate_story(story, estimation) congrats("Task estimated, thanks!") else error('Only feature can be estimated!') end end |
#finish_story(story) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/pt/action.rb', line 122 def finish_story story if story.story_type == 'chore' @client.mark_task_as(story, 'accepted') else @client.mark_task_as(story, 'finished') end congrats("Another story bites the dust, yeah!") end |
#open_story(story) ⇒ Object
62 63 64 65 |
# File 'lib/pt/action.rb', line 62 def open_story story `open #{story.url}` return :no_request end |
#open_story_from ⇒ Object
270 271 |
# File 'lib/pt/action.rb', line 270 def open_story_from end |
#reject_story(story) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/pt/action.rb', line 142 def reject_story(story) comment = ask("Please explain why are you rejecting the story.") if @client.comment_task(story, comment) @client.mark_task_as(story, 'rejected') congrats("story rejected, thanks!") else error("Ummm, something went wrong.") end end |
#save_recent_task(task_id) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/pt/action.rb', line 273 def save_recent_task( task_id ) # save list of recently accessed tasks unless (Settings[:recent_tasks]) Settings[:recent_tasks] = Array.new(); end Settings[:recent_tasks].unshift( task_id ) Settings[:recent_tasks] = Settings[:recent_tasks].uniq() if Settings[:recent_tasks].length > 10 Settings[:recent_tasks].pop() end @config.save_config( Settings, @config.get_local_config_path ) end |
#show_story(story) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pt/action.rb', line 3 def show_story(story) clear title('========================================='.red) title story.name.red title('========================================='.red) estimation = [-1, nil].include?(story.estimate) ? "Unestimated" : "#{story.estimate} points" requester = story.requested_by ? story.requested_by.initials : Settings[:user_name] if story.instance_variable_get(:@owners).present? owners = story.owners.map(&:initials).join(',') end "#{story.current_state.capitalize} #{story.story_type} | #{estimation} | Req: #{requester} | Owners: #{owners} | ID: #{story.id}" if story.instance_variable_get(:@labels).present? "Labels: " + story.labels.map(&:name).join(', ') end story.description.green unless story.description.nil? || story.description.empty? "View on pivotal: #{story.url}" if story.instance_variable_get(:@tasks).present? title('tasks'.yellow) story.tasks.each{ |t| "- #{t.complete ? "[done]" : ""} #{t.description}" } end if story.instance_variable_get(:@comments).present? story.comments.each do |n| title('......................................'.blue) text = ">> #{n.person.initials}: #{n.text}" text << "[#{n..size}F]" if n. text end end save_recent_task( story.id ) say "" title '================================================='.red choice = ask "Please choose action ([b]:back to table | [m]:show menu | [q] quit)" case choice when 'q' quit when 'm' choose_action(story) when 'b' say('back to table ....') return :no_request end end |
#start_story(story) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/pt/action.rb', line 101 def start_story story if story.story_type == 'feature' && !story.estimate estimate_story(story) end @client.mark_task_as(story, 'started') congrats("story started, go for it!") end |
#tasks_story(story) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pt/action.rb', line 51 def tasks_story(story) story_task = get_open_story_task_from_params(story) if story_task.position == -1 description = ask('Title for new task') story.create_task(:description => description) congrats("New todo task added to \"#{story.name}\"") else edit_story_task story_task end end |
#unstart_story(story) ⇒ Object
109 110 111 112 |
# File 'lib/pt/action.rb', line 109 def unstart_story story @client.mark_task_as(story, 'unstarted') congrats("story unstarted") end |