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
- #prompt ⇒ 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
156 157 158 159 |
# File 'lib/pt/action.rb', line 156 def accept_story story @client.mark_task_as(story, 'accepted') congrats("Accepted") end |
#add_label_story(story) ⇒ Object
104 105 106 107 108 |
# File 'lib/pt/action.rb', line 104 def add_label_story(story) label = ask("Which label?") @client.add_label(story, label ); congrats("#{label} added, thanks!") end |
#assign_story(story) ⇒ Object
86 87 88 89 90 |
# File 'lib/pt/action.rb', line 86 def assign_story story owner = choose_person @client.assign_story(story, owner) congrats("story assigned to #{owner.initials}, thanks!") end |
#choose_person ⇒ Object
282 283 284 285 286 |
# File 'lib/pt/action.rb', line 282 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
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pt/action.rb', line 92 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
179 180 181 182 |
# File 'lib/pt/action.rb', line 179 def copy_story_id(story) `echo #{story.id} | pbcopy` congrats("Story ID copied") end |
#copy_story_url(story) ⇒ Object
184 185 186 187 |
# File 'lib/pt/action.rb', line 184 def copy_story_url(story) `echo #{story.url} | pbcopy` congrats("Story URL copied") end |
#create_interactive_story ⇒ Object
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 |
# File 'lib/pt/action.rb', line 189 def create_interactive_story # set title title = ask("Name for the new task:") owners = [] # set owner if prompt.yes?('Do you want to assign it now? (y/n)') members = @client.get_members member_choices = members.map(&:person).map do |p| { name: "[#{p.initials}] #{p.name}", value: p } end owners = prompt.multi_select("Select member?", member_choices, min: 1) end # set story type type = prompt.select("Please set type of story:") do || .enum "." .choice("feature") .choice("bug") .choice("chore") .choice("release") .default("feature") end description = edit_using_editor if prompt.yes?('Do you want to write description now?(y/n)') story_args = { name: title, owner_ids: owners.map(&:id), requested_by_id: Settings[:user_id], story_type: type, description: description } story = @client.create_story(story_args) congrats("#{type.capitalize} has been created \n #{story.url}") story end |
#deliver_story(story) ⇒ Object
150 151 152 153 154 |
# File 'lib/pt/action.rb', line 150 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
171 172 173 174 175 176 177 |
# File 'lib/pt/action.rb', line 171 def done_story(story) start_story story finish_story story deliver_story story end |
#edit_story(story) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/pt/action.rb', line 229 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
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/pt/action.rb', line 252 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
275 276 277 278 279 280 |
# File 'lib/pt/action.rb', line 275 def edit_using_editor(content=nil) editor = ENV.fetch('EDITOR') { 'vi' } temp_path = "/tmp/editor-#{ Process.pid }.txt" TTY::Editor.open(temp_path, text: content) File.write(temp_path, content) if content end |
#estimate_story(story) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/pt/action.rb', line 110 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
141 142 143 144 145 146 147 148 |
# File 'lib/pt/action.rb', line 141 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
81 82 83 84 |
# File 'lib/pt/action.rb', line 81 def open_story story `open #{story.url}` return :no_request end |
#open_story_from ⇒ Object
288 289 |
# File 'lib/pt/action.rb', line 288 def open_story_from end |
#prompt ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pt/action.rb', line 8 def prompt @prompt ||= TTY::Prompt .new .on(:keypress) do |event| if event.value == "j" prompt.trigger(:keydown) end if event.value == "k" prompt.trigger(:keyup) end end end |
#reject_story(story) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/pt/action.rb', line 161 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
291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/pt/action.rb', line 291 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
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pt/action.rb', line 22 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
120 121 122 123 124 125 126 |
# File 'lib/pt/action.rb', line 120 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
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pt/action.rb', line 70 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
128 129 130 131 |
# File 'lib/pt/action.rb', line 128 def unstart_story story @client.mark_task_as(story, 'unstarted') congrats("story unstarted") end |