Class: Dude::Gitlab::AddSpendTime

Inherits:
Base
  • Object
show all
Defined in:
lib/dude/gitlab/add_spend_time.rb

Constant Summary

Constants included from Settings

Settings::CONFIG_FILE

Instance Attribute Summary

Attributes included from Service

#options

Instance Method Summary collapse

Methods inherited from Base

#check_input_data, #configure_gitlab, #initialize, #issue_exists?, #project_id, #throw_error

Methods included from Settings

#file, #read, #settings

Methods included from Service

included, #initialize

Constructor Details

This class inherits a constructor from Dude::Gitlab::Base

Instance Method Details

#add_spend_timeObject



13
14
15
16
17
# File 'lib/dude/gitlab/add_spend_time.rb', line 13

def add_spend_time
  ::Gitlab.add_time_spent_on_issue(
    project_id, options[:issue_id], "#{options[:duration]}s"
  )
end

#callObject



4
5
6
7
8
9
10
11
# File 'lib/dude/gitlab/add_spend_time.rb', line 4

def call
  if duration_exists?
    add_spend_time
    print_success_message
  else
    print_error_message
  end
end

#duration_exists?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dude/gitlab/add_spend_time.rb', line 19

def duration_exists?
  options[:duration] > 0
end

#formatted_timeObject



31
32
33
# File 'lib/dude/gitlab/add_spend_time.rb', line 31

def formatted_time
  Time.at(options[:duration]).utc.strftime('%H:%M:%S').to_s.colorize(:green)
end


27
28
29
# File 'lib/dude/gitlab/add_spend_time.rb', line 27

def print_error_message
  puts "Nothing to add".colorize(:yellow)
end


23
24
25
# File 'lib/dude/gitlab/add_spend_time.rb', line 23

def print_success_message
  puts "Added #{formatted_time} to spent time"
end