Skip to content

Adding Git Style Messages #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ task :clean do
end

require 'rake/testtask'
ENV['EDITOR'] = ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this sets EDITOR globally for the Rakefile, because it's executed at the top level. This is probably not what is intended.

Rake::TestTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/*_test.rb']
Expand Down
60 changes: 57 additions & 3 deletions lib/hcl/commands.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'chronic'
require 'highline'
require 'tempfile'

module HCl
module Commands
Expand Down Expand Up @@ -111,9 +112,24 @@ def start *args
if task.nil?
fail "Unknown task alias, try one of the following: ", aliases.join(', ')
end
note = args.join(' ')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good functionality but it repeats a lot of code. You should consider creating a helper method of some kind that does most of the heavy lifting, and then your repeated pattern is just a method call.

if note == ''
m = Tempfile.new("message_temp")
m.write(args.join(' '))
m.close
if ENV['EDITOR'] == ''
ENV['EDITOR'] = 'touch'
end
system("$EDITOR #{m.path}")
m.open
m.rewind
note = m.read
m.close
m.unlink
end
timer = task.start http,
:starting_time => starting_time,
:note => args.join(' ')
:note => note
"Started timer for #{timer} (at #{current_time})"
end

Expand All @@ -126,7 +142,28 @@ def log *args
def stop *args
entry = DayEntry.with_timer(http) || DayEntry.with_timer(http, Date.today - 1)
if entry
entry.append_note(http, args.join(' ')) if args.any?
note = args.join(' ')
set_note = ''
if note == ''
set_note = entry.notes
m = Tempfile.new("message_temp")
m.write(set_note)
m.close
if ENV['EDITOR'] == ''
ENV['EDITOR'] = 'touch'
end
system("$EDITOR #{m.path}")
m.open
m.rewind
set_note = m.read
m.close
m.unlink
end
if set_note != ''
entry.set_note(http, set_note)
elsif note != ''
entry.append_note(http, note)
end
entry.toggle http
"Stopped #{entry} (at #{current_time})"
else
Expand All @@ -140,7 +177,24 @@ def note *args
if args.empty?
return entry.notes
else
entry.append_note http, args.join(' ')
note = args.join(' ')
if note == ''
m = Tempfile.new("message_temp")
m.write(args.join(' '))
m.close
m.rewind
if ENV['EDITOR'] == ''
ENV['EDITOR'] = 'touch'
end
system("$EDITOR #{m.path}")
m.open
note = m.read
m.close
m.unlink
end
if note != ''
entry.append_note(http, note)
end
"Added note to #{entry}."
end
else
Expand Down
7 changes: 7 additions & 0 deletions lib/hcl/day_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def append_note http, new_notes
(self.notes << "\n#{new_notes}").lstrip!
http.post "daily/update/#{id}", notes:notes, hours:hours
end

def set_note http, new_notes
# If I don't include hours it gets reset.
# This doens't appear to be the case for task and project.
@data[:notes] = new_notes
http.post "daily/update/#{id}", notes:notes, hours:hours
end

def self.with_timer http, date=nil
daily(http, date).detect {|t| t.running? }
Expand Down
7 changes: 7 additions & 0 deletions test/day_entry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def test_append_note
entry.append_note(http, 'hi world')
assert_equal "yourmom.\nhi world", entry.notes
end

def test_set_note
entry = HCl::DayEntry.new(:id => '1', :notes => 'yourmom.', :hours => '1.0')
http.stubs(:post)
entry.set_note(http, 'hi world')
assert_equal "hi world", entry.notes
end

def test_append_note_to_empty
entry = HCl::DayEntry.new(:id => '1', :notes => nil, :hours => '1.0')
Expand Down