tempest_time 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/tempest_time/api/tempo_api/requests/submit_timesheet.rb +6 -8
- data/lib/tempest_time/commands/report.rb +19 -6
- data/lib/tempest_time/commands/submit.rb +20 -3
- data/lib/tempest_time/helpers/time_helper.rb +21 -12
- data/lib/tempest_time/services/generate_report.rb +2 -7
- data/lib/tempest_time/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b26cfdc661706032cc5149b28b05fbf1f322324f0f845c00af8d3e5135546c8
|
4
|
+
data.tar.gz: 1cb5c84cf724531917ec9c759dc83cd47a7fba89a8dc9c74401c65f89b6ea207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ac9e54ec617bae5c87fd405b1b1f6c5df82d47d668caa0a26deedfe52dc59352d5ce3e37b7e0cacb376562fbed3fcb670c1d6f92c737a81b911db2ff0658466
|
7
|
+
data.tar.gz: 502bf3a2a0d11b21167d4fa68305d4993477914462f6110d5dc930e44ceb7a8cf7528e98e135c68cee312d166ef75f571a3f2891a7fc9418b9fbcc7ddad5cf0f
|
data/Gemfile.lock
CHANGED
@@ -7,11 +7,12 @@ module TempoAPI
|
|
7
7
|
class SubmitTimesheet < TempoAPI::Request
|
8
8
|
include TempestTime::Helpers::TimeHelper
|
9
9
|
|
10
|
-
attr_reader :reviewer
|
10
|
+
attr_reader :reviewer, :week_number
|
11
11
|
|
12
|
-
def initialize(reviewer)
|
12
|
+
def initialize(reviewer, week_number)
|
13
13
|
super
|
14
14
|
@reviewer = reviewer
|
15
|
+
@week_number = week_number
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -29,9 +30,10 @@ module TempoAPI
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def query_params
|
33
|
+
dates = week_dates(week_number)
|
32
34
|
{
|
33
|
-
from:
|
34
|
-
to:
|
35
|
+
from: dates.first.strftime(DATE_FORMAT),
|
36
|
+
to: dates.last.strftime(DATE_FORMAT)
|
35
37
|
}
|
36
38
|
end
|
37
39
|
|
@@ -40,10 +42,6 @@ module TempoAPI
|
|
40
42
|
reviewerUsername: reviewer
|
41
43
|
}
|
42
44
|
end
|
43
|
-
|
44
|
-
def week_dates
|
45
|
-
parsed_date_input('week')
|
46
|
-
end
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -12,14 +12,17 @@ module TempestTime
|
|
12
12
|
|
13
13
|
def initialize(users, options)
|
14
14
|
@users = users || []
|
15
|
-
@
|
15
|
+
@team = options[:team]
|
16
|
+
@week = options[:week]
|
16
17
|
end
|
17
18
|
|
18
19
|
def execute(input: $stdin, output: $stdout)
|
19
|
-
|
20
|
-
@users
|
21
|
-
@users.push(TempestTime::Settings::Teams.members(team)) if team
|
20
|
+
@users = user_prompt if @users.empty? && @team.nil?
|
21
|
+
@users.push(TempestTime::Settings::Teams.members(@team)) if @team
|
22
22
|
abort('No users specified.') unless @users.any?
|
23
|
+
|
24
|
+
@week ||= week_prompt
|
25
|
+
|
23
26
|
with_spinner('Generating report...') do |spinner|
|
24
27
|
table = render_table
|
25
28
|
spinner.stop(pastel.green('Your report is ready!'))
|
@@ -35,11 +38,11 @@ module TempestTime
|
|
35
38
|
|
36
39
|
def report
|
37
40
|
@report ||= TempestTime::Services::GenerateReport.new(
|
38
|
-
@users.flatten, @
|
41
|
+
@users.flatten, @week
|
39
42
|
)
|
40
43
|
end
|
41
44
|
|
42
|
-
def
|
45
|
+
def user_prompt
|
43
46
|
type = prompt.select(
|
44
47
|
"Generate a report for a #{pastel.green('user')} or #{pastel.green('team')}?",
|
45
48
|
['User', 'Team']
|
@@ -54,6 +57,16 @@ module TempestTime
|
|
54
57
|
teams.members(team)
|
55
58
|
end
|
56
59
|
|
60
|
+
def week_prompt
|
61
|
+
week = TTY::Prompt.new.select(
|
62
|
+
'Please select the week to report.',
|
63
|
+
week_ranges,
|
64
|
+
default: current_week,
|
65
|
+
per_page: 5
|
66
|
+
)
|
67
|
+
week_ranges.find_index(week) + 1
|
68
|
+
end
|
69
|
+
|
57
70
|
def table_headings
|
58
71
|
%w[User COMP% UTIL%] + report.projects
|
59
72
|
end
|
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative '../command'
|
4
4
|
require_relative '../api/tempo_api/requests/submit_timesheet'
|
5
|
+
require_relative '../helpers/time_helper'
|
5
6
|
|
6
7
|
module TempestTime
|
7
8
|
module Commands
|
8
9
|
class Submit < TempestTime::Command
|
10
|
+
include TempestTime::Helpers::TimeHelper
|
11
|
+
|
9
12
|
def initialize(options)
|
10
13
|
@options = options
|
11
14
|
end
|
@@ -13,14 +16,28 @@ module TempestTime
|
|
13
16
|
def execute(input: $stdin, output: $stdout)
|
14
17
|
# Command logic goes here ...
|
15
18
|
reviewer = prompt.ask('Who should review this timesheet? (username)')
|
16
|
-
|
19
|
+
week_number = week_prompt
|
20
|
+
|
21
|
+
message = 'Submit the selected timesheet to ' + pastel.green(reviewer) + '?'
|
17
22
|
abort unless prompt.yes?(message)
|
18
23
|
abort unless prompt.yes?('Are you sure? No edits can be made once submitted!')
|
19
24
|
|
20
|
-
with_success_fail_spinner("Submitting
|
21
|
-
TempoAPI::Requests::SubmitTimesheet.new(reviewer).send_request
|
25
|
+
with_success_fail_spinner("Submitting your timesheet...") do
|
26
|
+
TempoAPI::Requests::SubmitTimesheet.new(reviewer, week_number).send_request
|
22
27
|
end
|
23
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def week_prompt
|
33
|
+
week = TTY::Prompt.new.select(
|
34
|
+
'Please select the week to submit.',
|
35
|
+
week_ranges,
|
36
|
+
default: current_week,
|
37
|
+
per_page: 5
|
38
|
+
)
|
39
|
+
week_ranges.find_index(week) + 1
|
40
|
+
end
|
24
41
|
end
|
25
42
|
end
|
26
43
|
end
|
@@ -21,7 +21,7 @@ module TempestTime
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def formatted_date_range(start_date, end_date)
|
24
|
-
return formatted_date(start_date) if end_date.nil?
|
24
|
+
return formatted_date(start_date) if end_date.nil?
|
25
25
|
"#{formatted_date(start_date)} - #{formatted_date(end_date)}"
|
26
26
|
end
|
27
27
|
|
@@ -35,29 +35,38 @@ module TempestTime
|
|
35
35
|
[Date.today]
|
36
36
|
when 'yesterday'
|
37
37
|
[Date.today.prev_day]
|
38
|
-
when 'week'
|
39
|
-
|
38
|
+
when 'week', 'thisweek'
|
39
|
+
week_dates(current_week)
|
40
|
+
when 'lastweek'
|
41
|
+
week_dates(current_week - 1)
|
40
42
|
else
|
41
43
|
[Date.parse(date_input)]
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
def
|
46
|
-
|
47
|
+
def current_week
|
48
|
+
# Helper method to make weeks start on Sunday instead of Monday.
|
49
|
+
@current_week ||= (Date.today + 1).cweek
|
47
50
|
end
|
48
51
|
|
49
52
|
def beginning_of_week(week_number)
|
50
|
-
|
51
|
-
|
52
|
-
days_in_the_past = (this_week_number - week_number) * 7
|
53
|
-
beginning_of_this_week - days_in_the_past
|
53
|
+
return unless week_number.positive? && week_number < 53
|
54
|
+
(Date.today - Date.today.wday) - ((current_week - week_number) * 7)
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
-
(
|
58
|
-
|
57
|
+
def week_beginnings
|
58
|
+
@week_beginnings ||= (1..52).map { |week_number| beginning_of_week(week_number) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def week_ranges
|
62
|
+
@week_ranges ||= week_beginnings.map do |start_date|
|
63
|
+
formatted_date_range(start_date, start_date + 6)
|
59
64
|
end
|
60
65
|
end
|
66
|
+
|
67
|
+
def week_dates(week_number)
|
68
|
+
(0..6).map { |days| beginning_of_week(week_number) + days }
|
69
|
+
end
|
61
70
|
end
|
62
71
|
end
|
63
72
|
end
|
@@ -12,7 +12,7 @@ module TempestTime
|
|
12
12
|
def initialize(users, week_number)
|
13
13
|
@users = users
|
14
14
|
@week_number = week_number || Date.today.cweek
|
15
|
-
@reports = build_reports
|
15
|
+
@reports = build_reports
|
16
16
|
end
|
17
17
|
|
18
18
|
def projects
|
@@ -37,17 +37,12 @@ module TempestTime
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
def valid?
|
41
|
-
return false unless week_number <= Date.today.cweek
|
42
|
-
true
|
43
|
-
end
|
44
|
-
|
45
40
|
def build_reports
|
46
41
|
users.map do |user|
|
47
42
|
request = TempoAPI::Requests::ListWorklogs.new(start_date, end_date, user)
|
48
43
|
request.send_request
|
49
44
|
TempestTime::Models::Report.new(user, request.response.worklogs)
|
50
|
-
end
|
45
|
+
end || []
|
51
46
|
end
|
52
47
|
end
|
53
48
|
end
|
data/lib/tempest_time/version.rb
CHANGED