dude-cli 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.travis.yml +4 -3
  4. data/CHANGELOG.md +25 -0
  5. data/Gemfile +3 -2
  6. data/Gemfile.lock +55 -54
  7. data/README.md +41 -25
  8. data/bin/dude +3 -2
  9. data/dude.gemspec +16 -16
  10. data/lib/dude.rb +14 -0
  11. data/lib/dude/commands.rb +24 -0
  12. data/lib/dude/commands/checkout.rb +21 -0
  13. data/lib/dude/commands/install.rb +57 -0
  14. data/lib/dude/commands/move.rb +15 -0
  15. data/lib/dude/commands/start.rb +29 -0
  16. data/lib/dude/commands/stop.rb +15 -0
  17. data/lib/dude/commands/tasks.rb +31 -0
  18. data/lib/dude/commands/track.rb +28 -0
  19. data/lib/dude/commands/version.rb +11 -0
  20. data/lib/dude/git.rb +5 -0
  21. data/lib/dude/git/checkout.rb +2 -16
  22. data/lib/dude/git/current_branch_name.rb +1 -2
  23. data/lib/dude/project_management/client.rb +25 -0
  24. data/lib/dude/project_management/entities/board.rb +9 -0
  25. data/lib/dude/project_management/entities/issue.rb +37 -0
  26. data/lib/dude/project_management/jira.rb +9 -0
  27. data/lib/dude/project_management/jira/client.rb +49 -0
  28. data/lib/dude/project_management/jira/get_current_tasks.rb +40 -0
  29. data/lib/dude/project_management/jira/get_task_name_by_id.rb +24 -0
  30. data/lib/dude/project_management/jira/move_task_to_list.rb +47 -0
  31. data/lib/dude/project_management/trello.rb +6 -0
  32. data/lib/dude/project_management/trello/checkout.rb +4 -0
  33. data/lib/dude/project_management/trello/client.rb +33 -0
  34. data/lib/dude/project_management/trello/get_current_tasks.rb +24 -0
  35. data/lib/dude/project_management/trello/get_lists.rb +15 -0
  36. data/lib/dude/project_management/trello/move_tasks_to_list.rb +14 -0
  37. data/lib/dude/settings.rb +6 -2
  38. data/lib/dude/time_trackers/toggl.rb +5 -0
  39. data/lib/dude/time_trackers/toggl/base.rb +18 -0
  40. data/lib/dude/{toggl → time_trackers/toggl}/start_time_entry.rb +14 -8
  41. data/lib/dude/{toggl → time_trackers/toggl}/stop_time_entry.rb +4 -2
  42. data/lib/dude/version.rb +1 -1
  43. metadata +56 -103
  44. data/.ruby-version +0 -1
  45. data/LICENSE.txt +0 -21
  46. data/lib/dude/cli.rb +0 -156
  47. data/lib/dude/gitlab/add_spend_time.rb +0 -36
  48. data/lib/dude/gitlab/base.rb +0 -38
  49. data/lib/dude/gitlab/count_spend_time.rb +0 -13
  50. data/lib/dude/gitlab/estimate.rb +0 -20
  51. data/lib/dude/gitlab/get_issue_info.rb +0 -9
  52. data/lib/dude/gitlab/get_issue_time_spent.rb +0 -9
  53. data/lib/dude/gitlab/get_issue_title.rb +0 -14
  54. data/lib/dude/gitlab/get_my_issues.rb +0 -31
  55. data/lib/dude/gitlab/move_issue.rb +0 -37
  56. data/lib/dude/interface.rb +0 -98
  57. data/lib/dude/report.rb +0 -38
  58. data/lib/dude/service.rb +0 -18
  59. data/lib/dude/toggl.rb +0 -40
  60. data/lib/dude/toggl/base.rb +0 -36
  61. data/lib/dude/toggl/issue_spend_time.rb +0 -56
  62. data/lib/dude/toggl/report.rb +0 -25
data/lib/dude/report.rb DELETED
@@ -1,38 +0,0 @@
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)
10
- @report = report
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/service.rb DELETED
@@ -1,18 +0,0 @@
1
- module Dude
2
- module Service
3
- attr_reader :options
4
- def initialize(options = {})
5
- @options = options
6
- end
7
-
8
- def self.included(klass)
9
- klass.extend(ClassMethods)
10
- end
11
-
12
- module ClassMethods
13
- def call(options = {})
14
- new(options).call
15
- end
16
- end
17
- end
18
- end
data/lib/dude/toggl.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'rest-client'
2
- require 'date'
3
- require_relative 'settings'
4
- require_relative 'report'
5
-
6
- module Dude
7
- class Toggl
8
- include Settings
9
- attr_accessor :options
10
-
11
- def initialize(options = {})
12
- @options = options
13
- end
14
-
15
-
16
- def stop_current_time_entry
17
- toggl_api["time_entries/#{current_time_entry['id']}/stop"].put ''
18
- rescue NoMethodError
19
- puts 'No runned time entries in Toggl'.colorize(:yellow)
20
- end
21
-
22
- def time_entry_params(title)
23
- {
24
- time_entry: {
25
- description: title,
26
- pid: project_id,
27
- created_with: "dude"
28
- }
29
- }
30
- end
31
-
32
- def toggl_api
33
- @toggl_api ||= RestClient::Resource.new(
34
- 'https://www.toggl.com/api/v8',
35
- settings['TOGGL_TOKEN'],
36
- 'api_token'
37
- )
38
- end
39
- end
40
- end
@@ -1,36 +0,0 @@
1
- module Dude
2
- module Toggl
3
- class Base
4
- include Service
5
- include Settings
6
-
7
- def toggl_api
8
- @toggl_api ||= RestClient::Resource.new(
9
- 'https://www.toggl.com/api/v8',
10
- settings['TOGGL_TOKEN'],
11
- 'api_token'
12
- )
13
- end
14
-
15
- def toggl_report
16
- @toggl_report ||= RestClient::Resource.new(
17
- 'https://www.toggl.com/reports/api/v2/weekly',
18
- settings['TOGGL_TOKEN'],
19
- 'api_token'
20
- )
21
- end
22
-
23
- def toggl_summary
24
- @toggl_summary ||= RestClient::Resource.new(
25
- 'https://www.toggl.com/reports/api/v2/summary',
26
- settings['TOGGL_TOKEN'],
27
- 'api_token'
28
- )
29
- end
30
-
31
- def projects_response
32
- toggl_api["workspaces/#{settings['TOGGL_WORKSPACE_ID']}/projects"].get
33
- end
34
- end
35
- end
36
- end
@@ -1,56 +0,0 @@
1
- module Dude
2
- module Toggl
3
- class IssueSpendTime < Dude::Toggl::Base
4
- def call
5
- parse_time_entries_list / 1000
6
- end
7
-
8
- def params
9
- {
10
- workspace_id: settings['TOGGL_WORKSPACE_ID'],
11
- user_agent: settings['TOGGL_EMAIL'],
12
- since: Date.today.prev_year,
13
- until: Date.today.to_s
14
- }
15
- end
16
-
17
- def response
18
- toggl_summary.get params: params
19
- end
20
-
21
- def time_entries
22
- JSON.parse(response.body)['data']
23
- end
24
-
25
- def all_project_issues
26
- time_entries.find { |project| project['id'].eql? project_id }['items']
27
- end
28
-
29
- def current_issue_time_entry
30
- all_project_issues.find { |entry| match_issue_id?(entry) }
31
- end
32
-
33
- def match_issue_id?(time_entry)
34
- title = time_entry.dig('title', 'time_entry')
35
- title.match?(/\(##{options[:issue_id]}\)/) ||
36
- title.match?(/##{options[:issue_id]}\s/)
37
- end
38
-
39
- def parse_time_entries_list
40
- current_issue_time_entry['time']
41
- end
42
-
43
- def project_id
44
- # TODO: Concretize project selection
45
- @project_id ||= projects_array.find do |title, id|
46
- title.eql?(options[:project_title])
47
- end.last
48
- end
49
-
50
- def projects_array
51
- JSON.parse(projects_response)
52
- .map { |a| [a['name'].downcase.gsub(/\s/, '-'), a['id']] }
53
- end
54
- end
55
- end
56
- end
@@ -1,25 +0,0 @@
1
- module Dude
2
- module Toggl
3
- class Report < Dude::Toggl::Base
4
- def call
5
- Dude::Report.new(parsed_response)
6
- end
7
-
8
- def response
9
- toggl_report.get params: params
10
- end
11
-
12
- def params
13
- {
14
- workspace_id: settings['TOGGL_WORKSPACE_ID'],
15
- user_agent: settings['TOGGL_EMAIL'],
16
- since: Date.parse('monday').strftime('%Y-%m-%d')
17
- }
18
- end
19
-
20
- def parsed_response
21
- @parsed_response = JSON.parse(response.body)
22
- end
23
- end
24
- end
25
- end