class Abt::Providers::Asana::Commands::Start
Public Class Methods
description()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 12 def self.description "Move current or specified task to WIP section (column) and assign it to you" end
flags()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 16 def self.flags [ ["-s", "--set", "Set specified task as current"] ] end
usage()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 8 def self.usage "abt start asana[:<project-gid>/<task-gid>]" end
Public Instance Methods
perform()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 22 def perform require_task! print_task(project_gid, task) update_assignee_if_needed move_if_needed maybe_override_current_task end
Private Instance Methods
current_assignee()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 56 def current_assignee task["assignee"] end
current_task_section()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 82 def current_task_section task_section_membership&.dig("section") end
current_user()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 108 def current_user @current_user ||= api.get("users/me", opt_fields: "name") end
maybe_override_current_task()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 34 def maybe_override_current_task return unless flags[:set] return if path.nil? return if path == config.path return unless config.local_available? config.path = path warn("Current task updated") end
move_if_needed()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 64 def move_if_needed unless project_gid == config.path.project_gid warn("Task was not moved, this is not implemented for tasks outside current project") return end if task_already_in_wip_section? warn("Task already in section: #{current_task_section['name']}") else warn("Moving task to section: #{wip_section['name']}") move_task end end
move_task()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 96 def move_task body = { data: { task: task_gid } } body_json = Oj.dump(body, mode: :json) api.post("sections/#{config.wip_section_gid}/addTask", body_json) end
should_reassign?()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 60 def should_reassign? cli.prompt.boolean("Task is assigned to: #{current_assignee['name']}, take over?") end
task()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 112 def task @task ||= api.get("tasks/#{task_gid}", opt_fields: "name,memberships.section.name,assignee.name,permalink_url") end
task_already_in_wip_section?()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 78 def task_already_in_wip_section? !task_section_membership.nil? end
task_section_membership()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 86 def task_section_membership task["memberships"].find do |membership| membership.dig("section", "gid") == config.wip_section_gid end end
update_assignee()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 102 def update_assignee body = { data: { assignee: current_user["gid"] } } body_json = Oj.dump(body, mode: :json) api.put("tasks/#{task_gid}", body_json) end
update_assignee_if_needed()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 44 def update_assignee_if_needed if current_assignee.nil? warn("Assigning task to user: #{current_user['name']}") update_assignee elsif current_assignee["gid"] == current_user["gid"] warn("You are already assigned to this task") elsif should_reassign? warn("Reassigning task to user: #{current_user['name']}") update_assignee end end
wip_section()
click to toggle source
# File lib/abt/providers/asana/commands/start.rb, line 92 def wip_section @wip_section ||= api.get("sections/#{config.wip_section_gid}", opt_fields: "name") end