abt-cli 0.0.17 → 0.0.22

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/bin/abt +3 -3
  3. data/lib/abt.rb +6 -6
  4. data/lib/abt/ari.rb +20 -0
  5. data/lib/abt/ari_list.rb +13 -0
  6. data/lib/abt/base_command.rb +63 -0
  7. data/lib/abt/cli.rb +58 -59
  8. data/lib/abt/cli/arguments_parser.rb +8 -27
  9. data/lib/abt/cli/global_commands.rb +23 -0
  10. data/lib/abt/cli/global_commands/commands.rb +23 -0
  11. data/lib/abt/cli/global_commands/examples.rb +23 -0
  12. data/lib/abt/cli/global_commands/help.rb +23 -0
  13. data/lib/abt/cli/global_commands/readme.rb +23 -0
  14. data/lib/abt/cli/global_commands/share.rb +36 -0
  15. data/lib/abt/cli/global_commands/version.rb +23 -0
  16. data/lib/abt/cli/prompt.rb +52 -20
  17. data/lib/abt/docs.rb +48 -25
  18. data/lib/abt/docs/cli.rb +7 -7
  19. data/lib/abt/docs/markdown.rb +13 -12
  20. data/lib/abt/git_config.rb +21 -39
  21. data/lib/abt/providers/asana/api.rb +9 -9
  22. data/lib/abt/providers/asana/base_command.rb +16 -38
  23. data/lib/abt/providers/asana/commands/add.rb +18 -15
  24. data/lib/abt/providers/asana/commands/branch_name.rb +13 -8
  25. data/lib/abt/providers/asana/commands/clear.rb +8 -7
  26. data/lib/abt/providers/asana/commands/current.rb +23 -38
  27. data/lib/abt/providers/asana/commands/finalize.rb +11 -16
  28. data/lib/abt/providers/asana/commands/harvest_time_entry_data.rb +14 -9
  29. data/lib/abt/providers/asana/commands/init.rb +8 -41
  30. data/lib/abt/providers/asana/commands/pick.rb +22 -17
  31. data/lib/abt/providers/asana/commands/projects.rb +5 -5
  32. data/lib/abt/providers/asana/commands/share.rb +6 -8
  33. data/lib/abt/providers/asana/commands/start.rb +26 -23
  34. data/lib/abt/providers/asana/commands/tasks.rb +6 -5
  35. data/lib/abt/providers/asana/configuration.rb +34 -40
  36. data/lib/abt/providers/asana/path.rb +36 -0
  37. data/lib/abt/providers/devops/api.rb +23 -11
  38. data/lib/abt/providers/devops/base_command.rb +18 -43
  39. data/lib/abt/providers/devops/commands/boards.rb +5 -7
  40. data/lib/abt/providers/devops/commands/branch_name.rb +14 -10
  41. data/lib/abt/providers/devops/commands/clear.rb +8 -7
  42. data/lib/abt/providers/devops/commands/current.rb +25 -49
  43. data/lib/abt/providers/devops/commands/harvest_time_entry_data.rb +20 -12
  44. data/lib/abt/providers/devops/commands/init.rb +29 -25
  45. data/lib/abt/providers/devops/commands/pick.rb +11 -18
  46. data/lib/abt/providers/devops/commands/share.rb +7 -6
  47. data/lib/abt/providers/devops/commands/{work-items.rb → work_items.rb} +3 -3
  48. data/lib/abt/providers/devops/configuration.rb +31 -56
  49. data/lib/abt/providers/devops/path.rb +51 -0
  50. data/lib/abt/providers/git/commands/branch.rb +29 -25
  51. data/lib/abt/providers/harvest/api.rb +8 -8
  52. data/lib/abt/providers/harvest/base_command.rb +18 -38
  53. data/lib/abt/providers/harvest/commands/clear.rb +8 -7
  54. data/lib/abt/providers/harvest/commands/current.rb +28 -35
  55. data/lib/abt/providers/harvest/commands/init.rb +10 -39
  56. data/lib/abt/providers/harvest/commands/pick.rb +11 -12
  57. data/lib/abt/providers/harvest/commands/projects.rb +5 -5
  58. data/lib/abt/providers/harvest/commands/share.rb +6 -8
  59. data/lib/abt/providers/harvest/commands/start.rb +5 -3
  60. data/lib/abt/providers/harvest/commands/stop.rb +13 -13
  61. data/lib/abt/providers/harvest/commands/tasks.rb +9 -6
  62. data/lib/abt/providers/harvest/commands/track.rb +40 -32
  63. data/lib/abt/providers/harvest/configuration.rb +28 -37
  64. data/lib/abt/providers/harvest/path.rb +36 -0
  65. data/lib/abt/version.rb +1 -1
  66. metadata +18 -6
  67. data/lib/abt/cli/base_command.rb +0 -61
@@ -6,24 +6,22 @@ module Abt
6
6
  module Commands
7
7
  class Finalize < BaseCommand
8
8
  def self.usage
9
- 'abt finalize asana[:<project-gid>/<task-gid>]'
9
+ "abt finalize asana[:<project-gid>/<task-gid>]"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Move current/specified task to section (column) for finalized tasks'
13
+ "Move current/specified task to section (column) for finalized tasks"
14
14
  end
15
15
 
16
16
  def perform
17
- unless config.local_available?
18
- cli.abort 'This is a no-op for tasks outside the current project'
19
- end
17
+ abort("This is a no-op for tasks outside the current project") unless project_gid == config.path.project_gid
20
18
  require_task!
21
19
  print_task(project_gid, task)
22
20
 
23
21
  if task_already_in_finalized_section?
24
- cli.warn "Task already in section: #{current_task_section['name']}"
22
+ warn("Task already in section: #{current_task_section['name']}")
25
23
  else
26
- cli.warn "Moving task to section: #{finalized_section['name']}"
24
+ warn("Moving task to section: #{finalized_section['name']}")
27
25
  move_task
28
26
  end
29
27
  end
@@ -35,18 +33,18 @@ module Abt
35
33
  end
36
34
 
37
35
  def current_task_section
38
- task_section_membership&.dig('section')
36
+ task_section_membership&.dig("section")
39
37
  end
40
38
 
41
39
  def task_section_membership
42
- task['memberships'].find do |membership|
43
- membership.dig('section', 'gid') == config.finalized_section_gid
40
+ task["memberships"].find do |membership|
41
+ membership.dig("section", "gid") == config.finalized_section_gid
44
42
  end
45
43
  end
46
44
 
47
45
  def finalized_section
48
46
  @finalized_section ||= api.get("sections/#{config.finalized_section_gid}",
49
- opt_fields: 'name')
47
+ opt_fields: "name")
50
48
  end
51
49
 
52
50
  def move_task
@@ -57,11 +55,8 @@ module Abt
57
55
 
58
56
  def task
59
57
  @task ||= begin
60
- if task_gid.nil?
61
- nil
62
- else
63
- api.get("tasks/#{task_gid}", opt_fields: 'name,memberships.section.name,permalink_url')
64
- end
58
+ api.get("tasks/#{task_gid}",
59
+ opt_fields: "name,memberships.section.name,permalink_url")
65
60
  end
66
61
  end
67
62
  end
@@ -6,11 +6,11 @@ module Abt
6
6
  module Commands
7
7
  class HarvestTimeEntryData < BaseCommand
8
8
  def self.usage
9
- 'abt harvest-time-entry-data asana[:<project-gid>/<task-gid>]'
9
+ "abt harvest-time-entry-data asana[:<project-gid>/<task-gid>]"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Print Harvest time entry data for Asana task as json. Used by harvest start script.'
13
+ "Print Harvest time entry data for Asana task as json. Used by harvest start script."
14
14
  end
15
15
 
16
16
  def perform
@@ -18,29 +18,34 @@ module Abt
18
18
  ensure_current_is_valid!
19
19
 
20
20
  body = {
21
- notes: task['name'],
21
+ notes: task["name"],
22
22
  external_reference: {
23
23
  id: task_gid.to_i,
24
24
  group_id: project_gid.to_i,
25
- permalink: task['permalink_url']
25
+ permalink: task["permalink_url"]
26
26
  }
27
27
  }
28
28
 
29
- cli.puts Oj.dump(body, mode: :json)
29
+ puts Oj.dump(body, mode: :json)
30
30
  end
31
31
 
32
32
  private
33
33
 
34
34
  def ensure_current_is_valid!
35
- cli.abort "Invalid task gid: #{task_gid}" if task.nil?
35
+ abort("Invalid task gid: #{task_gid}") if task.nil?
36
36
 
37
- return if task['memberships'].any? { |m| m.dig('project', 'gid') == project_gid }
37
+ return if task["memberships"].any? { |m| m.dig("project", "gid") == project_gid }
38
38
 
39
- cli.abort "Invalid project gid: #{project_gid}"
39
+ abort("Invalid or unmatching project gid: #{project_gid}")
40
40
  end
41
41
 
42
42
  def task
43
- @task ||= api.get("tasks/#{task_gid}", opt_fields: 'name,permalink_url,memberships.project')
43
+ @task ||= begin
44
+ warn("Fetching task...")
45
+ api.get("tasks/#{task_gid}", opt_fields: "name,permalink_url,memberships.project")
46
+ rescue Abt::HttpError::NotFoundError
47
+ nil
48
+ end
44
49
  end
45
50
  end
46
51
  end
@@ -6,66 +6,33 @@ module Abt
6
6
  module Commands
7
7
  class Init < BaseCommand
8
8
  def self.usage
9
- 'abt init asana'
9
+ "abt init asana"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Pick Asana project for current git repository'
14
- end
15
-
16
- def initialize(cli:, **)
17
- @config = Configuration.new(cli: cli)
18
- @cli = cli
13
+ "Pick Asana project for current git repository"
19
14
  end
20
15
 
21
16
  def perform
22
- cli.abort 'Must be run inside a git repository' unless config.local_available?
17
+ abort("Must be run inside a git repository") unless config.local_available?
23
18
 
24
19
  projects # Load projects up front to make it obvious that searches are instant
25
- project = find_search_result
20
+ project = cli.prompt.search("Select a project", projects)
26
21
 
27
- config.project_gid = project['gid']
22
+ config.path = Path.from_ids(project["gid"])
28
23
 
29
24
  print_project(project)
30
25
  end
31
26
 
32
27
  private
33
28
 
34
- def find_search_result
35
- cli.warn 'Select a project'
36
-
37
- loop do
38
- matches = matches_for_string cli.prompt.text('Enter search')
39
- if matches.empty?
40
- cli.warn 'No matches'
41
- next
42
- end
43
-
44
- cli.warn 'Showing the 10 first matches' if matches.size > 10
45
- choice = cli.prompt.choice 'Select a project', matches[0...10], true
46
- break choice unless choice.nil?
47
- end
48
- end
49
-
50
- def matches_for_string(string)
51
- search_string = sanitize_string(string)
52
-
53
- projects.select do |project|
54
- sanitize_string(project['name']).include?(search_string)
55
- end
56
- end
57
-
58
- def sanitize_string(string)
59
- string.downcase.gsub(/[^\w]/, '')
60
- end
61
-
62
29
  def projects
63
30
  @projects ||= begin
64
- cli.warn 'Fetching projects...'
65
- api.get_paged('projects',
31
+ warn("Fetching projects...")
32
+ api.get_paged("projects",
66
33
  workspace: config.workspace_gid,
67
34
  archived: false,
68
- opt_fields: 'name,permalink_url')
35
+ opt_fields: "name,permalink_url")
69
36
  end
70
37
  end
71
38
  end
@@ -6,24 +6,24 @@ module Abt
6
6
  module Commands
7
7
  class Pick < BaseCommand
8
8
  def self.usage
9
- 'abt pick asana[:<project-gid>]'
9
+ "abt pick asana[:<project-gid>]"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Pick task for current git repository'
13
+ "Pick task for current git repository"
14
14
  end
15
15
 
16
16
  def self.flags
17
17
  [
18
- ['-d', '--dry-run', 'Keep existing configuration']
18
+ ["-d", "--dry-run", "Keep existing configuration"]
19
19
  ]
20
20
  end
21
21
 
22
22
  def perform
23
- cli.abort 'Must be run inside a git repository' unless config.local_available?
23
+ abort("Must be run inside a git repository") unless config.local_available?
24
24
  require_project!
25
25
 
26
- cli.warn project['name']
26
+ warn(project["name"])
27
27
 
28
28
  task = select_task
29
29
 
@@ -31,42 +31,47 @@ module Abt
31
31
 
32
32
  return if flags[:"dry-run"]
33
33
 
34
- config.project_gid = project_gid # We might have gotten the project ID as an argument
35
- config.task_gid = task['gid']
34
+ config.path = Path.from_ids(project_gid, task["gid"])
36
35
  end
37
36
 
38
37
  private
39
38
 
40
39
  def project
41
- @project ||= api.get("projects/#{project_gid}")
40
+ @project ||= api.get("projects/#{project_gid}", opt_fields: "name")
42
41
  end
43
42
 
44
43
  def select_task
45
44
  loop do
46
- section = cli.prompt.choice 'Which section?', sections
47
- cli.warn 'Fetching tasks...'
45
+ section = cli.prompt.choice("Which section?", sections)
46
+ warn("Fetching tasks...")
48
47
  tasks = tasks_in_section(section)
49
48
 
50
49
  if tasks.length.zero?
51
- cli.warn 'Section is empty'
50
+ warn("Section is empty")
52
51
  next
53
52
  end
54
53
 
55
- task = cli.prompt.choice 'Select a task', tasks, true
54
+ task = cli.prompt.choice("Select a task", tasks, nil_option: true)
56
55
  return task if task
57
56
  end
58
57
  end
59
58
 
60
59
  def tasks_in_section(section)
61
- api.get_paged('tasks', section: section['gid'], opt_fields: 'name,permalink_url')
60
+ tasks = api.get_paged(
61
+ "tasks",
62
+ section: section["gid"],
63
+ opt_fields: "name,completed,permalink_url"
64
+ )
65
+
66
+ # The below filtering is the best we can do with Asanas api, see this:
67
+ # https://forum.asana.com/t/tasks-query-completed-since-is-broken-for-sections/21461
68
+ tasks.reject { |task| task["completed"] }
62
69
  end
63
70
 
64
71
  def sections
65
72
  @sections ||= begin
66
- cli.warn 'Fetching sections...'
67
- api.get_paged("projects/#{project_gid}/sections", opt_fields: 'name')
68
- rescue Abt::HttpError::HttpError
69
- []
73
+ warn("Fetching sections...")
74
+ api.get_paged("projects/#{project_gid}/sections", opt_fields: "name")
70
75
  end
71
76
  end
72
77
  end
@@ -6,11 +6,11 @@ module Abt
6
6
  module Commands
7
7
  class Projects < BaseCommand
8
8
  def self.usage
9
- 'abt projects asana'
9
+ "abt projects asana"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'List all available projects - useful for piping into grep etc.'
13
+ "List all available projects - useful for piping into grep etc."
14
14
  end
15
15
 
16
16
  def perform
@@ -23,12 +23,12 @@ module Abt
23
23
 
24
24
  def projects
25
25
  @projects ||= begin
26
- cli.warn 'Fetching projects...'
26
+ warn("Fetching projects...")
27
27
  api.get_paged(
28
- 'projects',
28
+ "projects",
29
29
  workspace: config.workspace_gid,
30
30
  archived: false,
31
- opt_fields: 'name'
31
+ opt_fields: "name"
32
32
  )
33
33
  end
34
34
  end
@@ -6,20 +6,18 @@ module Abt
6
6
  module Commands
7
7
  class Share < BaseCommand
8
8
  def self.usage
9
- 'abt share asana[:<project-gid>[/<task-gid>]]'
9
+ "abt share asana[:<project-gid>[/<task-gid>]]"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Print project/task config string'
13
+ "Print project/task ARI"
14
14
  end
15
15
 
16
16
  def perform
17
- require_project!
18
-
19
- if task_gid.nil?
20
- cli.print_scheme_argument('asana', project_gid)
21
- else
22
- cli.print_scheme_argument('asana', "#{project_gid}/#{task_gid}")
17
+ if path != ""
18
+ cli.print_ari("asana", path)
19
+ elsif cli.output.isatty
20
+ warn("No configuration for project. Did you initialize Asana?")
23
21
  end
24
22
  end
25
23
  end
@@ -6,26 +6,27 @@ module Abt
6
6
  module Commands
7
7
  class Start < BaseCommand
8
8
  def self.usage
9
- 'abt start asana[:<project-gid>/<task-gid>]'
9
+ "abt start asana[:<project-gid>/<task-gid>]"
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Move current or specified task to WIP section (column) and assign it to you'
13
+ "Move current or specified task to WIP section (column) and assign it to you"
14
14
  end
15
15
 
16
16
  def self.flags
17
17
  [
18
- ['-s', '--set', 'Set specified task as current']
18
+ ["-s", "--set", "Set specified task as current"]
19
19
  ]
20
20
  end
21
21
 
22
22
  def perform
23
23
  require_task!
24
24
 
25
- maybe_override_current_task
25
+ print_task(project_gid, task)
26
26
 
27
27
  update_assignee_if_needed
28
28
  move_if_needed
29
+ maybe_override_current_task
29
30
  end
30
31
 
31
32
  private
@@ -33,36 +34,37 @@ module Abt
33
34
  def maybe_override_current_task
34
35
  return unless flags[:set]
35
36
  return if path.nil?
36
- return if same_args_as_config?
37
+ return if path == config.path
37
38
  return unless config.local_available?
38
39
 
39
- Current.new(path: path, cli: cli).call
40
+ config.path = path
41
+ warn("Current task updated")
40
42
  end
41
43
 
42
44
  def update_assignee_if_needed
43
- current_assignee = task.dig('assignee')
45
+ current_assignee = task["assignee"]
44
46
 
45
47
  if current_assignee.nil?
46
- cli.warn "Assigning task to user: #{current_user['name']}"
48
+ warn("Assigning task to user: #{current_user['name']}")
47
49
  update_assignee
48
- elsif current_assignee['gid'] == current_user['gid']
49
- cli.warn 'You are already assigned to this task'
50
- elsif cli.prompt.boolean "Task is assigned to: #{current_assignee['name']}, take over?"
51
- cli.warn "Reassigning task to user: #{current_user['name']}"
50
+ elsif current_assignee["gid"] == current_user["gid"]
51
+ warn("You are already assigned to this task")
52
+ elsif cli.prompt.boolean("Task is assigned to: #{current_assignee['name']}, take over?")
53
+ warn("Reassigning task to user: #{current_user['name']}")
52
54
  update_assignee
53
55
  end
54
56
  end
55
57
 
56
58
  def move_if_needed
57
- unless project_gid == config.project_gid
58
- cli.warn 'Task was not moved, this is not implemented for tasks outside current project'
59
+ unless project_gid == config.path.project_gid
60
+ warn("Task was not moved, this is not implemented for tasks outside current project")
59
61
  return
60
62
  end
61
63
 
62
64
  if task_already_in_wip_section?
63
- cli.warn "Task already in section: #{current_task_section['name']}"
65
+ warn("Task already in section: #{current_task_section['name']}")
64
66
  else
65
- cli.warn "Moving task to section: #{wip_section['name']}"
67
+ warn("Moving task to section: #{wip_section['name']}")
66
68
  move_task
67
69
  end
68
70
  end
@@ -72,17 +74,17 @@ module Abt
72
74
  end
73
75
 
74
76
  def current_task_section
75
- task_section_membership&.dig('section')
77
+ task_section_membership&.dig("section")
76
78
  end
77
79
 
78
80
  def task_section_membership
79
- task['memberships'].find do |membership|
80
- membership.dig('section', 'gid') == config.wip_section_gid
81
+ task["memberships"].find do |membership|
82
+ membership.dig("section", "gid") == config.wip_section_gid
81
83
  end
82
84
  end
83
85
 
84
86
  def wip_section
85
- @wip_section ||= api.get("sections/#{config.wip_section_gid}")
87
+ @wip_section ||= api.get("sections/#{config.wip_section_gid}", opt_fields: "name")
86
88
  end
87
89
 
88
90
  def move_task
@@ -92,17 +94,18 @@ module Abt
92
94
  end
93
95
 
94
96
  def update_assignee
95
- body = { data: { assignee: current_user['gid'] } }
97
+ body = { data: { assignee: current_user["gid"] } }
96
98
  body_json = Oj.dump(body, mode: :json)
97
99
  api.put("tasks/#{task_gid}", body_json)
98
100
  end
99
101
 
100
102
  def current_user
101
- @current_user ||= api.get('users/me', opt_fields: 'name')
103
+ @current_user ||= api.get("users/me", opt_fields: "name")
102
104
  end
103
105
 
104
106
  def task
105
- @task ||= api.get("tasks/#{task_gid}", opt_fields: 'name,memberships.section.name,assignee.name')
107
+ @task ||= api.get("tasks/#{task_gid}",
108
+ opt_fields: "name,memberships.section.name,assignee.name,permalink_url")
106
109
  end
107
110
  end
108
111
  end