abt-cli 0.0.13 → 0.0.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f61e3ba3cf1e1f6b5b69502861814a80b763849a7a9e8d654a593b55bf53b1bb
4
- data.tar.gz: 497d18071f5a32cc4df92d2075a097452ffa2ffbf7f97ab98916678e6c92fa31
3
+ metadata.gz: d6355433a65cf9e49738ab971a8886e657cefff8d3a8322e44d140a18fa7a6be
4
+ data.tar.gz: f71c9909c3c8063f24365d80db1ae91223876be98cda4e6681a5f37e017af2ca
5
5
  SHA512:
6
- metadata.gz: fa028736b67c70cd694a6e75665136e7829865d7afe66828262eae903aa553d5dc92478957e9e36526669f96fde1aa42ccab0036e2c1319f6db6cc47cfd033e4
7
- data.tar.gz: 01af79206699568177e2548cd2662012f63ea996c6289a7dc49795fb99f06ff157692a51df444505336c3851a1f562a63fef659ca046e03579e11123b1e8a7ba
6
+ metadata.gz: 809f27b09f6bbf41eefca395f95621b9bd7c48cb3f78cd5e7bf62c48a87895669fa74aebad4ea31fdee6ed484bf8944bb6216059b93066db2cfe118bc65c6e34
7
+ data.tar.gz: '032284e3f7e465618c2c039dbafa84855548bcee41d56725606fd2b48e58c008ba89010be8c25e78f714f3c1e16cc8a30f3e8021a0a5a531617dc0d54393ce1e'
data/lib/abt.rb CHANGED
@@ -11,6 +11,8 @@ Dir.glob("#{File.dirname(File.absolute_path(__FILE__))}/abt/*.rb").sort.each do
11
11
  end
12
12
 
13
13
  module Abt
14
+ module Providers; end
15
+
14
16
  def self.provider_names
15
17
  Providers.constants.sort.map { |constant_name| Helpers.const_to_command(constant_name) }
16
18
  end
@@ -36,19 +36,17 @@ module Abt
36
36
  set(key, value)
37
37
  end
38
38
 
39
- def full_keys
40
- if scope == 'local' && !self.class.local_available?
41
- raise StandardError, 'Local configuration is not available outside a git repository'
42
- end
43
-
44
- `git config --#{scope} --get-regexp --name-only ^#{namespace}`.lines.map(&:strip)
45
- end
46
-
47
39
  def keys
48
40
  offset = namespace.length + 1
49
41
  full_keys.map { |key| key[offset..-1] }
50
42
  end
51
43
 
44
+ def full_keys
45
+ ensure_scope_available!
46
+
47
+ `git config --#{scope} --get-regexp --name-only ^#{namespace}`.lines.map(&:strip)
48
+ end
49
+
52
50
  def local
53
51
  @local ||= begin
54
52
  if scope == 'local'
@@ -71,23 +69,25 @@ module Abt
71
69
 
72
70
  private
73
71
 
72
+ def ensure_scope_available!
73
+ return if scope != 'local' || self.class.local_available?
74
+
75
+ raise StandardError, 'Local configuration is not available outside a git repository'
76
+ end
77
+
74
78
  def key_with_namespace(key)
75
79
  namespace.empty? ? key : "#{namespace}.#{key}"
76
80
  end
77
81
 
78
82
  def get(key)
79
- if scope == 'local' && !self.class.local_available?
80
- raise StandardError, 'Local configuration is not available outside a git repository'
81
- end
83
+ ensure_scope_available!
82
84
 
83
85
  git_value = `git config --#{scope} --get #{key_with_namespace(key).inspect}`.strip
84
86
  git_value.empty? ? nil : git_value
85
87
  end
86
88
 
87
89
  def set(key, value)
88
- if scope == 'local' && !self.class.local_available?
89
- raise StandardError, 'Local configuration is not available outside a git repository'
90
- end
90
+ ensure_scope_available!
91
91
 
92
92
  if value.nil? || value.empty?
93
93
  `git config --#{scope} --unset #{key_with_namespace(key).inspect}`
data/lib/abt/helpers.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Abt
4
4
  module Helpers
5
5
  def self.const_to_command(string)
6
- string = string.to_s
6
+ string = string.to_s.dup
7
7
  string[0] = string[0].downcase
8
8
  string.gsub(/([A-Z])/, '-\1').downcase
9
9
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Asana
6
+ module Commands
7
+ class BranchName < BaseCommand
8
+ def self.command
9
+ 'branch-name asana[:<project-gid>/<task-gid>]'
10
+ end
11
+
12
+ def self.description
13
+ 'Suggest a git branch name for the current/specified task.'
14
+ end
15
+
16
+ def call
17
+ require_task!
18
+ ensure_current_is_valid!
19
+
20
+ cli.puts name
21
+ end
22
+
23
+ private
24
+
25
+ def name
26
+ task['name'].downcase.gsub(/[^\w]+/, '-')
27
+ end
28
+
29
+ def ensure_current_is_valid!
30
+ cli.abort "Invalid task gid: #{task_gid}" if task.nil?
31
+
32
+ return if task['memberships'].any? { |m| m.dig('project', 'gid') == project_gid }
33
+
34
+ cli.abort "Invalid project gid: #{project_gid}"
35
+ end
36
+
37
+ def task
38
+ @task ||= api.get("tasks/#{task_gid}", opt_fields: 'name,memberships.project')
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Devops
6
+ module Commands
7
+ class BranchName < BaseCommand
8
+ def self.command
9
+ 'branch-name devops[:<organization-name>/<project-name>/<board-id>/<work-item-id>]'
10
+ end
11
+
12
+ def self.description
13
+ 'Suggest a git branch name for the current/specified work-item.'
14
+ end
15
+
16
+ def call
17
+ require_work_item!
18
+
19
+ cli.puts name
20
+ rescue HttpError::NotFoundError
21
+ args = [organization_name, project_name, board_id, work_item_id].compact
22
+ cli.warn 'Unable to find work item for configuration:'
23
+ cli.abort "devops:#{args.join('/')}"
24
+ end
25
+
26
+ private
27
+
28
+ def name
29
+ str = work_item['id']
30
+ str += '-'
31
+ str += work_item['name'].downcase.gsub(/[^\w]/, '-')
32
+ str.gsub(/-+/, '-')
33
+ end
34
+
35
+ def work_item
36
+ @work_item ||= begin
37
+ work_item = api.get_paged('wit/workitems', ids: work_item_id)[0]
38
+ sanitize_work_item(work_item)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob("#{File.expand_path(__dir__)}/git/*.rb").sort.each { |file| require file }
4
+ Dir.glob("#{File.expand_path(__dir__)}/git/commands/*.rb").sort.each { |file| require file }
5
+
6
+ module Abt
7
+ module Providers
8
+ module Git
9
+ def self.command_names
10
+ Commands.constants.sort.map { |constant_name| Helpers.const_to_command(constant_name) }
11
+ end
12
+
13
+ def self.command_class(name)
14
+ const_name = Helpers.command_to_const(name)
15
+ Commands.const_get(const_name) if Commands.const_defined?(const_name)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Git
6
+ module Commands
7
+ class Branch
8
+ attr_reader :cli
9
+
10
+ def self.command
11
+ 'branch git <provider>'
12
+ end
13
+
14
+ def self.description
15
+ 'Switch branch. Uses a compatible provider to generate the branch-name: E.g. `abt branch git asana`'
16
+ end
17
+
18
+ def initialize(cli:, **)
19
+ @cli = cli
20
+ end
21
+
22
+ def call
23
+ create_and_switch unless switch
24
+ cli.warn "Switched to #{branch_name}"
25
+ end
26
+
27
+ private
28
+
29
+ def switch
30
+ success = false
31
+ Open3.popen3("git switch #{branch_name}") do |_i, _o, _error_output, thread|
32
+ success = thread.value.success?
33
+ end
34
+ success
35
+ end
36
+
37
+ def create_and_switch
38
+ cli.warn "No such branch: #{branch_name}"
39
+ cli.abort('Aborting') unless cli.prompt_boolean 'Create branch?'
40
+
41
+ Open3.popen3("git switch -c #{branch_name}") do |_i, _o, _e, thread|
42
+ thread.value
43
+ end
44
+ end
45
+
46
+ def branch_name # rubocop:disable Metrics/MethodLength
47
+ @branch_name ||= begin
48
+ if branch_names_from_providers.empty?
49
+ cli.abort [
50
+ 'None of the specified providers responded to `branch-name`.',
51
+ 'Did you add compatible provider? e.g.:',
52
+ ' abt branch git asana',
53
+ ' abt branch git devops'
54
+ ].join("\n")
55
+ end
56
+
57
+ if branch_names_from_providers.length > 1
58
+ cli.abort [
59
+ 'Got branch names from multiple providers, only one is supported',
60
+ 'Branch names where:',
61
+ *branch_names_from_providers.map { |name| " #{name}" }
62
+ ].join("\n")
63
+ end
64
+
65
+ branch_names_from_providers.first
66
+ end
67
+ end
68
+
69
+ def branch_names_from_providers
70
+ input = StringIO.new(cli.args.join(' '))
71
+ output = StringIO.new
72
+ Abt::Cli.new(argv: ['branch-name'], output: output, input: input).perform
73
+
74
+ output.string.lines.map(&:strip).compact
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ 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.13'
4
+ VERSION = '0.0.14'
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.13
4
+ version: 0.0.14
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-02-02 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -89,6 +89,7 @@ files:
89
89
  - "./lib/abt/providers/asana/api.rb"
90
90
  - "./lib/abt/providers/asana/base_command.rb"
91
91
  - "./lib/abt/providers/asana/commands/add.rb"
92
+ - "./lib/abt/providers/asana/commands/branch-name.rb"
92
93
  - "./lib/abt/providers/asana/commands/clear.rb"
93
94
  - "./lib/abt/providers/asana/commands/clear_global.rb"
94
95
  - "./lib/abt/providers/asana/commands/current.rb"
@@ -105,6 +106,7 @@ files:
105
106
  - "./lib/abt/providers/devops/api.rb"
106
107
  - "./lib/abt/providers/devops/base_command.rb"
107
108
  - "./lib/abt/providers/devops/commands/boards.rb"
109
+ - "./lib/abt/providers/devops/commands/branch-name.rb"
108
110
  - "./lib/abt/providers/devops/commands/clear.rb"
109
111
  - "./lib/abt/providers/devops/commands/clear_global.rb"
110
112
  - "./lib/abt/providers/devops/commands/current.rb"
@@ -114,6 +116,8 @@ files:
114
116
  - "./lib/abt/providers/devops/commands/share.rb"
115
117
  - "./lib/abt/providers/devops/commands/work-items.rb"
116
118
  - "./lib/abt/providers/devops/configuration.rb"
119
+ - "./lib/abt/providers/git.rb"
120
+ - "./lib/abt/providers/git/commands/branch.rb"
117
121
  - "./lib/abt/providers/harvest.rb"
118
122
  - "./lib/abt/providers/harvest/api.rb"
119
123
  - "./lib/abt/providers/harvest/base_command.rb"