abt-cli 0.0.7 → 0.0.8

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
  SHA256:
3
- metadata.gz: cd99c9123cfbd4222176495fd039015ad56ddaf0841350347169fa6809f8d6b2
4
- data.tar.gz: 33d0adf3e73be8f5b2a6f52d61cea46285e0e2ab036b2d1b0e1b4fe1f2c0a27a
3
+ metadata.gz: 3568d2d1acd067392e3832ee00bb1eb6f1fdcb6d9526fe1f747674c452173543
4
+ data.tar.gz: f189b4c27d9cac1703211dc4c9fefdd33d359149d336d74f67f47aa9e9d96137
5
5
  SHA512:
6
- metadata.gz: 2ea6b3ea3f1f2056b9e7911144542f0d2f3b568544fcd68901299fb64c84414290d7cecfc884405bde0125b096bc7033b99d3c2eb87e0598f434de79cfa76ae3
7
- data.tar.gz: 3c8ffb1c3ba6553d16611c0f55a1c1bae3cf97d156fc79242f66b2d0b2ac622b08ab4ef049b98299553c708dc36365fc4e6158e31b556d830d863019134f34eb
6
+ metadata.gz: c38b239739f77fd58ce6df48e7f4057fb66a1a50f96bb2d7469ef7b0809b085d643face8fdbc82f9bb654ea75e565f60e9629952f9cc894abe9745101fd670bb
7
+ data.tar.gz: f5fdf894aba1ca64f7a815f7aa1e17d2c23e3c690220f54b4cd0351586c293fd7a5716dbac544c9a63be6fb6ea8154e9e53c2e76658406e67f95656c597ab4f6
data/bin/abt CHANGED
@@ -5,6 +5,7 @@ require 'dry-inflector'
5
5
  require 'faraday'
6
6
  require 'oj'
7
7
  require 'open3'
8
+ require 'stringio'
8
9
 
9
10
  require_relative '../lib/abt.rb'
10
11
 
@@ -17,6 +17,10 @@ module Abt
17
17
  'abt start asana harvest' => 'Continue working, e.g. after a break',
18
18
  'abt finalize asana' => 'Finalize the selected asana task'
19
19
  },
20
+ 'Tracking meetings (without changing the config):' => {
21
+ 'abt tasks asana | grep -i standup | abt track harvest' => 'Track on asana meeting task without changing any configuration',
22
+ 'abt tasks harvest | grep -i comment | abt track harvest' => 'Track on harvest "Comment"-task (will prompt for a comment)'
23
+ },
20
24
  'Command output can be piped, e.g.:' => {
21
25
  'abt tasks asana | grep -i <name of task>' => nil,
22
26
  'abt tasks asana | grep -i <name of task> | abt start' => nil
@@ -10,21 +10,16 @@ module Abt
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Start tracker for current or specified task. Add a relevant provider to link the time entry: E.g. `abt start harvest asana`' # rubocop:disable Layout/LineLength
13
+ 'As track, but also lets the user override the current task and triggers `start` commands for other providers ' # rubocop:disable Layout/LineLength
14
14
  end
15
15
 
16
16
  def call
17
- abort 'No current/provided task' if task_id.nil?
17
+ start_output = call_start
18
+ puts start_output
18
19
 
19
- maybe_override_current_task
20
-
21
- print_task(project, task)
22
-
23
- cli.abort('No task selected') if task_id.nil?
24
-
25
- create_time_entry
20
+ use_arg_str(arg_str_from_start_output(start_output))
26
21
 
27
- cli.warn 'Tracker successfully started'
22
+ maybe_override_current_task
28
23
  rescue Abt::HttpError::HttpError => e
29
24
  cli.warn e
30
25
  cli.abort 'Unable to start tracker'
@@ -32,67 +27,29 @@ module Abt
32
27
 
33
28
  private
34
29
 
35
- def maybe_override_current_task
36
- return if arg_str.nil?
37
- return if same_args_as_config?
38
- return unless config.local_available?
39
-
40
- should_override = cli.prompt_boolean 'Set selected task as current?'
41
- Current.new(arg_str: arg_str, cli: cli).call if should_override
30
+ def arg_str_from_start_output(output)
31
+ output = output.split(' # ').first
32
+ output.split(':')[1]
42
33
  end
43
34
 
44
- def create_time_entry
45
- body = {
46
- project_id: project_id,
47
- task_id: task_id,
48
- user_id: config.user_id,
49
- spent_date: Date.today.iso8601
50
- }
51
-
52
- if external_link_data
53
- body.merge! external_link_data
54
- else
55
- cli.warn 'No external link provided'
56
- body[:notes] ||= cli.prompt('Fill in comment (optional)')
57
- end
58
-
59
- api.post('time_entries', Oj.dump(body, mode: :json))
60
- end
35
+ def call_start
36
+ output = StringIO.new
37
+ Abt::Cli.new(argv: ['track', *cli.args], output: output).perform
61
38
 
62
- def project
63
- project_assignment['project']
39
+ output_str = output.string.strip
40
+ cli.abort 'No task provided' if output_str.empty?
41
+ output_str
64
42
  end
65
43
 
66
- def task
67
- @task ||= project_assignment['task_assignments'].map { |ta| ta['task'] }.find do |task|
68
- task['id'].to_s == task_id
69
- end
70
- end
71
-
72
- def project_assignment
73
- @project_assignment ||= begin
74
- project_assignments.find { |pa| pa['project']['id'].to_s == project_id }
75
- end
76
- end
77
-
78
- def project_assignments
79
- @project_assignments ||= api.get_paged('users/me/project_assignments')
80
- end
81
-
82
- def external_link_data
83
- @external_link_data ||= begin
84
- arg_strs = cli.args.join(' ')
85
- lines = `#{$PROGRAM_NAME} harvest-time-entry-data #{arg_strs}`.split("\n")
86
-
87
- return if lines.empty?
88
-
89
- # TODO: Make user choose which reference to use by printing the urls
90
- if lines.length > 1
91
- cli.abort('Multiple providers had harvest reference data, only one is supported at a time') # rubocop:disable Layout/LineLength
92
- end
44
+ def maybe_override_current_task
45
+ return if arg_str.nil?
46
+ return if same_args_as_config?
47
+ return unless config.local_available?
48
+ return unless cli.prompt_boolean 'Set selected task as current?'
93
49
 
94
- Oj.load(lines.first)
95
- end
50
+ output = StringIO.new
51
+ Abt::Cli.new(argv: ['current', "harvest:#{project_id}/#{task_id}"],
52
+ output: output).perform
96
53
  end
97
54
  end
98
55
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Harvest
6
+ module Commands
7
+ class Track < BaseCommand
8
+ def self.command
9
+ 'track harvest[:<project-id>/<task-id>]'
10
+ end
11
+
12
+ def self.description
13
+ 'Start tracker for current or specified task. Add a relevant provider to link the time entry: E.g. `abt start harvest asana`' # rubocop:disable Layout/LineLength
14
+ end
15
+
16
+ def call
17
+ abort 'No current/provided task' if task_id.nil?
18
+ cli.abort('No task selected') if task_id.nil?
19
+
20
+ print_task(created_time_entry['project'], created_time_entry['task'])
21
+
22
+ cli.warn 'Tracker successfully started'
23
+ rescue Abt::HttpError::HttpError => e
24
+ cli.abort 'Invalid task'
25
+ end
26
+
27
+ private
28
+
29
+ def created_time_entry
30
+ @created_time_entry ||= create_time_entry
31
+ end
32
+
33
+ def create_time_entry
34
+ body = {
35
+ project_id: project_id,
36
+ task_id: task_id,
37
+ user_id: config.user_id,
38
+ spent_date: Date.today.iso8601
39
+ }
40
+
41
+ if external_link_data
42
+ body.merge! external_link_data
43
+ else
44
+ cli.warn 'No external link provided'
45
+ body[:notes] ||= cli.prompt('Fill in comment (optional)')
46
+ end
47
+
48
+ api.post('time_entries', Oj.dump(body, mode: :json))
49
+ end
50
+
51
+ def external_link_data
52
+ @external_link_data ||= begin
53
+ arg_strs = cli.args.join(' ')
54
+ lines = `#{$PROGRAM_NAME} harvest-time-entry-data #{arg_strs}`.split("\n")
55
+
56
+ return if lines.empty?
57
+
58
+ # TODO: Make user choose which reference to use by printing the urls
59
+ if lines.length > 1
60
+ cli.abort('Multiple providers had harvest reference data, only one is supported at a time') # rubocop:disable Layout/LineLength
61
+ end
62
+
63
+ Oj.load(lines.first)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Abt
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abt-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesper Sørensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -113,6 +113,7 @@ files:
113
113
  - "./lib/abt/providers/harvest/commands/start.rb"
114
114
  - "./lib/abt/providers/harvest/commands/stop.rb"
115
115
  - "./lib/abt/providers/harvest/commands/tasks.rb"
116
+ - "./lib/abt/providers/harvest/commands/track.rb"
116
117
  - "./lib/abt/providers/harvest/configuration.rb"
117
118
  - "./lib/abt/version.rb"
118
119
  - bin/abt