Class: Task

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Git
Defined in:
lib/caperoma/models/task.rb

Direct Known Subclasses

Chore, Meeting, TaskWithCommit

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Git

#git_actual_rebase, #git_branch, #git_checkout, #git_commit, #git_current_branch, #git_last_commit_name, #git_pull_request, #git_push, #git_rebase_to_upstream

Class Method Details

.abort_started(comment) ⇒ Object



40
41
42
43
44
# File 'lib/caperoma/models/task.rb', line 40

def self.abort_started(comment)
  puts 'Aborting current task'
  unfinished.each { |task| task.abort(comment) }
  puts 'Current task aborted'
end

.abort_started_without_time(comment) ⇒ Object



46
47
48
49
50
# File 'lib/caperoma/models/task.rb', line 46

def self.abort_started_without_time(comment)
  puts 'Aborting current task without putting time into Jira'
  unfinished.each { |task| task.abort_without_time(comment) }
  puts 'Current task aborted without putting time into Jira'
end

.finish_started(comment) ⇒ Object



28
29
30
31
32
# File 'lib/caperoma/models/task.rb', line 28

def self.finish_started(comment)
  puts 'Finishing current task'
  unfinished.each { |task| task.finish(comment) }
  puts 'Current task finished'
end

.pause_started(comment) ⇒ Object



34
35
36
37
38
# File 'lib/caperoma/models/task.rb', line 34

def self.pause_started(comment)
  puts 'Pausing current task'
  unfinished.each { |task| task.pause(comment) }
  puts 'Current task paused'
end

.statusObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/caperoma/models/task.rb', line 52

def self.status
  if unfinished.empty?
    puts 'You are not working on anything now.'
  else
    unfinished.each do |task|
      puts 'You are working on: '
      puts "Title: #{task.title}"
      puts "Type: #{task.type}"
      puts "Jira ID: #{task.jira_key} (#{task.jira_live_url})." if task.jira_key.present?
      puts "Pivotal ID: #{task.pivotal_id} (#{task.pivotal_url})" if task.pivotal_id.present?
      puts "Time spent at the moment: #{task.time_spent_so_far}"
      puts "Branch with the task: #{task.branch}" if task.branch.present?
      puts "Pull request will be sent to this branch: #{task.parent_branch}" if task.parent_branch.present?
      puts "Project location: #{task.project.folder_path}"
    end
  end
end

Instance Method Details

#abort(comment) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/caperoma/models/task.rb', line 88

def abort(comment)
  # finish without commit or push
  update_attribute(:finished_at, Time.now)
  close_issue_on_jira
  log_work_to_jira(comment) if should_log_work?
  finish_on_pivotal if finish_on_pivotal?
  puts time_spent
end

#abort_without_time(_comment) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/caperoma/models/task.rb', line 97

def abort_without_time(_comment)
  # finish without commit or push
  update_attribute(:finished_at, Time.now)
  close_issue_on_jira
  # the task closes on Jira, but is still running in Pivotal
  puts time_spent
end

#finish(comment) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/caperoma/models/task.rb', line 70

def finish(comment)
  # full pull request
  update_attribute(:finished_at, Time.now)
  close_issue_on_jira
  log_work_to_jira(comment) if should_log_work?
  finish_on_pivotal if finish_on_pivotal?
  puts time_spent
end

#jira_live_urlObject



131
132
133
# File 'lib/caperoma/models/task.rb', line 131

def jira_live_url
  "#{project.jira_url}browse/#{jira_key}" if jira_key.present?
end

#pause(comment = 'Done') ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/caperoma/models/task.rb', line 79

def pause(comment = 'Done')
  # finish with commit & push but without pull request
  update_attribute(:finished_at, Time.now)
  close_issue_on_jira
  log_work_to_jira(comment) if should_log_work?
  finish_on_pivotal if finish_on_pivotal?
  puts time_spent
end

#pivotal_urlObject



127
128
129
# File 'lib/caperoma/models/task.rb', line 127

def pivotal_url
  "https://www.pivotaltracker.com/story/show/#{pivotal_id}" if pivotal_id.present?
end

#should_log_work?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/caperoma/models/task.rb', line 105

def should_log_work?
  time_spent_so_far != '0h 0m' && Account.jira.present?
end

#time_spentObject



118
119
120
121
122
123
124
125
# File 'lib/caperoma/models/task.rb', line 118

def time_spent
  result = TimeDifference.between(started_at, finished_at).in_minutes

  hours = (result / 60).to_i
  minutes = (result - hours * 60).to_i

  "#{hours}h #{minutes}m"
end

#time_spent_in_minutesObject



135
136
137
# File 'lib/caperoma/models/task.rb', line 135

def time_spent_in_minutes
  TimeDifference.between(started_at, finished_at).in_minutes # TODO: test
end

#time_spent_so_farObject



109
110
111
112
113
114
115
116
# File 'lib/caperoma/models/task.rb', line 109

def time_spent_so_far
  result = TimeDifference.between(started_at, Time.now).in_minutes

  hours = (result / 60).to_i
  minutes = (result - hours * 60).to_i

  "#{hours}h #{minutes}m"
end