ptimelog 0.10.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +43 -0
- data/README.md +177 -26
- data/docs/add-command.md +239 -0
- data/exe/ptimelog +26 -2
- data/lib/ptimelog/command/confirm.rb +88 -0
- data/lib/ptimelog/command/edit.rb +47 -7
- data/lib/ptimelog/command/info.rb +48 -0
- data/lib/ptimelog/command/show.rb +49 -29
- data/lib/ptimelog/command/summarize.rb +65 -0
- data/lib/ptimelog/command/upload.rb +55 -18
- data/lib/ptimelog/configuration.rb +13 -6
- data/lib/ptimelog/data_source.rb +43 -0
- data/lib/ptimelog/day.rb +8 -31
- data/lib/ptimelog/entry.rb +98 -23
- data/lib/ptimelog/error.rb +7 -0
- data/lib/ptimelog/joiner.rb +47 -0
- data/lib/ptimelog/month_not_supported.rb +15 -0
- data/lib/ptimelog/named_date.rb +39 -11
- data/lib/ptimelog/operon.rb +189 -0
- data/lib/ptimelog/script.rb +1 -1
- data/lib/ptimelog/timelog.rb +8 -3
- data/lib/ptimelog/version.rb +9 -1
- data/lib/ptimelog.rb +16 -6
- data/opencode.json +41 -0
- metadata +142 -48
- data/.envrc +0 -1
- data/.gitignore +0 -10
- data/.overcommit.yml +0 -26
- data/.rspec +0 -2
- data/.rubocop.yml +0 -42
- data/.rubocop_todo.yml +0 -16
- data/.ruby-version +0 -1
- data/.tool-versions +0 -1
- data/.travis.yml +0 -7
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/ptimelog/app.rb +0 -21
- data/lib/ptimelog/command/add.rb +0 -65
- data/lib/ptimelog/command/base.rb +0 -29
- data/lib/ptimelog/command/version.rb +0 -16
- data/ptimelog.gemspec +0 -40
data/lib/ptimelog/entry.rb
CHANGED
|
@@ -4,29 +4,43 @@ require 'time'
|
|
|
4
4
|
|
|
5
5
|
module Ptimelog
|
|
6
6
|
# Dataclass to wrap an entry
|
|
7
|
-
class Entry
|
|
7
|
+
class Entry # rubocop:disable Metrics/ClassLength
|
|
8
|
+
SEPARATOR = '|'
|
|
9
|
+
|
|
8
10
|
# define only trivial writers, omit special and derived values
|
|
9
11
|
attr_accessor :date, :ticket, :description
|
|
10
12
|
|
|
11
13
|
# allow to read everything else
|
|
12
|
-
attr_reader :start_time, :finish_time, :tags, :billable, :account
|
|
14
|
+
attr_reader :start_time, :finish_time, :tags, :billable, :account, :publishable
|
|
13
15
|
|
|
14
16
|
BILLABLE = 1
|
|
15
17
|
NON_BILLABLE = 0
|
|
16
18
|
|
|
19
|
+
class AdditionError < ::StandardError
|
|
20
|
+
end
|
|
21
|
+
|
|
17
22
|
def initialize(config = Configuration.instance)
|
|
18
23
|
@config = config
|
|
19
24
|
@script = Script.new(@config[:dir])
|
|
20
25
|
end
|
|
21
26
|
|
|
22
27
|
class << self
|
|
28
|
+
# TODO: this only covers one backend, move into timelog-class
|
|
23
29
|
def from_timelog(matched_line)
|
|
24
30
|
entry = new
|
|
25
31
|
entry.from_timelog(matched_line)
|
|
26
32
|
entry
|
|
27
33
|
end
|
|
34
|
+
|
|
35
|
+
def format_duration(seconds)
|
|
36
|
+
full_days, last_day = seconds.divmod(86_400)
|
|
37
|
+
hours, minutes = Time.at(last_day).utc.strftime('%H:%M').split(':')
|
|
38
|
+
|
|
39
|
+
format('%<hours>02d:%<minutes>s', hours: (full_days * 24) + hours.to_i, minutes: minutes)
|
|
40
|
+
end
|
|
28
41
|
end
|
|
29
42
|
|
|
43
|
+
# TODO: this only covers one backend, move into timelog-class
|
|
30
44
|
def from_timelog(matched_line)
|
|
31
45
|
self.date = matched_line[:date]
|
|
32
46
|
self.ticket = matched_line[:ticket]
|
|
@@ -37,6 +51,34 @@ module Ptimelog
|
|
|
37
51
|
infer_ptime_settings
|
|
38
52
|
end
|
|
39
53
|
|
|
54
|
+
def +(other) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
55
|
+
raise AdditionError, "Tickets don't match or empty" if @ticket != other.ticket || @ticket.to_s == ''
|
|
56
|
+
raise AdditionError, 'O RLY? Date is different' if @date != other.date
|
|
57
|
+
raise AdditionError, 'At least one is invalid' if [self, other].reject(&:valid?).any?
|
|
58
|
+
|
|
59
|
+
both_have_tags = [self, other].all? { |entry| !entry.tags.nil? }
|
|
60
|
+
raise AdditionError, 'Tags do not match' if both_have_tags && tag_list.sort != other.tag_list.sort
|
|
61
|
+
|
|
62
|
+
joined = self.class.new
|
|
63
|
+
joined.ticket = @ticket
|
|
64
|
+
joined.date = @date
|
|
65
|
+
joined.description = [@description, other.description].uniq.join(', ')
|
|
66
|
+
joined.tags = [tag_list, other.tag_list].uniq.join(' ')
|
|
67
|
+
|
|
68
|
+
joined.infer_ptime_settings
|
|
69
|
+
|
|
70
|
+
earlier, later = [self, other].sort
|
|
71
|
+
|
|
72
|
+
joined.start_time = earlier.start_time
|
|
73
|
+
joined.finish_time = if earlier.finish_time == later.start_time
|
|
74
|
+
later.finish_time
|
|
75
|
+
else
|
|
76
|
+
(Time.parse(earlier.finish_time) + later.duration).strftime('%H:%M')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
joined
|
|
80
|
+
end
|
|
81
|
+
|
|
40
82
|
def start_time=(time)
|
|
41
83
|
@start_time = round_time(time, @config[:rounding])
|
|
42
84
|
end
|
|
@@ -46,56 +88,85 @@ module Ptimelog
|
|
|
46
88
|
end
|
|
47
89
|
|
|
48
90
|
def tags=(tags)
|
|
91
|
+
raise 'HELL' unless tags.is_a?(String) || tags.nil?
|
|
92
|
+
|
|
49
93
|
@tags = case tags
|
|
50
94
|
when '', nil then nil
|
|
51
95
|
else tags.split.compact
|
|
52
96
|
end
|
|
53
97
|
end
|
|
54
98
|
|
|
55
|
-
def valid?
|
|
56
|
-
@start_time && duration.positive? && !hidden?
|
|
57
|
-
end
|
|
99
|
+
def valid? = @start_time && duration.positive? && !hidden?
|
|
58
100
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
end
|
|
101
|
+
# hide lunch and breaks
|
|
102
|
+
def hidden? = @description.to_s.end_with?('**') || !publishable?
|
|
62
103
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
104
|
+
# filter all mentioned tags
|
|
105
|
+
def tagged_with?(wanted) = wanted.all? { |tag| tag_list.include?(tag) }
|
|
106
|
+
|
|
107
|
+
def billable? = @billable == BILLABLE
|
|
108
|
+
|
|
109
|
+
def publishable? = @publishable != false
|
|
66
110
|
|
|
67
111
|
def infer_ptime_settings
|
|
68
112
|
return if hidden?
|
|
69
113
|
return unless @script.inferer(script_name).exist?
|
|
70
114
|
|
|
71
|
-
@account, @billable =
|
|
115
|
+
@account, @billable, @publishable = infer_entry_attributes
|
|
72
116
|
end
|
|
73
117
|
|
|
74
118
|
def duration
|
|
75
119
|
(Time.parse(@finish_time) - Time.parse(@start_time)).to_i
|
|
76
120
|
end
|
|
77
121
|
|
|
78
|
-
def
|
|
122
|
+
def duration_hours
|
|
123
|
+
format('%.02f', duration / 3600.0)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def label
|
|
79
127
|
billable = billable? ? '($)' : nil
|
|
80
|
-
tag_list = Array(@tags).compact
|
|
81
128
|
|
|
82
129
|
tags = tag_list.join(' ') if tag_list.any?
|
|
83
130
|
desc = [@ticket, @description].compact.join(': ')
|
|
84
131
|
acc = [@account, billable].compact.join(' ') if @account
|
|
85
132
|
|
|
133
|
+
[desc, tags, acc].compact.join(" #{SEPARATOR} ")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def to_s
|
|
86
137
|
[
|
|
87
|
-
@start_time, '-', @finish_time,
|
|
88
|
-
|
|
138
|
+
@start_time, '-', @finish_time, SEPARATOR,
|
|
139
|
+
"#{duration_hours}h", SEPARATOR,
|
|
140
|
+
label,
|
|
89
141
|
].compact.join(' ')
|
|
90
142
|
end
|
|
91
143
|
|
|
92
|
-
|
|
144
|
+
def <=>(other)
|
|
145
|
+
@start_time <=> other.start_time
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def ==(other)
|
|
149
|
+
comparable_attrs = %i[date ticket description start_time finish_time tags]
|
|
150
|
+
|
|
151
|
+
self.class == other.class &&
|
|
152
|
+
comparable_attrs.map { |attr| send(attr) == other.send(attr) }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
protected
|
|
156
|
+
|
|
157
|
+
def tag_list
|
|
158
|
+
list = [first_tag] + tail_tags.split
|
|
159
|
+
list.reject(&:empty?).compact
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def first_tag = @tags.to_a.first.to_s
|
|
163
|
+
def tail_tags = @tags.to_a[1..].to_a.join(' ')
|
|
93
164
|
|
|
94
165
|
private
|
|
95
166
|
|
|
96
167
|
def round_time(time, interval)
|
|
97
168
|
return time unless interval
|
|
98
|
-
return unless
|
|
169
|
+
return unless /\d\d:\d\d/.match?(time.to_s)
|
|
99
170
|
|
|
100
171
|
hour, minute = time.split(':')
|
|
101
172
|
minute = (minute.to_i / interval.to_f).round * interval.to_i
|
|
@@ -108,21 +179,25 @@ module Ptimelog
|
|
|
108
179
|
end
|
|
109
180
|
|
|
110
181
|
def script_name
|
|
111
|
-
@script_name ||=
|
|
182
|
+
@script_name ||= first_tag
|
|
112
183
|
end
|
|
113
184
|
|
|
114
185
|
def script_args
|
|
115
|
-
@script_args ||=
|
|
186
|
+
@script_args ||= tail_tags.split.map(&:inspect).join(' ')
|
|
116
187
|
end
|
|
117
188
|
|
|
118
|
-
def
|
|
189
|
+
def infer_entry_attributes
|
|
119
190
|
script = @script.inferer(script_name)
|
|
120
191
|
|
|
121
192
|
cmd = %(#{script} "#{@ticket}" "#{@description}" #{script_args})
|
|
193
|
+
@inferer_cmd = cmd
|
|
122
194
|
|
|
123
|
-
|
|
195
|
+
results = `#{cmd}`.chomp.split
|
|
196
|
+
account = results[0]
|
|
197
|
+
billable = ((results[1] || 'false').to_s == 'true' ? BILLABLE : NON_BILLABLE)
|
|
198
|
+
publishable = ((results[2] || 'true').to_s == 'true')
|
|
124
199
|
|
|
125
|
-
[account,
|
|
200
|
+
[account, billable, publishable]
|
|
126
201
|
end
|
|
127
202
|
end
|
|
128
203
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ptimelog
|
|
4
|
+
# Join two directly adjacent entries or adjacent entries with the same ticket
|
|
5
|
+
class Joiner
|
|
6
|
+
def initialize(compact_on_ticket_only: false)
|
|
7
|
+
@compact_on_ticket_only = compact_on_ticket_only
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def join_similar(list)
|
|
11
|
+
return [] if list.empty?
|
|
12
|
+
return list if list.one?
|
|
13
|
+
|
|
14
|
+
one, *tail = list
|
|
15
|
+
two, *rest = tail
|
|
16
|
+
|
|
17
|
+
joined = maybe_join(one, two)
|
|
18
|
+
|
|
19
|
+
if joined.one?
|
|
20
|
+
join_similar(joined + rest)
|
|
21
|
+
else
|
|
22
|
+
[one] + join_similar(tail)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def maybe_join(one, two)
|
|
29
|
+
return [one, two] if one.ticket != two.ticket || one.ticket.to_s == ''
|
|
30
|
+
return [one, two] if tags_are_present_but_differ(one, two)
|
|
31
|
+
|
|
32
|
+
if @compact_on_ticket_only ||
|
|
33
|
+
(one.description == two.description && one.finish_time == two.start_time)
|
|
34
|
+
[one + two]
|
|
35
|
+
else
|
|
36
|
+
[one, two]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def tags_are_present_but_differ(one, two)
|
|
41
|
+
both_have_tags = [one, two].all? { |entry| !entry.tags.nil? }
|
|
42
|
+
tags_differ = (one.tags.sort != two.tags.sort)
|
|
43
|
+
|
|
44
|
+
both_have_tags && tags_differ
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ptimelog
|
|
4
|
+
# A month resolves to a range, which NamedDate would turn into :all further down
|
|
5
|
+
class MonthNotSupported < Ptimelog::Error
|
|
6
|
+
def initialize(day)
|
|
7
|
+
super(<<~MSG)
|
|
8
|
+
The timelog-datasource cannot show a whole month (#{day}).
|
|
9
|
+
|
|
10
|
+
Please request a single day, e.g. 'ptimelog show #{day.first}'
|
|
11
|
+
or just everything with 'ptimelog show all'
|
|
12
|
+
MSG
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/ptimelog/named_date.rb
CHANGED
|
@@ -9,31 +9,59 @@ module Ptimelog
|
|
|
9
9
|
named_date(arg) || :all
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def named_date(date) # rubocop:disable Metrics/CyclomaticComplexity
|
|
12
|
+
def named_date(date) # rubocop:disable Metrics/CyclomaticComplexity
|
|
13
13
|
case date.to_s
|
|
14
14
|
when 'yesterday' then yesterday
|
|
15
15
|
when 'today' then Date.today.to_s
|
|
16
|
-
when 'last', '' then last_entry
|
|
17
|
-
when '
|
|
18
|
-
when
|
|
19
|
-
when 'wed', 'wednesday' then previous_weekday('wednesday')
|
|
20
|
-
when 'thu', 'thursday' then previous_weekday('thursday')
|
|
21
|
-
when 'fri', 'friday' then previous_weekday('friday')
|
|
22
|
-
when 'sat', 'saturday' then previous_weekday('saturday')
|
|
23
|
-
when 'sun', 'sunday' then previous_weekday('sunday')
|
|
16
|
+
when 'last', '' then (last_entry || yesterday).to_s
|
|
17
|
+
when 'month' then month(Date.today.year, Date.today.month)
|
|
18
|
+
when /\A[a-z]{3,9}\z/ then weekday_or_month(date.to_s)
|
|
24
19
|
when /\d{4}(-\d{2}){2}/ then date.to_s
|
|
25
20
|
end
|
|
26
21
|
end
|
|
27
22
|
|
|
23
|
+
# for now, every range we build is a month, so we cheat a little.
|
|
24
|
+
def title(date)
|
|
25
|
+
if date.is_a?(Range)
|
|
26
|
+
Date.parse(date.first).strftime('%B %Y')
|
|
27
|
+
else
|
|
28
|
+
date.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
private
|
|
29
33
|
|
|
30
|
-
def
|
|
34
|
+
def weekday_or_month(name)
|
|
35
|
+
if (valid_weekday = index_of(name, Date::DAYNAMES, Date::ABBR_DAYNAMES))
|
|
36
|
+
previous_weekday(valid_weekday)
|
|
37
|
+
elsif (valid_month = index_of(name, Date::MONTHNAMES, Date::ABBR_MONTHNAMES))
|
|
38
|
+
previous_month(valid_month)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def index_of(name, names, abbreviated_names)
|
|
43
|
+
names.index(name.capitalize) || abbreviated_names.index(name.capitalize)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def previous_weekday(wday)
|
|
31
47
|
Date.today.prev_day(7)
|
|
32
48
|
.step(Date.today.prev_day)
|
|
33
|
-
.find { |
|
|
49
|
+
.find { |date| date.wday == wday }
|
|
34
50
|
.to_s
|
|
35
51
|
end
|
|
36
52
|
|
|
53
|
+
def previous_month(number)
|
|
54
|
+
return unless number
|
|
55
|
+
|
|
56
|
+
year = Date.today.year - (number >= Date.today.month ? 1 : 0)
|
|
57
|
+
|
|
58
|
+
month(year, number)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def month(year, month)
|
|
62
|
+
(Date.new(year, month, 1).to_s..Date.new(year, month, -1).to_s)
|
|
63
|
+
end
|
|
64
|
+
|
|
37
65
|
def last_entry
|
|
38
66
|
timelog.to_h.keys.compact.sort[-2]
|
|
39
67
|
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'date'
|
|
4
|
+
require 'time'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
module Ptimelog
|
|
8
|
+
# Extract entries from the time-sessions Operon tracks on its tasks
|
|
9
|
+
class Operon # rubocop:disable Metrics/ClassLength
|
|
10
|
+
# Operon documents its own task-syntax as examples, and the archive is history
|
|
11
|
+
SKIP_PATHS = ['Operon/Docs', 'archive'].freeze
|
|
12
|
+
|
|
13
|
+
FIELD_RE = /\{\{(\w+)::\s*(.*?)\}\}/
|
|
14
|
+
TASK_RE = /^\s*-\s\[( |x|X)\]\s/
|
|
15
|
+
RANGE_RE = %r{
|
|
16
|
+
\A(?<start>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?)/
|
|
17
|
+
(?<stop>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?)\z
|
|
18
|
+
}x
|
|
19
|
+
|
|
20
|
+
# A config naming only one key must not lose the other
|
|
21
|
+
# TODO: determine if this can be done in the Ptimelog::Configuration
|
|
22
|
+
def self.custom_keys
|
|
23
|
+
Ptimelog::Configuration::CONFIGURATION_DEFAULTS['operon_custom_keys']
|
|
24
|
+
.merge(Ptimelog::Configuration.instance['operon_custom_keys'].to_h)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def initialize(day)
|
|
28
|
+
@day = day
|
|
29
|
+
@configuration = Ptimelog::Configuration.instance
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# A missing vault would silently look like a day without any tracked time
|
|
33
|
+
class VaultNotFound < Ptimelog::Error
|
|
34
|
+
def initialize(path)
|
|
35
|
+
super(<<~MSG)
|
|
36
|
+
Could not find your Obsidian vault at #{path}
|
|
37
|
+
|
|
38
|
+
Please check 'obsidian_vault' in your ptimelog-config. It should
|
|
39
|
+
point to the folder which contains your '.obsidian'-directory.
|
|
40
|
+
MSG
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# A session belongs to the day it started on. Plans and running timers are no time yet
|
|
45
|
+
def entries
|
|
46
|
+
tasks.flat_map { |task| entries_of(task) }
|
|
47
|
+
.sort_by { |entry| [entry.date, entry.start_time] }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# What a new entry would continue from: a running timer, the last session, the start of the day
|
|
51
|
+
# shortcut: only meaningful for a single day, guard when a caller may pass a range
|
|
52
|
+
def previous_entry
|
|
53
|
+
start = running_timer || entries.last&.finish_time || @configuration['operon_start_time'] || '08:00'
|
|
54
|
+
|
|
55
|
+
Ptimelog::Entry.new.tap do |entry|
|
|
56
|
+
entry.date = @day
|
|
57
|
+
entry.description = 'start **'
|
|
58
|
+
entry.start_time = start
|
|
59
|
+
entry.finish_time = start
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# An entry can come from any note of the vault, so there is no one file to point at
|
|
64
|
+
def file = NullPathname.new
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def vault
|
|
69
|
+
@vault ||= begin
|
|
70
|
+
path = @configuration['obsidian_vault']
|
|
71
|
+
raise VaultNotFound, path unless File.directory?(path)
|
|
72
|
+
|
|
73
|
+
path
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def markdown_files
|
|
78
|
+
Dir.glob(vault.join('**/*.md')).reject { |fn| ignored?(fn) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def ignored?(fn)
|
|
82
|
+
relative = fn.delete_prefix("#{vault}/")
|
|
83
|
+
|
|
84
|
+
SKIP_PATHS.any? { |path| relative.start_with?("#{path}/") }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Every task of the vault, an inline one on its line, a file task in its frontmatter
|
|
88
|
+
def tasks
|
|
89
|
+
@tasks ||= markdown_files.flat_map do |fn|
|
|
90
|
+
frontmatter, body = split_frontmatter(File.read(fn, encoding: 'UTF-8'))
|
|
91
|
+
|
|
92
|
+
file_tasks(frontmatter, fn) + inline_tasks(body)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def file_tasks(frontmatter, fn)
|
|
97
|
+
return [] unless frontmatter.is_a?(Hash)
|
|
98
|
+
|
|
99
|
+
[{ fields: frontmatter, description: File.basename(fn, '.md') }]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def inline_tasks(body)
|
|
103
|
+
body.each_line.filter_map do |line|
|
|
104
|
+
next unless line.match?(TASK_RE)
|
|
105
|
+
|
|
106
|
+
{ fields: fields_of(line), description: description_of(line) }
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def fields_of(line) = line.scan(FIELD_RE).to_h.transform_values(&:strip)
|
|
111
|
+
|
|
112
|
+
def description_of(line)
|
|
113
|
+
line.sub(TASK_RE, '').sub(/\s*\{\{.*\}\}\s*\z/m, '').strip
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# A file task keeps its fields in frontmatter, an inline task carries them on its line
|
|
117
|
+
def split_frontmatter(text)
|
|
118
|
+
return [nil, text] unless text.start_with?('---')
|
|
119
|
+
|
|
120
|
+
close = text.index("\n---", 3)
|
|
121
|
+
return [nil, text] unless close
|
|
122
|
+
|
|
123
|
+
[YAML.safe_load(text[4...close], permitted_classes: [Date, Time], aliases: true), text[(close + 4)..]]
|
|
124
|
+
rescue Psych::Exception
|
|
125
|
+
[nil, text]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def entries_of(task)
|
|
129
|
+
session_list(task[:fields]['trackers']).filter_map do |session|
|
|
130
|
+
next unless on_day?(session[:start])
|
|
131
|
+
|
|
132
|
+
entry_for(session, task)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Malformed ranges are dropped, one broken note must not sink a whole day
|
|
137
|
+
def session_list(sessions)
|
|
138
|
+
list = sessions.is_a?(String) ? sessions.split('; ') : Array(sessions)
|
|
139
|
+
|
|
140
|
+
list.filter_map { |session| RANGE_RE.match(session.to_s.strip) }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# A running timer is no session yet, but it says where the work stopped
|
|
144
|
+
def running_timer
|
|
145
|
+
started = tasks.filter_map { |task| task[:fields]['activeTracker'] }.find { |at| on_day?(at) }
|
|
146
|
+
|
|
147
|
+
started && Time.parse(started).strftime('%R')
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# @day is a single date or a range of them, a whole month
|
|
151
|
+
def on_day?(datetime)
|
|
152
|
+
day = Time.parse(datetime).strftime('%F')
|
|
153
|
+
|
|
154
|
+
@day.is_a?(Range) ? @day.cover?(day) : @day == day
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def entry_for(session, task) # rubocop:disable Metrics/AbcSize
|
|
158
|
+
fields = task[:fields]
|
|
159
|
+
start = Time.parse(session[:start])
|
|
160
|
+
|
|
161
|
+
Ptimelog::Entry.new.tap do |entry|
|
|
162
|
+
entry.date = start.strftime('%F')
|
|
163
|
+
entry.ticket = field(fields, 'ticket')
|
|
164
|
+
entry.description = task[:description]
|
|
165
|
+
entry.tags = field(fields, 'inferer')
|
|
166
|
+
entry.start_time = start.strftime('%R')
|
|
167
|
+
entry.finish_time = Time.parse(session[:stop]).strftime('%R')
|
|
168
|
+
|
|
169
|
+
entry.infer_ptime_settings
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# A subtask only carries what differs from its parent, ticket and tags stay up there
|
|
174
|
+
def field(fields, name, seen = [])
|
|
175
|
+
return if seen.include?(fields) # a hand-edited note can make two tasks each others parent
|
|
176
|
+
|
|
177
|
+
parent = tasks_by_id[fields['parentTask']]
|
|
178
|
+
|
|
179
|
+
fields[custom_key(name)] || (parent && field(parent, name, seen << fields))
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# A task without an operonId can be tracked, but never be a parent
|
|
183
|
+
def tasks_by_id
|
|
184
|
+
@tasks_by_id ||= tasks.to_h { |task| [task[:fields]['operonId'], task[:fields]] }.except(nil)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def custom_key(name) = self.class.custom_keys.fetch(name)
|
|
188
|
+
end
|
|
189
|
+
end
|
data/lib/ptimelog/script.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Ptimelog
|
|
|
10
10
|
|
|
11
11
|
def inferer(name)
|
|
12
12
|
return NullPathname.new if name.to_s.empty?
|
|
13
|
-
raise if
|
|
13
|
+
raise if %r{[\\/]}.match?(name) # prevent relavtive paths, stupidly, FIXME: really check FS
|
|
14
14
|
|
|
15
15
|
@config_dir.join('inferers').join(name).expand_path
|
|
16
16
|
end
|
data/lib/ptimelog/timelog.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'singleton'
|
|
3
4
|
require 'pathname'
|
|
4
5
|
|
|
5
6
|
module Ptimelog
|
|
@@ -13,12 +14,16 @@ module Ptimelog
|
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def timelog_txt
|
|
16
|
-
Pathname.new(Configuration.instance[:
|
|
17
|
+
Pathname.new(Configuration.instance[:timelog_txt]).expand_path
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def previous_entry
|
|
20
|
-
lines = timelog_txt.readlines.last(
|
|
21
|
-
|
|
21
|
+
lines = timelog_txt.readlines.last(10)
|
|
22
|
+
|
|
23
|
+
last_line = lines.map(&:chomp).delete_if do |line|
|
|
24
|
+
line.empty? || line.end_with?('**')
|
|
25
|
+
end.last
|
|
26
|
+
|
|
22
27
|
last_entry = instance.tokenize(last_line)
|
|
23
28
|
|
|
24
29
|
Entry.from_timelog(last_entry)
|
data/lib/ptimelog/version.rb
CHANGED
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
# any remaining questions, please open an issue or even better a pull-request
|
|
16
16
|
# with an improvement. Keep in mind that this is also covered by rspec so I
|
|
17
17
|
# expect (pun intended) 100% test-coverage for any additional code.
|
|
18
|
+
#
|
|
19
|
+
# Without much preparation came the addition of cmdparse to this gem. While
|
|
20
|
+
# adding it, it became apparent that a duplication between the gemspec and the
|
|
21
|
+
# main executable may exist. In order to avoid this dreadfully duplicated
|
|
22
|
+
# description, a constant for this has been added to this module. So, the
|
|
23
|
+
# correct subtitle of this documentation-block would be "and a Banner not named
|
|
24
|
+
# Bruce."
|
|
18
25
|
module Ptimelog
|
|
19
|
-
VERSION = '0.
|
|
26
|
+
VERSION = '0.13.0'
|
|
27
|
+
BANNER = 'Move time-entries from gTimelog or Obsidian to PuzzleTime'
|
|
20
28
|
end
|
data/lib/ptimelog.rb
CHANGED
|
@@ -4,24 +4,34 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
|
|
|
4
4
|
|
|
5
5
|
# Autoloading and such
|
|
6
6
|
module Ptimelog
|
|
7
|
-
autoload :App, 'ptimelog/app'
|
|
8
7
|
autoload :Configuration, 'ptimelog/configuration'
|
|
9
|
-
autoload :
|
|
8
|
+
autoload :DataSource, 'ptimelog/data_source'
|
|
10
9
|
autoload :DeprecationWarning, 'ptimelog/deprecation_warning'
|
|
11
10
|
autoload :Entry, 'ptimelog/entry'
|
|
11
|
+
autoload :Error, 'ptimelog/error'
|
|
12
|
+
autoload :Joiner, 'ptimelog/joiner'
|
|
12
13
|
autoload :NamedDate, 'ptimelog/named_date'
|
|
13
14
|
autoload :NullPathname, 'ptimelog/null_pathname'
|
|
14
15
|
autoload :Script, 'ptimelog/script'
|
|
15
|
-
autoload :Timelog, 'ptimelog/timelog'
|
|
16
16
|
autoload :VERSION, 'ptimelog/version'
|
|
17
17
|
|
|
18
|
+
# datasources
|
|
19
|
+
|
|
20
|
+
# obsidian
|
|
21
|
+
autoload :Operon, 'ptimelog/operon'
|
|
22
|
+
|
|
23
|
+
# timelog.txt
|
|
24
|
+
autoload :Day, 'ptimelog/day'
|
|
25
|
+
autoload :Timelog, 'ptimelog/timelog'
|
|
26
|
+
autoload :MonthNotSupported, 'ptimelog/month_not_supported'
|
|
27
|
+
|
|
18
28
|
# Collection of commands available at the CLI
|
|
19
29
|
module Command
|
|
20
|
-
autoload :
|
|
21
|
-
autoload :Base, 'ptimelog/command/base'
|
|
30
|
+
autoload :Confirm, 'ptimelog/command/confirm'
|
|
22
31
|
autoload :Edit, 'ptimelog/command/edit'
|
|
32
|
+
autoload :Info, 'ptimelog/command/info'
|
|
23
33
|
autoload :Show, 'ptimelog/command/show'
|
|
34
|
+
autoload :Summarize, 'ptimelog/command/summarize'
|
|
24
35
|
autoload :Upload, 'ptimelog/command/upload'
|
|
25
|
-
autoload :Version, 'ptimelog/command/version'
|
|
26
36
|
end
|
|
27
37
|
end
|
data/opencode.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://opencode.ai/config.json",
|
|
3
|
+
"agent": {
|
|
4
|
+
"researcher": {
|
|
5
|
+
"permission": {
|
|
6
|
+
"edit": "deny",
|
|
7
|
+
"skill": "deny",
|
|
8
|
+
"question": "allow",
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"assistant": {
|
|
12
|
+
"permission": {
|
|
13
|
+
"bash": {
|
|
14
|
+
"*": "ask",
|
|
15
|
+
"bundle exec rspec*": "allow",
|
|
16
|
+
"bundle exec rubocop*": "allow",
|
|
17
|
+
"bundle exec rake*": "allow",
|
|
18
|
+
"rspec*": "allow",
|
|
19
|
+
"rubocop*": "allow",
|
|
20
|
+
"rake*": "allow",
|
|
21
|
+
"git status*": "allow",
|
|
22
|
+
"git diff*": "allow",
|
|
23
|
+
"git log*": "allow",
|
|
24
|
+
"git show*": "allow",
|
|
25
|
+
"git add --intent-to-add*": "allow",
|
|
26
|
+
"git add*": "ask",
|
|
27
|
+
"git commit*": "ask",
|
|
28
|
+
"git push*": "deny",
|
|
29
|
+
"cat*": "allow",
|
|
30
|
+
"echo*": "allow",
|
|
31
|
+
"grep*": "allow",
|
|
32
|
+
"head *": "allow",
|
|
33
|
+
"ls*": "allow",
|
|
34
|
+
"pwd": "allow",
|
|
35
|
+
"tail *": "allow"
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|