Class: Afterlife::Clickup::UpdateTaskStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/afterlife/clickup/update_task_status.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(force: false, dry_run: false) ⇒ UpdateTaskStatus



12
13
14
15
16
17
18
# File 'lib/afterlife/clickup/update_task_status.rb', line 12

def initialize(force: false, dry_run: false)
  @force = force
  @dry_run = dry_run
  token = ENV['CLICKUP_TOKEN'] || fail('CLICKUP_TOKEN required, put `export CLICKUP_TOKEN=...` or the equivalent in your shell') # rubocop:disable Layout/LineLength
  @api = Api.new(token: token)
  @precedence_checker = StatusPrecedenceChecker.new
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



6
7
8
# File 'lib/afterlife/clickup/update_task_status.rb', line 6

def api
  @api
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



6
7
8
# File 'lib/afterlife/clickup/update_task_status.rb', line 6

def dry_run
  @dry_run
end

#forceObject (readonly)

Returns the value of attribute force.



6
7
8
# File 'lib/afterlife/clickup/update_task_status.rb', line 6

def force
  @force
end

#precedence_checkerObject (readonly)

Returns the value of attribute precedence_checker.



6
7
8
# File 'lib/afterlife/clickup/update_task_status.rb', line 6

def precedence_checker
  @precedence_checker
end

#target_statusObject (readonly)

Returns the value of attribute target_status.



6
7
8
# File 'lib/afterlife/clickup/update_task_status.rb', line 6

def target_status
  @target_status
end

Class Method Details

.call(task_ids, target_status, force: false, dry_run: false) ⇒ Object



8
9
10
# File 'lib/afterlife/clickup/update_task_status.rb', line 8

def self.call(task_ids, target_status, force: false, dry_run: false)
  new(force: force, dry_run: dry_run).call(task_ids, target_status)
end

Instance Method Details

#call(task_ids, target_status) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/afterlife/clickup/update_task_status.rb', line 20

def call(task_ids, target_status) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  if task_ids.empty?
    puts 'No tasks to update'
    return []
  end

  puts 'WARNING: Forcing status updates...' if force
  puts 'WARNING: Dry run, no tasks will be updated' if dry_run
  puts "Updating #{task_ids.length} tasks to '#{target_status}'"
  moved_task_ids = task_ids.map { |task_id| move_task(task_id, target_status) }.compact
  puts "#{dry_run ? 'Would have moved' : 'Moved'} #{moved_task_ids.length} tasks:"
  moved_task_ids.each do |task|
    puts "- #{task[:link]} (from '#{task[:previous_status]}' to '#{task[:new_status]}')"
  end
  moved_task_ids
end