abt-cli 0.0.27 → 0.0.28

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: 0bffe51f05670b4fcbf1bf2a023c354e26a387b0a74fd34751ef180b1f619c62
4
- data.tar.gz: 7e5c476b8e1b803adfbb92590676c883e66a6ac74b5111e83aed9f4d6b9feb8a
3
+ metadata.gz: 5dd7a6d58fed695f167581c8c7b16578b1e0f29664319c1b3594235e07bfc179
4
+ data.tar.gz: 48e88420bd4e7b7dd2c99ac82cfcc7ada1120637f9f7b08c39fa9abf128ebefe
5
5
  SHA512:
6
- metadata.gz: 9dba1d7966f28966e5fe8d33fd3b380e823f707536b86e1f21a82bfdb74e20ba4d76b2c08e1fb9da9b7f1dc1d74ea6a787979b6ae86ca59b3ce9305964f7a063
7
- data.tar.gz: 33b61911f3018b0e51ece32264c98f8327af60fcfb94bb59e4d210171bf8562fb885c120be565f79a827dd7f35c72d4d91acf48aa8497079107e120d8e4535bf
6
+ metadata.gz: d8e7534007c20d2f16099e453d8d7fdaae042f4f658ef111c4a7d2ec25dee13d9e6c7ed511de57ba14e249c1043129cb540742a5746ee32c6ed51c419470e756
7
+ data.tar.gz: 28173fc0ea536fdfd3c787e18abf4ed27818f9a47d4e69bfa2c25c6f5a00ef12e586378dec0be4e21b61cb198e24ab8ba36c1289ccc0b90f0f009d88000ba5e3
data/lib/abt.rb CHANGED
@@ -23,8 +23,4 @@ module Abt
23
23
  const_name = Helpers.command_to_const(scheme)
24
24
  Providers.const_get(const_name) if Providers.const_defined?(const_name)
25
25
  end
26
-
27
- def self.directory_config
28
- @directory_config ||= Abt::DirectoryConfig.new
29
- end
30
26
  end
data/lib/abt/cli.rb CHANGED
@@ -62,6 +62,10 @@ module Abt
62
62
  @aris ||= ArgumentsParser.new(sanitized_piped_args + remaining_args).parse
63
63
  end
64
64
 
65
+ def directory_config
66
+ @directory_config ||= Abt::DirectoryConfig.new
67
+ end
68
+
65
69
  private
66
70
 
67
71
  def alias?
@@ -69,7 +73,7 @@ module Abt
69
73
  end
70
74
 
71
75
  def process_alias
72
- matching_alias = Abt.directory_config.dig("aliases", command[1..-1])
76
+ matching_alias = directory_config.dig("aliases", command[1..-1])
73
77
 
74
78
  abort("No such alias #{command}") if matching_alias.nil?
75
79
 
@@ -2,24 +2,42 @@
2
2
 
3
3
  module Abt
4
4
  class DirectoryConfig < Hash
5
+ FILE_NAME = ".abt.yml"
6
+
5
7
  def initialize
6
8
  super
7
- merge!(YAML.load_file(config_file_path)) if config_file_path
9
+ load! if config_file_path && File.exist?(config_file_path)
8
10
  end
9
11
 
10
- private
12
+ def available?
13
+ !config_file_path.nil?
14
+ end
11
15
 
12
- def config_file_path
13
- dir = Dir.pwd
16
+ def load!
17
+ merge!(YAML.load_file(config_file_path))
18
+ end
14
19
 
15
- until File.exist?(File.join(dir, ".abt.yml"))
16
- next_dir = File.expand_path("..", dir)
17
- return if next_dir == dir
20
+ def save!
21
+ raise Abt::Cli::Abort("Configuration files are not available outside of git repositories") unless available?
18
22
 
19
- dir = next_dir
20
- end
23
+ config_file = File.open(config_file_path, "w")
24
+ YAML.dump(to_h, config_file)
25
+ config_file.close
26
+ end
27
+
28
+ private
21
29
 
22
- File.join(dir, ".abt.yml")
30
+ def config_file_path
31
+ @config_file_path ||= begin
32
+ path = nil
33
+ Open3.popen3("git rev-parse --show-toplevel") do |_i, output, _e, thread|
34
+ if thread.value.success?
35
+ repo_root = output.read.chomp
36
+ path = File.join(repo_root, FILE_NAME)
37
+ end
38
+ end
39
+ path
40
+ end
23
41
  end
24
42
  end
25
43
  end
@@ -58,10 +58,8 @@ module Abt
58
58
  end
59
59
 
60
60
  def task
61
- @task ||= begin
62
- api.get("tasks/#{task_gid}",
63
- opt_fields: "name,memberships.section.name,permalink_url")
64
- end
61
+ @task ||= api.get("tasks/#{task_gid}",
62
+ opt_fields: "name,memberships.section.name,permalink_url")
65
63
  end
66
64
  end
67
65
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Asana
6
+ module Commands
7
+ class WriteConfig < BaseCommand
8
+ def self.usage
9
+ "abt write-config asana[:<project-gid>]"
10
+ end
11
+
12
+ def self.description
13
+ "Write Asana settings to .abt.yml"
14
+ end
15
+
16
+ def self.flags
17
+ [
18
+ ["-c", "--clean", "Don't reuse project configuration"]
19
+ ]
20
+ end
21
+
22
+ def perform
23
+ cli.directory_config["asana"] = config_data
24
+ cli.directory_config.save!
25
+
26
+ warn("Asana configuration written to #{Abt::DirectoryConfig::FILE_NAME}")
27
+ end
28
+
29
+ private
30
+
31
+ def config_data
32
+ {
33
+ "path" => project_gid,
34
+ "wip_section_gid" => wip_section_gid,
35
+ "finalized_section_gid" => finalized_section_gid
36
+ }
37
+ end
38
+
39
+ def project_gid
40
+ @project_gid ||= begin
41
+ prompt_project! if super.nil? || flags[:clean]
42
+
43
+ super
44
+ end
45
+ end
46
+
47
+ def wip_section_gid
48
+ return config.wip_section_gid if use_previous_config?
49
+
50
+ cli.prompt.choice("Select WIP (Work In Progress) section", sections)["gid"]
51
+ end
52
+
53
+ def finalized_section_gid
54
+ return config.finalized_section_gid if use_previous_config?
55
+
56
+ cli.prompt.choice('Select section for finalized tasks (E.g. "Merged")', sections)["gid"]
57
+ end
58
+
59
+ def use_previous_config?
60
+ project_gid == config.path.project_gid
61
+ end
62
+
63
+ def sections
64
+ @sections ||= begin
65
+ warn("Fetching sections...")
66
+ api.get_paged("projects/#{project_gid}/sections", opt_fields: "name")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -71,7 +71,7 @@ module Abt
71
71
  private
72
72
 
73
73
  def directory_config
74
- Abt.directory_config.fetch("asana", {})
74
+ cli.directory_config.fetch("asana", {})
75
75
  end
76
76
 
77
77
  def git
@@ -28,7 +28,7 @@ module Abt
28
28
  private
29
29
 
30
30
  def match
31
- @match ||= PATH_REGEX.match(self)
31
+ @match ||= PATH_REGEX.match(to_s)
32
32
  end
33
33
  end
34
34
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Devops
6
+ module Commands
7
+ class WriteConfig < BaseCommand
8
+ def self.usage
9
+ "abt write-config devops[:<organization-name>/<project-name>/<board-id>]"
10
+ end
11
+
12
+ def self.description
13
+ "Write DevOps settings to .abt.yml"
14
+ end
15
+
16
+ def self.flags
17
+ [
18
+ ["-c", "--clean", "Don't reuse configuration"]
19
+ ]
20
+ end
21
+
22
+ def perform
23
+ prompt_project! if project_name.nil? || flags[:clean]
24
+ prompt_board! if board_id.nil? || flags[:clean]
25
+
26
+ update_directory_config!
27
+
28
+ warn("DevOps configuration written to #{Abt::DirectoryConfig::FILE_NAME}")
29
+ end
30
+
31
+ private
32
+
33
+ def update_directory_config!
34
+ cli.directory_config["devops"] = {
35
+ "path" => Path.from_ids(
36
+ organization_name: organization_name,
37
+ project_name: project_name,
38
+ board_id: board_id
39
+ ).to_s
40
+ }
41
+ cli.directory_config.save!
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -15,7 +15,7 @@ module Abt
15
15
  end
16
16
 
17
17
  def path
18
- Path.new(local_available? && git["path"] || Abt.directory_config.dig("devops", "path") || "")
18
+ Path.new(local_available? && git["path"] || cli.directory_config.dig("devops", "path") || "")
19
19
  end
20
20
 
21
21
  def path=(new_path)
@@ -43,7 +43,7 @@ module Abt
43
43
  private
44
44
 
45
45
  def match
46
- @match ||= PATH_REGEX.match(self)
46
+ @match ||= PATH_REGEX.match(to_s)
47
47
  end
48
48
  end
49
49
  end
@@ -37,15 +37,11 @@ module Abt
37
37
  private
38
38
 
39
39
  def project_name
40
- @project_name ||= begin
41
- project_url_match && project_url_match[:project]
42
- end
40
+ @project_name ||= project_url_match && project_url_match[:project]
43
41
  end
44
42
 
45
43
  def organization_name
46
- @organization_name ||= begin
47
- project_url_match && project_url_match[:organization]
48
- end
44
+ @organization_name ||= project_url_match && project_url_match[:organization]
49
45
  end
50
46
 
51
47
  def project_url_match
@@ -53,14 +49,12 @@ module Abt
53
49
  end
54
50
 
55
51
  def project_url
56
- @project_url ||= begin
57
- loop do
58
- url = prompt_url
52
+ @project_url ||= loop do
53
+ url = prompt_url
59
54
 
60
- break url if AZURE_DEV_URL_REGEX =~ url || VS_URL_REGEX =~ url
55
+ break url if AZURE_DEV_URL_REGEX =~ url || VS_URL_REGEX =~ url
61
56
 
62
- cli.warn("Invalid URL")
63
- end
57
+ cli.warn("Invalid URL")
64
58
  end
65
59
  end
66
60
 
@@ -22,10 +22,8 @@ module Abt
22
22
  private
23
23
 
24
24
  def projects
25
- @projects ||= begin
26
- project_assignments.map do |project_assignment|
27
- project_assignment["project"].merge("client" => project_assignment["client"])
28
- end
25
+ @projects ||= project_assignments.map do |project_assignment|
26
+ project_assignment["project"].merge("client" => project_assignment["client"])
29
27
  end
30
28
  end
31
29
  end
@@ -24,9 +24,7 @@ module Abt
24
24
  private
25
25
 
26
26
  def tasks
27
- @tasks ||= begin
28
- project_assignment["task_assignments"].map { |ta| ta["task"] }
29
- end
27
+ @tasks ||= project_assignment["task_assignments"].map { |ta| ta["task"] }
30
28
  end
31
29
  end
32
30
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Harvest
6
+ module Commands
7
+ class WriteConfig < BaseCommand
8
+ def self.usage
9
+ "abt write-config harvest[:<project-id>[/<task-id>]]"
10
+ end
11
+
12
+ def self.description
13
+ "Write Harvest settings to .abt.yml"
14
+ end
15
+
16
+ def self.flags
17
+ [
18
+ ["-c", "--clean", "Don't reuse configuration"]
19
+ ]
20
+ end
21
+
22
+ def perform
23
+ prompt_project! if project_id.nil? || flags[:clean]
24
+ prompt_task! if task_id.nil? || flags[:clean]
25
+
26
+ update_directory_config!
27
+
28
+ warn("Harvest configuration written to #{Abt::DirectoryConfig::FILE_NAME}")
29
+ end
30
+
31
+ private
32
+
33
+ def update_directory_config!
34
+ cli.directory_config["harvest"] = { "path" => path.to_s }
35
+ cli.directory_config.save!
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -15,7 +15,7 @@ module Abt
15
15
  end
16
16
 
17
17
  def path
18
- Path.new(local_available? && git["path"] || Abt.directory_config.dig("harvest", "path") || "")
18
+ Path.new(local_available? && git["path"] || cli.directory_config.dig("harvest", "path") || "")
19
19
  end
20
20
 
21
21
  def path=(new_path)
@@ -28,7 +28,7 @@ module Abt
28
28
  private
29
29
 
30
30
  def match
31
- @match ||= PATH_REGEX.match(self)
31
+ @match ||= PATH_REGEX.match(to_s)
32
32
  end
33
33
  end
34
34
  end
data/lib/abt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Abt
4
- VERSION = "0.0.27"
4
+ VERSION = "0.0.28"
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.27
4
+ version: 0.0.28
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-03-26 00:00:00.000000000 Z
11
+ date: 2021-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -110,6 +110,7 @@ files:
110
110
  - "./lib/abt/providers/asana/commands/share.rb"
111
111
  - "./lib/abt/providers/asana/commands/start.rb"
112
112
  - "./lib/abt/providers/asana/commands/tasks.rb"
113
+ - "./lib/abt/providers/asana/commands/write_config.rb"
113
114
  - "./lib/abt/providers/asana/configuration.rb"
114
115
  - "./lib/abt/providers/asana/path.rb"
115
116
  - "./lib/abt/providers/asana/services/project_picker.rb"
@@ -125,6 +126,7 @@ files:
125
126
  - "./lib/abt/providers/devops/commands/pick.rb"
126
127
  - "./lib/abt/providers/devops/commands/share.rb"
127
128
  - "./lib/abt/providers/devops/commands/work_items.rb"
129
+ - "./lib/abt/providers/devops/commands/write_config.rb"
128
130
  - "./lib/abt/providers/devops/configuration.rb"
129
131
  - "./lib/abt/providers/devops/path.rb"
130
132
  - "./lib/abt/providers/devops/services/board_picker.rb"
@@ -144,6 +146,7 @@ files:
144
146
  - "./lib/abt/providers/harvest/commands/stop.rb"
145
147
  - "./lib/abt/providers/harvest/commands/tasks.rb"
146
148
  - "./lib/abt/providers/harvest/commands/track.rb"
149
+ - "./lib/abt/providers/harvest/commands/write_config.rb"
147
150
  - "./lib/abt/providers/harvest/configuration.rb"
148
151
  - "./lib/abt/providers/harvest/path.rb"
149
152
  - "./lib/abt/providers/harvest/services/project_picker.rb"