task_report 0.5.3 → 0.6.3
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/README.md +2 -1
- data/VERSION +1 -1
- data/bin/task +34 -3
- data/lib/task_report/gist.rb +26 -4
- data/lib/task_report/report.rb +28 -25
- data/lib/task_report.rb +60 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c892838becbaf46a4fd36fad5567a8da474a936
|
4
|
+
data.tar.gz: 4d7756be9e805d934214c3d484e6436d9bc1c0d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6881843d91884e65f38bfcdf23d40319ade48de0d69a37064284275aa24bc26124379182150a55ad78ea617e340b0057e172a3a16370f2b3058ebc24c3ce2c4
|
7
|
+
data.tar.gz: 1f1dc6f2313e311f2e022b3c844c851dc7d6d2643b949d542924a8c4e87a33bae8fa53a1a3a3bf56b893706164be8722e87e8203085bb0cb9aa7bc648ba55231
|
data/README.md
CHANGED
@@ -40,10 +40,11 @@ Use `task` as follows:
|
|
40
40
|
`task list`
|
41
41
|
- Lists all of today's tasks
|
42
42
|
|
43
|
-
`task summary [--gist, -g]`
|
43
|
+
`task summary [--gist, -g] [{--from, -f} YYYY-MM-DD {--until, -u} YYYY-MM-DD]`
|
44
44
|
- prints a task summary to the command line
|
45
45
|
- if the `--gist` or `-g` options are used, creates a markdown gist summary
|
46
46
|
and prints the link to stdout
|
47
|
+
- if `--from` and `--until` options are passed, then a gist will be made including any tracked time between the two dates
|
47
48
|
|
48
49
|
`task delete {TASK-ID, TASK-DESCRIPTION, today, gist}`
|
49
50
|
- deletes the provided task if it exists
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.3
|
data/bin/task
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'task_report'
|
4
4
|
|
5
|
-
def show_usage_message(exit_status = 0)
|
5
|
+
def show_usage_message(additional_message = nil, exit_status = 0)
|
6
|
+
if additional_message
|
7
|
+
puts additional_message
|
8
|
+
puts ''
|
9
|
+
end
|
10
|
+
|
6
11
|
puts \
|
7
12
|
"Use `task` as follows:
|
8
13
|
|
@@ -22,10 +27,11 @@ def show_usage_message(exit_status = 0)
|
|
22
27
|
`task list`
|
23
28
|
- Lists all of today's tasks
|
24
29
|
|
25
|
-
`task summary [--gist, -g]`
|
30
|
+
`task summary [--gist, -g] [{--from, -f} YYYY-MM-DD {--until, -u} YYYY-MM-DD]`
|
26
31
|
- prints a task summary to the command line
|
27
32
|
- if the `--gist` or `-g` options are used, creates a markdown gist summary
|
28
33
|
and prints the link to stdout
|
34
|
+
- if `--from` and `--until` options are passed, then a gist will be made including any tracked time between the two dates
|
29
35
|
|
30
36
|
`task delete {TASK-ID, TASK-DESCRIPTION, today, gist}`
|
31
37
|
- deletes the provided task if it exists
|
@@ -45,6 +51,31 @@ def show_usage_message(exit_status = 0)
|
|
45
51
|
exit exit_status
|
46
52
|
end
|
47
53
|
|
54
|
+
def parse_summary_args
|
55
|
+
gist = from = to = nil
|
56
|
+
|
57
|
+
ARGV.each_with_index do |arg, i|
|
58
|
+
case arg
|
59
|
+
when '--gist', '-g'
|
60
|
+
gist = true
|
61
|
+
when '--from', '-f'
|
62
|
+
if ARGV[i+1] =~ /\d{4}-\d{2}-\d{2}/ # must be a date
|
63
|
+
from = ARGV[i+1]
|
64
|
+
else
|
65
|
+
show_usage_message('summary date arguments must have the format: YYYY-MM-DD')
|
66
|
+
end
|
67
|
+
when '--until', '-u'
|
68
|
+
if ARGV[i+1] =~ /\d{4}-\d{2}-\d{2}/ # must be a date
|
69
|
+
to = ARGV[i+1]
|
70
|
+
else
|
71
|
+
show_usage_message('summary date arguments must have the format: YYYY-MM-DD')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
[gist, from, to]
|
77
|
+
end
|
78
|
+
|
48
79
|
TaskReport.read_config
|
49
80
|
|
50
81
|
case ARGV[0]
|
@@ -61,7 +92,7 @@ when 'delete'
|
|
61
92
|
when 'current'
|
62
93
|
TaskReport.current
|
63
94
|
when 'summary'
|
64
|
-
TaskReport.summary(
|
95
|
+
TaskReport.summary(*parse_summary_args)
|
65
96
|
when 'note'
|
66
97
|
TaskReport.note(ARGV[1], ARGV[2])
|
67
98
|
when 'total'
|
data/lib/task_report/gist.rb
CHANGED
@@ -6,16 +6,26 @@ module TaskReport
|
|
6
6
|
module Gist
|
7
7
|
class << self
|
8
8
|
def find_gist_from_today_by_description(description)
|
9
|
-
|
9
|
+
get_gists_for_user.find do |gist|
|
10
10
|
gist['description'] == description
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def find_gists_by_descriptions(descriptions, from = Time.now)
|
15
|
+
get_gists_for_user(from).select do |gist|
|
16
|
+
descriptions.include? gist['description']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_gists_by_description(description, from = Time.now)
|
21
|
+
get_gists_for_user(from).find do |gist|
|
22
|
+
description == gist['description']
|
23
|
+
end
|
24
|
+
end
|
16
25
|
|
26
|
+
def get_gists_for_user(from = Time.now)
|
17
27
|
# kind of like Time.now.midnight in UTC
|
18
|
-
time_string = Time.new(
|
28
|
+
time_string = Time.new(from.year, from.month, from.day).getgm.strftime('%Y-%m-%dT%H:%M:%SZ')
|
19
29
|
|
20
30
|
params = {
|
21
31
|
access_token: User.api_token,
|
@@ -76,6 +86,18 @@ module TaskReport
|
|
76
86
|
response = http.request(request)
|
77
87
|
JSON.parse(response.body)
|
78
88
|
end
|
89
|
+
|
90
|
+
def create_or_update(params, from)
|
91
|
+
description = params[:description]
|
92
|
+
found = find_gists_by_description(from)
|
93
|
+
|
94
|
+
if found
|
95
|
+
edit(found['id'], params)
|
96
|
+
return found
|
97
|
+
end
|
98
|
+
|
99
|
+
create(params)
|
100
|
+
end
|
79
101
|
end
|
80
102
|
end
|
81
103
|
end
|
data/lib/task_report/report.rb
CHANGED
@@ -8,12 +8,12 @@ module TaskReport
|
|
8
8
|
attr_reader :gist_id
|
9
9
|
|
10
10
|
class << self
|
11
|
-
def gist_description
|
12
|
-
"#{User.name}_report_#{
|
11
|
+
def gist_description(time = Time.now)
|
12
|
+
"#{User.name}_report_#{time.strftime('%Y-%m-%d')}"
|
13
13
|
end
|
14
14
|
|
15
|
-
def json_file_name
|
16
|
-
"#{gist_description}.json"
|
15
|
+
def json_file_name(description = nil)
|
16
|
+
"#{description || gist_description}.json"
|
17
17
|
end
|
18
18
|
|
19
19
|
def create(new_task_description:)
|
@@ -24,10 +24,11 @@ module TaskReport
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def create_from_gist(gist)
|
27
|
-
|
27
|
+
description = gist['description'] || gist_description
|
28
|
+
raw_url = gist['files'][json_file_name(description)]['raw_url']
|
28
29
|
|
29
30
|
Report.new(
|
30
|
-
description:
|
31
|
+
description: description,
|
31
32
|
json_file_name: json_file_name,
|
32
33
|
gist_id: gist['id'],
|
33
34
|
gist_html_url: gist['html_url'],
|
@@ -117,8 +118,10 @@ module TaskReport
|
|
117
118
|
puts " - #{note}"
|
118
119
|
end
|
119
120
|
|
120
|
-
puts "\
|
121
|
+
puts "\n"
|
121
122
|
end
|
123
|
+
|
124
|
+
puts "Total time tracked: #{total_duration.to_s}\n\n"
|
122
125
|
end
|
123
126
|
|
124
127
|
def gist_summary
|
@@ -161,6 +164,24 @@ module TaskReport
|
|
161
164
|
puts total_duration.to_s
|
162
165
|
end
|
163
166
|
|
167
|
+
def gist_summary_content
|
168
|
+
lines = ["## #{User.name} Task Report #{@date.strftime('%Y-%m-%d')}", '']
|
169
|
+
|
170
|
+
@tasks.each do |task|
|
171
|
+
lines << "- '#{task.description}'"
|
172
|
+
lines << " - #{task.duration.to_s}"
|
173
|
+
|
174
|
+
task.notes.each do |note|
|
175
|
+
lines << " - #{note}"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
lines << ''
|
180
|
+
lines << "#### Total time tracked: #{total_duration.to_s}"
|
181
|
+
|
182
|
+
lines.join("\n")
|
183
|
+
end
|
184
|
+
|
164
185
|
private
|
165
186
|
def initialize(description:, json_file_name:, gist_id: nil, gist_html_url: nil, existing_json_content: {})
|
166
187
|
@description = description
|
@@ -239,24 +260,6 @@ module TaskReport
|
|
239
260
|
raise MultipleOngoingTasks if @tasks.count(&:ongoing?) > 1
|
240
261
|
end
|
241
262
|
|
242
|
-
def gist_summary_content
|
243
|
-
lines = ["## #{User.name} Task Report #{@date.strftime('%Y-%m-%d')}", '']
|
244
|
-
|
245
|
-
@tasks.each do |task|
|
246
|
-
lines << "- '#{task.description}'"
|
247
|
-
lines << " - #{task.duration.to_s}"
|
248
|
-
|
249
|
-
task.notes.each do |note|
|
250
|
-
lines << " - #{note}"
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
lines << ''
|
255
|
-
lines << "#### Total time tracked: #{total_duration.to_s}"
|
256
|
-
|
257
|
-
lines.join("\n")
|
258
|
-
end
|
259
|
-
|
260
263
|
def total_duration
|
261
264
|
total_time_in_seconds =
|
262
265
|
@tasks.inject(0) do |sum, task|
|
data/lib/task_report.rb
CHANGED
@@ -98,23 +98,43 @@ module TaskReport
|
|
98
98
|
puts 'Something went wrong. There are multiple ongoing tasks.'
|
99
99
|
end
|
100
100
|
|
101
|
-
def summary(
|
101
|
+
def summary(gist, from, to)
|
102
|
+
if from
|
103
|
+
return range_summary(gist, from, to || Time.now.strftime('%Y-%m-%d'))
|
104
|
+
end
|
105
|
+
|
102
106
|
return if no_gist?
|
103
107
|
|
104
108
|
@report ||= Report.create_from_gist(report_gist)
|
105
109
|
|
106
|
-
if
|
110
|
+
if gist
|
107
111
|
@report.gist_summary
|
108
112
|
else
|
109
|
-
unless options.nil?
|
110
|
-
puts "The #{options} option is not recorgnized.\n"\
|
111
|
-
"Printing the summary to the stdout.\n\n"
|
112
|
-
end
|
113
|
-
|
114
113
|
@report.print_summary
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
117
|
+
def print_range_summary_to_gist(reports, from, to)
|
118
|
+
content = reports.map { |r| r.gist_summary_content }.compact.join("\n\n")
|
119
|
+
file_name = "task_report_#{from}_-_#{to}.md"
|
120
|
+
|
121
|
+
gist =
|
122
|
+
Gist.create_or_update(
|
123
|
+
{
|
124
|
+
public: false,
|
125
|
+
description: "Task Report: #{from} - #{to}",
|
126
|
+
files: {
|
127
|
+
file_name => {
|
128
|
+
content: content
|
129
|
+
}
|
130
|
+
}
|
131
|
+
},
|
132
|
+
Time.parse(from)
|
133
|
+
)
|
134
|
+
|
135
|
+
puts gist['html_url']
|
136
|
+
end
|
137
|
+
|
118
138
|
def note(task_id, note)
|
119
139
|
return if no_gist?
|
120
140
|
|
@@ -150,5 +170,38 @@ module TaskReport
|
|
150
170
|
|
151
171
|
false
|
152
172
|
end
|
173
|
+
|
174
|
+
def find_reports(from, to)
|
175
|
+
from_time = Time.parse(from)
|
176
|
+
from_epoch = from_time.to_i
|
177
|
+
|
178
|
+
to_epoch =
|
179
|
+
if to
|
180
|
+
Time.parse(to).to_i
|
181
|
+
else
|
182
|
+
now = Time.now
|
183
|
+
Time.new(now.year, now.month, now.day).to_i
|
184
|
+
end
|
185
|
+
|
186
|
+
seconds_in_a_day = 86400
|
187
|
+
descriptions = []
|
188
|
+
|
189
|
+
(from_epoch..to_epoch).step(seconds_in_a_day) do |epoch|
|
190
|
+
descriptions << Report.gist_description(Time.at(epoch))
|
191
|
+
end
|
192
|
+
|
193
|
+
gists = Gist.find_gists_by_descriptions(descriptions, from_time)
|
194
|
+
gists.map { |gist| Report.create_from_gist(gist) }
|
195
|
+
end
|
196
|
+
|
197
|
+
def range_summary(gist, from, to)
|
198
|
+
reports = find_reports(from, to).reverse
|
199
|
+
|
200
|
+
if gist
|
201
|
+
print_range_summary_to_gist(reports, from, to)
|
202
|
+
else
|
203
|
+
reports.map(&:print_summary)
|
204
|
+
end
|
205
|
+
end
|
153
206
|
end
|
154
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: task_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Pataki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|