dude-cli 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 319efa8b53b8ca61b34a665a566a8d01f40ea89e
4
- data.tar.gz: 5de5fc6b10a6c3221de627d99ed647e8ea06d353
3
+ metadata.gz: f1b1363a91b57a06932df8d4b80be8b7a709e694
4
+ data.tar.gz: 9e65b6ffa950cfd5c4a14e53872040385cb06a88
5
5
  SHA512:
6
- metadata.gz: '069c31f407392c712dbc799f0fc192b6a43259e641c779bfce81db4a22563db77d23dab823609d43003cacdafd58cd02bf5b7fbd1800c5c7ecd17d01372cac21'
7
- data.tar.gz: 10852b3cada4229f153c818cd74668a14c5cca749a23b4137c04bc198fa6d14c3fa3e10795e0618b8a73ba4c3b50cd23a570355696f9be1a1ae186b92023922d
6
+ metadata.gz: 54999e8a1a98d83a94fb3442bc98d06101a54836426b0e5f22e1b3eed4dcfc1035568920b921ddd60b81b00fecfd36763e35b55cb8006653342e91cb56fa15f3
7
+ data.tar.gz: f65cb5832180d149fde8d9af81a24468c2fdf747c7174c6ce55ab0f80ce39d9091efbf1ee919975822ca5a9b8aecdcd642d6b6720e50a62c0e3e7e267315eeac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dude-cli (0.2.3)
4
+ dude-cli (0.2.4)
5
5
  colorize (~> 0.8)
6
6
  git (~> 1.3)
7
7
  gitlab (~> 4.2)
data/lib/dude/cli.rb CHANGED
@@ -22,18 +22,14 @@ module Dude
22
22
 
23
23
  desc 'checkout [ISSUE_ID]', 'checkout to branch with name "ID-issue-title"'
24
24
  def checkout(issue_id, project_title = folder_name)
25
- issue_title = Gitlab.new(
26
- issue_id: issue_id, project_title: project_title
27
- ).call
25
+ issue_title = get_issue_title(issue_id, project_title)
28
26
  Git.new(branch_name: git_branch_name(issue_title, issue_id)).call
29
27
  end
30
28
 
31
- desc 'start [ISSUE_ID]', 'start task in Toggl with issue title and checkout to branch'
29
+ desc 'start [ISSUE_ID]', 'start task in Toggl with issue title, checkout to branch and estimate time if it is needed'
32
30
  def start(issue_id, project_title = folder_name)
33
31
  checkout(issue_id, project_title)
34
- issue_title = Gitlab.new(
35
- issue_id: issue_id, project_title: project_title
36
- ).call
32
+ issue_title = get_issue_title(issue_id, project_title)
37
33
  Toggl.new(title: "##{issue_id} #{issue_title}", project_title: project_title).start_time_entry
38
34
  puts "Starting Toggl task"
39
35
  end
@@ -44,17 +40,36 @@ module Dude
44
40
  Interface.new.issues_list(issues)
45
41
  end
46
42
 
43
+ desc 'estimate [DURATION] [ISSUE_ID]', 'estimate time'
44
+ def estimate(duration, issue_id = current_issue_id, project_title = folder_name)
45
+ Gitlab.new(issue_id: issue_id, project_title: project_title).estimate_time(duration)
46
+ end
47
+
47
48
  desc 'stop', 'stop current time entry in Toggl'
48
49
  def stop
49
50
  Toggl.new.stop_current_time_entry
50
51
  end
51
52
 
53
+ desc 'issue', 'Information about issue'
54
+ def issue(issue_id = current_issue_id, project_title = folder_name)
55
+ Gitlab.new(issue_id: issue_id, project_title: project_title).issue_info
56
+ end
57
+
52
58
  desc 'stats', 'display your stats from Toggl'
53
59
  def stats
54
60
  Toggl.new.report
55
61
  end
62
+
56
63
  private
57
64
 
65
+ def current_issue_id
66
+ Git.new.current_branch_name.chomp.split('-').first
67
+ end
68
+
69
+ def get_issue_title(issue_id, project_title)
70
+ Gitlab.new(issue_id: issue_id, project_title: project_title).call
71
+ end
72
+
58
73
  def duderc_file_content
59
74
  "TOGGL_EMAIL=\nTOGGL_TOKEN=\nTOGGL_WORKSPACE_ID=\n" \
60
75
  "GITLAB_ENDPOINT=https://gitlab.yoursite.com/api/v4/\n" \
data/lib/dude/git.rb CHANGED
@@ -6,10 +6,15 @@ module Dude
6
6
 
7
7
  def initialize(options = {})
8
8
  @options = options
9
+ @git = ::Git.init
9
10
  end
10
11
 
11
12
  def call
12
- ::Git.init.branch(options[:branch_name]).checkout if options[:branch_name]
13
+ @git.branch(options[:branch_name]).checkout if options[:branch_name]
14
+ end
15
+
16
+ def current_branch_name
17
+ %x(git rev-parse --abbrev-ref HEAD)
13
18
  end
14
19
  end
15
20
  end
data/lib/dude/gitlab.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'gitlab'
2
+ require 'rest-client'
2
3
  require_relative 'settings'
4
+ require_relative 'interface'
3
5
 
4
6
  module Dude
5
7
  class Gitlab
@@ -26,8 +28,25 @@ module Dude
26
28
  ::Gitlab.issues(project_id).select.map {|a| [a.iid, a.title, a.labels]}
27
29
  end
28
30
 
31
+ def estimate_time(duration)
32
+ issue_resource['time_estimate'].post duration: duration
33
+ end
34
+
35
+ def issue_info
36
+ issue_info = JSON.parse(issue_resource.get.body)
37
+ Interface.new.draw_issue_info(issue_info)
38
+ end
39
+
29
40
  private
30
41
 
42
+ def issue_link
43
+ @issue_link ||= ::Gitlab.issue(project_id, options[:issue_id])._links.self.gsub(/http/, 'https')
44
+ end
45
+
46
+ def issue_resource
47
+ @issue_resource ||= RestClient::Resource.new(issue_link, headers: { 'PRIVATE-TOKEN': settings['GITLAB_TOKEN'] })
48
+ end
49
+
31
50
  def project_id
32
51
  @project_id ||= ::Gitlab.project_search(options[:project_title])[0].id
33
52
  end
@@ -5,10 +5,34 @@ module Dude
5
5
  class Interface
6
6
  include Settings
7
7
 
8
- def report(worked_week, worked_today)
9
- report_weekly(worked_week)
8
+ def draw_report(report)
9
+ @report = report
10
+ report_weekly
10
11
  puts ''
11
- report_daily(worked_today, worked_week)
12
+ report_daily
13
+ end
14
+
15
+ def draw_issue_info(info)
16
+ issue_label = info['labels'].find do |label|
17
+ ['To Do', 'Doing', 'To Verify'].include? label
18
+ end
19
+
20
+ issue_color = case issue_label
21
+ when 'To Do'
22
+ :yellow
23
+ when 'Doing'
24
+ :green
25
+ when 'To Verify'
26
+ :blue
27
+ end
28
+
29
+ puts "#{info['title']} ##{info['iid']}".colorize(issue_color).bold
30
+ puts "Status: ".colorize(:yellow) + "#{issue_label}"
31
+ puts "Estimated time: ".colorize(:yellow) +
32
+ "#{info['time_stats']['human_time_estimate']}"
33
+ puts "Spent time: ".colorize(:yellow) +
34
+ "#{info['time_stats']['human_total_time_spent'] || '0h'}"
35
+ puts "Link: ".colorize(:yellow) + "#{info['web_url']}"
12
36
  end
13
37
 
14
38
  def issues_list(issues)
@@ -28,22 +52,26 @@ module Dude
28
52
 
29
53
  private
30
54
 
31
- def report_weekly(worked_week)
32
- puts "Week".center(15).colorize(:green).bold
33
- puts '-' * 15
34
- puts "Worked:".colorize(:yellow).bold +
35
- " #{seconds_to_time(worked_week)} / #{settings['HOURS_PER_WEEK']}:00:00 (#{worked_week * 100 / 144000}%)"
36
- puts "Time left:".colorize(:yellow).bold +
37
- " #{seconds_to_time(144000 - worked_week)}"
55
+ def report_weekly
56
+ puts "Week".colorize(:green).bold
57
+ # puts '-' * 15
58
+ puts " Worked:".colorize(:yellow).bold +
59
+ " #{seconds_to_time(@report.week_time_worked)} / " \
60
+ "#{@report.hours_without_weekends}:00:00 " \
61
+ "(#{@report.week_time_worked * 100 / 144000}%)"
62
+ puts " Time left:".colorize(:yellow).bold +
63
+ " #{seconds_to_time(144000 - @report.week_time_worked)}"
38
64
  end
39
65
 
40
- def report_daily(worked_today, worked_week)
41
- puts "Today".center(15).colorize(:green).bold
42
- puts '-' * 15
43
- puts "Worked:".colorize(:yellow).bold +
44
- " #{seconds_to_time(worked_today)} / #{settings['HOURS_PER_DAY']}:00:00 (#{worked_today * 100 / 28800}%)"
45
- puts "Time left:".colorize(:yellow).bold +
46
- " #{seconds_to_time(seconds_for_today - worked_week)}"
66
+ def report_daily
67
+ puts "Today".colorize(:green).bold
68
+ # puts '-' * 15
69
+ puts " Worked:".colorize(:yellow).bold +
70
+ " #{seconds_to_time(@report.today_time_worked)} / " \
71
+ " #{settings['HOURS_PER_DAY']}:00:00 " \
72
+ "(#{@report.today_time_worked * 100 / 28800}%)"
73
+ puts " Time left:".colorize(:yellow).bold +
74
+ " #{seconds_to_time(@report.seconds_for_today - @report.week_time_worked)}"
47
75
  end
48
76
 
49
77
  def seconds_to_time(s)
@@ -51,10 +79,6 @@ module Dude
51
79
  "#{sprintf '%02d', hms[0]}:#{sprintf '%02d', hms[1]}:#{sprintf '%02d', hms[2]}"
52
80
  end
53
81
 
54
- def seconds_for_today
55
- Time.now.wday * settings['HOURS_PER_DAY'].to_i * 3600
56
- end
57
-
58
82
  def term
59
83
  term_size = IO.console.winsize
60
84
  @terminal = OpenStruct.new(h: term_size[0], w: term_size[1])
@@ -0,0 +1,38 @@
1
+ require 'date'
2
+ require_relative 'settings'
3
+
4
+ module Dude
5
+ class Report
6
+ include Settings
7
+ attr_reader :report
8
+
9
+ def initialize(report_json)
10
+ @report = JSON.parse(report_json.body)
11
+ end
12
+
13
+ def week_time_worked
14
+ @time_worked ||= report['total_grand'] / 1000
15
+ end
16
+
17
+ def today_time_worked
18
+ @today_time_worked ||= report['week_totals'].map {|a| a.nil? ? 0 : a / 1000}[Time.now.wday - 1]
19
+ end
20
+
21
+ def days_without_weekends
22
+ @days_without_weekends ||= report['week_totals'][0..Time.now.wday - 1].compact.count
23
+ end
24
+
25
+ def weekends
26
+ @weekends ||= report['week_totals'][0..Time.now.wday - 1].
27
+ select { |a| a.nil? }.count
28
+ end
29
+
30
+ def hours_without_weekends
31
+ @hours_without_weekends ||= settings['HOURS_PER_WEEK'].to_i - weekends * settings['HOURS_PER_DAY'].to_i
32
+ end
33
+
34
+ def seconds_for_today
35
+ days_without_weekends * settings['HOURS_PER_DAY'].to_i * 3600
36
+ end
37
+ end
38
+ end
data/lib/dude/toggl.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rest-client'
2
2
  require 'date'
3
3
  require_relative 'settings'
4
+ require_relative 'report'
4
5
 
5
6
  module Dude
6
7
  class Toggl
@@ -12,10 +13,8 @@ module Dude
12
13
  end
13
14
 
14
15
  def report
15
- report = toggl_report.get params: report_params
16
- time_worked = JSON.parse(report.body)['total_grand'] / 1000
17
- today_time_worked = JSON.parse(report.body)['week_totals'].map {|a| a.nil? ? 0 : a / 1000}[Time.now.wday - 1]
18
- Interface.new.report(time_worked, today_time_worked)
16
+ report = Report.new(toggl_report.get params: report_params)
17
+ Interface.new.draw_report(report)
19
18
  end
20
19
 
21
20
  def start_time_entry
data/lib/dude/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dude
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dude-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Pupko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,6 +161,7 @@ files:
161
161
  - lib/dude/git.rb
162
162
  - lib/dude/gitlab.rb
163
163
  - lib/dude/interface.rb
164
+ - lib/dude/report.rb
164
165
  - lib/dude/settings.rb
165
166
  - lib/dude/toggl.rb
166
167
  - lib/dude/version.rb