wlog 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +100 -39
  3. data/lib/wlog/commands/bootstrap_templates.rb +5 -0
  4. data/lib/wlog/commands/delete_attachment.rb +17 -0
  5. data/lib/wlog/commands/fetch_git_commits.rb +45 -0
  6. data/lib/wlog/commands/fetch_git_commits_standard.rb +29 -0
  7. data/lib/wlog/commands/innit_db.rb +3 -2
  8. data/lib/wlog/commands/write_template.rb +22 -0
  9. data/lib/wlog/domain/attachment.rb +26 -54
  10. data/lib/wlog/domain/git_commit.rb +11 -0
  11. data/lib/wlog/domain/issue.rb +14 -1
  12. data/lib/wlog/domain/key_value.rb +1 -1
  13. data/lib/wlog/domain/template_helper.rb +21 -0
  14. data/lib/wlog/migrations/fix_attachments_polymorphic_table.rb +15 -0
  15. data/lib/wlog/migrations/make_standard_tables.rb +0 -13
  16. data/lib/wlog/tech/git_commit_parser.rb +48 -0
  17. data/lib/wlog/tech/git_commit_printer.rb +19 -0
  18. data/lib/wlog/tech/uncolored_string.rb +1 -1
  19. data/lib/wlog/ui/bootstrap.rb +1 -0
  20. data/lib/wlog/ui/cli_interface.rb +2 -58
  21. data/lib/wlog/ui/edit_handler.rb +7 -0
  22. data/lib/wlog/ui/git_ui.rb +47 -0
  23. data/lib/wlog/ui/invoice_ui.rb +53 -36
  24. data/lib/wlog/ui/issue_ui.rb +57 -5
  25. data/lib/wlog/ui/template_ui.rb +2 -2
  26. data/lib/wlog/version.rb +1 -1
  27. data/spec/domain/attachment_spec.rb +49 -55
  28. data/spec/domain/commands/concat_desc_spec.rb +1 -0
  29. data/spec/domain/commands/new_entry_spec.rb +1 -0
  30. data/spec/domain/commands/replace_pattern_spec.rb +1 -0
  31. data/spec/domain/git_commits_spec.rb +85 -0
  32. data/spec/domain/invoice_spec.rb +35 -0
  33. data/spec/domain/issue_spec.rb +1 -0
  34. data/spec/domain/key_value_spec.rb +1 -0
  35. data/spec/domain/log_entry_spec.rb +1 -0
  36. data/spec/domain/sys_config_spec.rb +1 -0
  37. data/spec/spec_helper.rb +31 -0
  38. data/wlog.gemspec +3 -1
  39. metadata +40 -18
  40. data/lib/wlog/domain/session.rb +0 -17
  41. data/lib/wlog/domain/sql_modules/polymorphic_attachments_sql.rb +0 -24
  42. data/lib/wlog/domain/template_engine.rb +0 -55
  43. data/lib/wlog/sql/mono/1.sql +0 -50
  44. data/lib/wlog/sql/seq/.gitkeep +0 -0
  45. data/lib/wlog/sql/seq/2.sql +0 -4
  46. data/lib/wlog/sql/seq/3.sql +0 -3
  47. data/lib/wlog/ui/commands/ui_command.rb +0 -9
@@ -8,6 +8,7 @@ require 'wlog/commands/innit_db'
8
8
  require 'wlog/commands/concat_description'
9
9
  require 'wlog/domain/sys_config'
10
10
  require 'wlog/domain/timelog_helper'
11
+ require 'wlog/domain/attachment'
11
12
  require 'wlog/ui/edit_handler'
12
13
 
13
14
  module Wlog
@@ -30,7 +31,7 @@ class IssueUi
30
31
  when /^new/ then new_entry
31
32
  when /^(ls|show)/ then show_entries
32
33
  when /^desc/ then describe_issue
33
- when /^delete/ then delete_entry
34
+ when /^delete/ then delete_entry(cmd.split.drop 1)
34
35
  when /^edit/ then EditHandler.new(@issue).edit_what(cmd.split.drop 1)
35
36
  when /^concat/ then concat_description
36
37
  when /^replace/ then replace_pattern
@@ -38,6 +39,9 @@ class IssueUi
38
39
  when /^lt/ then time(cmd.split.drop 1) # lt for log time
39
40
  when /^forget/ then cmd = "end"
40
41
  when /^finish/ then finish ? cmd = "end" : nil
42
+ when /^attachout/ then output_attach
43
+ when /^attachls/ then show_attach
44
+ when /^attach/ then attach
41
45
  when /^help/ then print_help
42
46
  when /^end/ then next
43
47
  else puts "Type 'help' for help"
@@ -50,6 +54,44 @@ class IssueUi
50
54
 
51
55
  private
52
56
 
57
+ # Wriet out the data contained in the database of the attachment
58
+ def output_attach
59
+ att_id = Readline.readline('Which attachment to output? : ').to_i
60
+ loc = Readline.readline('Output where (abs dir) ? : ')
61
+ loc.chomp!
62
+ att = Attachment.find(att_id)
63
+
64
+ fh = File.open("#{loc}/#{att.filename}", 'w')
65
+ fh.write(att.data)
66
+ fh.close
67
+ end
68
+
69
+ def show_attach
70
+ atts = @issue.attachments
71
+ atts.each do |att|
72
+ printf "[%d] - %s (alias: %s)\n", att.id, att.filename, att.given_name
73
+ end
74
+ end
75
+
76
+ def attach
77
+ loc = Readline.readline('Absolute file location: ')
78
+ loc.strip!
79
+ name_alias = Readline.readline('Alias name for file (optional): ')
80
+ name_alias.strip!
81
+
82
+ fh = File.open(loc, "r")
83
+ data = fh.read
84
+ fh.close
85
+
86
+ att = Attachment.new(:filename => loc.split('/').last, :data => data,
87
+ :given_name => :name_alias)
88
+ @issue.attachments << att
89
+
90
+ puts 'Attached file.'
91
+ rescue
92
+ puts 'You need to provide a proper path.'
93
+ end
94
+
53
95
  # Time logging command
54
96
  def time(rest)
55
97
  time = TimelogHelper.parse(rest.join)
@@ -58,12 +100,17 @@ private
58
100
  end
59
101
 
60
102
  # Print the description of the issue
61
- def describe_issue; puts @issue end
103
+ def describe_issue;
104
+ puts @issue
105
+ end
62
106
 
63
107
  # This needs updating
64
108
  def print_help
65
109
  ["new", "Create a new log entry",
66
110
  "outcsv", "Export everything to CSV",
111
+ 'attach', 'Attach a file to the current issue',
112
+ 'attachls', 'Show what files have been attached to an issue',
113
+ 'attachout', 'Extract a file from the database',
67
114
  "help", "print this dialog",
68
115
  "end", "Exit the progam",
69
116
  "search", "Search for a string in the log description text",
@@ -91,9 +138,14 @@ private
91
138
  NewEntry.new(description, @issue).execute
92
139
  end
93
140
 
94
- def delete_entry
95
- id = Readline.readline('Remove task log with id : ').to_i
96
- LogEntry.delete(id)
141
+ def delete_entry(cmd_a)
142
+ case cmd_a[0]
143
+ when /t/, /task/ then LogEntry.delete(cmd_a[1])
144
+ when /a/, /attachment/ then Attachment.delete(cmd_a[1])
145
+ end
146
+ # If something gets deleted, we need to reload the issue so that the
147
+ # relations are ok.
148
+ @issue.reload
97
149
  end
98
150
 
99
151
  # Concatenate an aggregate description to a previous item
@@ -42,7 +42,7 @@ private
42
42
  end
43
43
 
44
44
  def ls
45
- num = SysConfig.get_config('template') || 1
45
+ num = KeyValue.get('template') || 1
46
46
  num = num.to_i
47
47
  Dir[TemplateDir + "*"].each_with_index do |file,ix|
48
48
  print " #{ix + 1 == num ? @strmaker.blue('*') : ' '} "
@@ -58,7 +58,7 @@ private
58
58
  return
59
59
  end
60
60
 
61
- SysConfig.store_config('template', num)
61
+ KeyValue.put!('template', num)
62
62
  end
63
63
 
64
64
  end
data/lib/wlog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wlog
2
- VERSION = "1.1.7"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,58 +1,52 @@
1
1
  # We'll be ignoring this for now...
2
2
  #
3
- # require_relative '../make_db'
4
- # require 'wlog/domain/attachment'
5
- # require 'wlog/domain/log_entry'
6
- # require 'wlog/domain/issue'
7
- #
8
- # include Wlog
9
- #
10
- # describe Attachment do
11
- #
12
- # db_name = './default'
13
- #
14
- # class FileMock
15
- # attr_accessor :filename, :data, :path
16
- # end
17
- #
18
- # def create_mock_file
19
- # fm = FileMock.new
20
- # fm.filename = "thefile.txt"
21
- # fm.data = "This is my text data."
22
- # fm.path = "/home/user/"
23
- # fm end
24
- #
25
- # before(:all) do
26
- # make_testing_db(db_name)
27
- # @db = DbRegistry.new(db_name)
28
- # @issue = Issue.new(@db)
29
- # @log_entry = LogEntry.new(@db)
30
- #
31
- # @issue.description = "This is my issue"
32
- # @issue.insert
33
- # @log_entry.issue_id = @issue.id
34
- # @log_entry.description = "This is my log_entry"
35
- # @log_entry.insert
36
- # end
37
- #
38
- # after(:all) do
39
- # FileUtils.rm db_name
40
- # end
41
- #
42
- # # Note: this example uses issue, but this will be valid for whatever other
43
- # # type we want to associate to this class.
44
- # it "should insert given polymorphic type" do
45
- # file = create_mock_file
46
- # attach = Attachment.new(@db, Issue.name, @issue.id)
47
- # attach.filename = file.filename
48
- # attach.data = file.data
49
- # attach.insert
50
- # check = Attachment.find(@db, Issue.name, @issue.id)
51
- # expect(check).to_not eq(nil)
52
- # end
53
- #
54
- # it "should return nil if something is not found" do
55
- # expect(Attachment.find(@db, Issue.name, 123123123)).to eq(nil)
56
- # end
57
- # end
3
+ require_relative '../spec_helper.rb'
4
+ require_relative '../make_db'
5
+ require 'wlog/domain/attachment'
6
+ require 'wlog/domain/log_entry'
7
+ require 'wlog/domain/issue'
8
+ require 'zlib'
9
+
10
+ include Wlog
11
+
12
+ describe Attachment do
13
+
14
+ db_name = 'default'
15
+ db_path = standard_db_path(db_name)
16
+
17
+ before(:all) do
18
+ make_testing_db(db_name)
19
+ end
20
+
21
+ after(:all) do
22
+ close_testing_db
23
+ FileUtils.rm db_path
24
+ end
25
+
26
+ it 'should attach a mock file to an issue' do
27
+ @issue = Issue.create(:description => 'mydesc',
28
+ :long_description => 'potato')
29
+
30
+ # You're kind of forced to do this because I've hacked a shitty
31
+ # implementation of compressing - uncompressing strings automatically when
32
+ # attaching files.
33
+ @attachment = Attachment.new
34
+ @attachment.filename = 'filename'
35
+ @attachment.given_name = 'given name'
36
+ @attachment.data = 'data stuff'
37
+
38
+ @issue.attachments << @attachment
39
+ @issue.save
40
+
41
+ issue = Issue.find(@issue.id)
42
+ expect(issue.attachments.count).to eq(1)
43
+ expect(issue.attachments.first.filename).to eq('filename')
44
+ expect(issue.attachments.first.given_name).to eq('given name')
45
+ expect(issue.attachments.first.data).to eq('data stuff')
46
+ end
47
+
48
+ it "should return nil if something is not found" do
49
+ expect(Attachment.find_by_id(123123123)).to eq(nil)
50
+ end
51
+ end
58
52
  #
@@ -1,3 +1,4 @@
1
+ require_relative '../../spec_helper'
1
2
  require_relative '../../make_db'
2
3
  require 'wlog/domain/attachment'
3
4
  require 'wlog/domain/log_entry'
@@ -1,3 +1,4 @@
1
+ require_relative '../../spec_helper'
1
2
  require_relative '../../make_db'
2
3
  require 'wlog/domain/attachment'
3
4
  require 'wlog/domain/log_entry'
@@ -1,3 +1,4 @@
1
+ require_relative '../../spec_helper'
1
2
  require_relative '../../make_db'
2
3
  require 'wlog/domain/log_entry'
3
4
  require 'wlog/domain/issue'
@@ -0,0 +1,85 @@
1
+ require_relative '../spec_helper'
2
+
3
+ include Wlog
4
+
5
+ describe GitCommitParser do
6
+
7
+ GitLogSample = <<GITDATA
8
+ commit 19b5dd496ba2e4125c681b3c505f7631053a2fab
9
+ Author: psyomn <lethaljellybean@gmail.com>
10
+ Date: Wed Oct 23 23:00:56 2013 -0400
11
+
12
+ Tiny setup wizard for checking if ansi or not
13
+
14
+ Need to provide a system configuration service that takes into account things
15
+ that are the same for any running instance of the application (because others
16
+ might just be specific to project databases).
17
+
18
+ commit 533f1245a8e6d4382e250518d0a9ee4b19b7657d
19
+ Author: psyomn <lethaljellybean@gmail.com>
20
+ Date: Wed Oct 23 22:57:57 2013 -0400
21
+
22
+ Add taint setup command.
23
+
24
+ commit 4630d627b5b5f4f114e35991daea8684fca6ddd9
25
+ Author: psyomn <lethaljellybean@gmail.com>
26
+ Date: Wed Oct 23 22:46:27 2013 -0400
27
+
28
+ Add setup wizard.
29
+
30
+ GITDATA
31
+
32
+ Malformed = <<BADGIT
33
+ potato potato potato potato potato potato potato potato potato potato potato
34
+ potato potato potato potato potato potato potato potato potato potato potato potato
35
+ potato potato potato potato potato potato potato potato potato potato potato potato
36
+ potato potato potato potato potato potato potato potato potato potato potato potato
37
+ potato potato potato potato potato potato potato potato potato potato potato potato
38
+ BADGIT
39
+
40
+ it 'should return [] on null string' do
41
+ expect(GitCommitParser.parse('')).to eq([])
42
+ end
43
+
44
+ it 'should return [] on malformed format' do
45
+ expect(GitCommitParser.parse(Malformed)).to eq([])
46
+ end
47
+
48
+ it 'should return 3 commit logs' do
49
+ expect(GitCommitParser.parse(GitLogSample).count).to eq(3)
50
+ end
51
+
52
+ it 'should retrieve hashes' do
53
+ commits = GitCommitParser.parse(GitLogSample)
54
+ hashes = commits.collect &:commit
55
+ expected_hashes = [
56
+ '4630d627b5b5f4f114e35991daea8684fca6ddd9',
57
+ '533f1245a8e6d4382e250518d0a9ee4b19b7657d',
58
+ '19b5dd496ba2e4125c681b3c505f7631053a2fab']
59
+ expect(hashes.count).to eq(3)
60
+ expect((hashes & expected_hashes).count).to eq(3)
61
+ end
62
+
63
+ it 'should retrieve authors' do
64
+ commits = GitCommitParser.parse(GitLogSample)
65
+ authors = commits.collect &:author
66
+ expect(authors.count).to eq(3)
67
+ end
68
+
69
+ it 'should retrieve shortlogs' do
70
+ commits = GitCommitParser.parse(GitLogSample)
71
+ shortlogs = commits.collect &:shortlog
72
+ expect(shortlogs.count).to eq(3)
73
+ # all shortlogs contain text
74
+ expect(shortlogs.inject(true){ |sum,e| e != "" }).to be true
75
+ end
76
+
77
+ it 'should retrieve messages' do
78
+ commits = GitCommitParser.parse(GitLogSample)
79
+ messages = commits.collect &:message
80
+ messages.reject! { |e| e == "" }
81
+ expect(messages.count).to eq(1)
82
+ expect(messages.inject(true){ |e| e != "" }).to be true
83
+ end
84
+
85
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../make_db'
3
+
4
+ include Wlog
5
+
6
+ describe Invoice do
7
+ include DomainHelpers
8
+
9
+ db_name = 'default'
10
+ db_path = standard_db_path(db_name)
11
+
12
+ before :all do
13
+ make_testing_db(db_name)
14
+ end
15
+
16
+ after :all do
17
+ FileUtils.rm db_path
18
+ end
19
+
20
+ it 'should fetch all relevant log entries between two dates' do
21
+ invoice = Invoice.create(:from => (DateTime.now - 5), :to => (DateTime.now + 5))
22
+ issue = make_issue
23
+
24
+ 10.times do
25
+ le = make_log_entry
26
+ le.created_at = DateTime.now - 2
27
+ issue.log_entries << le
28
+ end
29
+ issue.save
30
+
31
+ expect(invoice.log_entries_within_dates.count).to eq(10)
32
+ end
33
+
34
+ end
35
+
@@ -1,3 +1,4 @@
1
+ require_relative '../spec_helper'
1
2
  require_relative '../make_db'
2
3
  require 'wlog/domain/issue'
3
4
 
@@ -1,3 +1,4 @@
1
+ require_relative '../spec_helper'
1
2
  require_relative '../make_db'
2
3
  require 'wlog/domain/key_value'
3
4
 
@@ -1,3 +1,4 @@
1
+ require_relative '../spec_helper'
1
2
  require_relative '../make_db'
2
3
  require 'wlog/domain/log_entry'
3
4
  require 'wlog/domain/issue'
@@ -1,3 +1,4 @@
1
+ require_relative '../spec_helper'
1
2
  require_relative '../make_db'
2
3
  require 'wlog/domain/sys_config'
3
4
 
@@ -0,0 +1,31 @@
1
+ require 'coveralls'
2
+ require 'date'
3
+ require 'wlog/domain/invoice'
4
+ require 'wlog/domain/issue'
5
+ require 'wlog/domain/log_entry'
6
+ require 'wlog/tech/git_commit_parser'
7
+
8
+ Coveralls.wear!
9
+
10
+ $sn = 0
11
+
12
+ module DomainHelpers
13
+ def sn
14
+ old = $sn
15
+ $sn += 1
16
+ old end
17
+
18
+ # Make a log entry but don't store it
19
+ def make_log_entry
20
+ le = LogEntry.new(:description => "Desc ##{sn}")
21
+ le end
22
+
23
+ def make_issue
24
+ is = Issue.new(:description => "Desc #{sn}",
25
+ :due_date => DateTime.now,
26
+ :status => 0,
27
+ :timelog => 10,
28
+ :long_description => "big desc #{sn}")
29
+ is end
30
+ end
31
+
data/wlog.gemspec CHANGED
@@ -26,7 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
28
28
  spec.add_development_dependency "yard"
29
+ spec.add_development_dependency "coveralls"
30
+ spec.add_development_dependency 'redcarpet'
31
+
29
32
  spec.add_runtime_dependency "sqlite3", ">= 1.3.7"
30
- spec.add_runtime_dependency "rake", ">= 10.3.2"
31
33
  spec.add_runtime_dependency 'activerecord', "4.1.6"
32
34
  end