branch-name 3.0.0 → 3.2.2

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: ecf9d15cb3f6a7be37ca9d39377e9d8c103b71557ae26a01dbf19670ce3c9548
4
- data.tar.gz: 2ee162f10d1bd5bf48cde5e2d7611241600030098b9e50331472eef08077bbad
3
+ metadata.gz: 589277a07c2a1a873385e77be6276f7b0f2aaecbe6d5047b4f6e56e436ffcf8a
4
+ data.tar.gz: a185c55be39afb5611b25cecd50d39a761c0fedef40bf96b4927fd3e410ac3a2
5
5
  SHA512:
6
- metadata.gz: d7dd261862332096d9dd74d38ade8fd517b72ea07fe867a8d2b2b6cbf367b13e296ce2f8fc35cd9bd2a697e53a51d39edc842ca9ad644a6ece15dcd4e0c0b3ac
7
- data.tar.gz: cba46ce2945c423427d1e39930d9695841a0153fa041d61899f90b396a156162a4dcce047f1c04d1b131ce7573aa497b3f351538d8d12f6bc7820fcf2fe39b6e
6
+ metadata.gz: 5418d3f1ad7aa1cdc5ab523fb1824ffcf022c5c16ad54d3f9be773eaa4f02b3ba5f040ab2b3b5f5a8f7c0aecbe58dc2be848464f5409f68468cfb0059b222e49
7
+ data.tar.gz: eb1fc297bdd508848208e8b95a389d0ac8ff37e9c2310a865a209587ea42377206c17543595790ac7dabb8f90ac73171a0160c7fd4e3d3359ac963e7dc2679cd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
- ## ['3.0.0'] - 2022-09-26
1
+ ## ['3.2.2'] - 2022-09-27
2
+ * Changes:
3
+ * Refactor code that patches Thor incorrect display of nested commands (subcommangs).
4
+
5
+ ## ['3.2.1'] - 2022-09-27
6
+ * Changes:
7
+ * Fix rubocop violations.
8
+ * Miscellaneous mixin refactors.
9
+ * Bug Fixes: Fix bug that displayed subcommand help incorrectly.
10
+
11
+ ## ['3.1.0'] - 2022-09-26
2
12
  * Enhancements:
13
+ * Branch names may now be created using a forward-slash (/). See the README.md file for more information.
14
+ * The `branch-name create :format_string` option string now accepts a %u placeholder which will be replaced with the currently logged in username. See `$ branch-name help create` for more information.
15
+
16
+ ## ['3.0.0'] - 2022-09-26
3
17
  * Changes:
4
18
  * Default default commands to :help.
5
19
  * Remove references to system for options, folder locations, etc. These were not being used and the nature of this tool is that global options should suffice.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (3.0.0)
4
+ branch-name (3.2.2)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
7
  os (~> 1.1, >= 1.1.4)
data/README.md CHANGED
@@ -93,6 +93,7 @@ NOTE: The below examples will assume the following `global` config file defaults
93
93
  create:
94
94
  downcase: false
95
95
  separator: _
96
+ format_string: "%t %d"
96
97
  project: false
97
98
  project_location: "/Users/<username>/feature-branches/%Y"
98
99
  project_files:
@@ -112,6 +113,27 @@ This example simply formulates feature a branch named *Add_create_and_destroy_se
112
113
  ```shell
113
114
  $ branch-name create "Add #create and #destroy session controller actions"
114
115
  ```
116
+ #### Creating a Branch Name that Contains Forward-Slashes (`/`)
117
+
118
+ This can be accomplished in different ways; here are some examples:
119
+
120
+ Embed the forward-slashes using the `--format-string/-x` option:
121
+
122
+ ```shell
123
+ $ branch-name create -x "%u/%t %d" "Remove debug code" UX-54321
124
+ #=> Branch name: <username>/ux-54321-remove-debug-code
125
+ ...
126
+ ```
127
+
128
+ Embed the forward-slashes in the ticket description itself. Depending on *where* you want your forward-slashes to appear, you'll have to place them appropriately:
129
+
130
+ ```shell
131
+ $ branch-name create "<username>/UX-54321 Remove debug code"
132
+ #=> Branch name: <username>/ux-54321-remove-debug-code
133
+ ...
134
+ ```
135
+
136
+ NOTE: Project folders created (`--project/-p`) will replace any forward-slash with the `create: :separator` option value.
115
137
 
116
138
  ## Development
117
139
 
@@ -72,11 +72,14 @@ module Branch
72
72
  The default is: "#{Locatable.project_folder(options: options)}".
73
73
 
74
74
  \x5 -x FORMAT_STRING: This is a string that determines the format of the branch name
75
- that is formulated. The following are a list of required placeholders you must put
76
- in your format string to format the brach name: [%t, %d].
75
+ that is formulated. The following is a list of required placeholders you must put
76
+ in your format string to format the branch name: [%t, %d].
77
77
  \x5Where %t will be replaced by the ticket.
78
78
  \x5Where %d will be replaced by the ticket description.
79
- \x5The default is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
79
+ \x5The following is a list of optional placeholders you may put
80
+ in your format string to format the branch name: [%u].
81
+ \x5Where %u will be replaced with your username (`Etc.getlogin`, https://rubygems.org/gems/etc).
82
+ \x5The default format string is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
80
83
  LONG_DESC
81
84
  method_option :downcase, type: :boolean, aliases: '-d'
82
85
  method_option :separator, type: :string, aliases: '-s'
@@ -97,12 +100,18 @@ module Branch
97
100
  say_error error.message
98
101
  exit 1
99
102
  end
100
-
101
103
  say "Branch name: #{branch_name}", :cyan
102
104
 
103
- say "\"#{branch_name}\" has been copied to the clipboard!", :green if copy_to_clipboard branch_name
105
+ if options[:project]
106
+ project_folder = project_folder_from(branch_name) do |error|
107
+ say_error error.message
108
+ exit 1
109
+ end
110
+ say "Project folder name: #{project_folder}", :cyan
111
+ create_project!(project_folder)
112
+ end
104
113
 
105
- create_project!(branch_name) if options[:project]
114
+ say "Branch name \"#{branch_name}\" has been copied to the clipboard!", :green if copy_to_clipboard branch_name
106
115
  end
107
116
 
108
117
  desc 'config SUBCOMMAND', 'Manages config files for this gem'
@@ -5,13 +5,28 @@ require_relative 'option_error'
5
5
  module Branch
6
6
  module Name
7
7
  module Normalizable
8
- NON_WORD_CHARS_REGEX = /[\W_]/
8
+ # The regex used to split ticket and ticket description tokens
9
+ # to formulate a source control branch name.
10
+ BRANCH_NAME_REGEX = %r{[^/\w\x20]}
11
+
12
+ # The regex used to split ticket and ticket description tokens
13
+ # to formulate a project folder based on the branch name formulated.
14
+ PROJECT_FOLDER_REGEX = /[\W_]/
9
15
 
10
16
  def normalize_branch_name(ticket_description, ticket)
11
17
  formatted_branch_name = format_string_or_default
12
18
  formatted_branch_name = formatted_branch_name.gsub('%t', ticket || '')
13
19
  formatted_branch_name = formatted_branch_name.gsub('%d', ticket_description)
14
- formatted_branch_name = normalize_token formatted_branch_name
20
+ formatted_branch_name = formatted_branch_name.gsub('%u', Etc.getlogin)
21
+ normalize_token formatted_branch_name, BRANCH_NAME_REGEX
22
+ rescue Branch::Name::OptionError => e
23
+ raise unless block_given?
24
+
25
+ yield e
26
+ end
27
+
28
+ def project_folder_from(normalized_branch_name)
29
+ normalize_token normalized_branch_name, PROJECT_FOLDER_REGEX
15
30
  rescue Branch::Name::OptionError => e
16
31
  raise unless block_given?
17
32
 
@@ -34,20 +49,8 @@ module Branch
34
49
  format_string
35
50
  end
36
51
 
37
- def normalize_ticket_description(ticket_description)
38
- normalize_token ticket_description
39
- end
40
-
41
- def normalize_ticket(ticket)
42
- return if ticket.blank?
43
-
44
- ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
45
- normalize_token(token)
46
- end.join(options[:separator])
47
- end
48
-
49
- def normalize_token(token)
50
- token = token.gsub(NON_WORD_CHARS_REGEX, ' ')
52
+ def normalize_token(token, regex)
53
+ token = token.gsub(regex, ' ')
51
54
  token = token.strip
52
55
  .squeeze(' ')
53
56
  .split.join(options[:separator])
@@ -16,13 +16,12 @@ module Branch
16
16
  include TaskDefaultable
17
17
 
18
18
  class << self
19
- def ascestor_name
19
+ def base_usage
20
20
  'config delete'
21
21
  end
22
22
  end
23
23
 
24
24
  desc 'all', 'Deletes all config files (local and global) for this gem'
25
- subcommand_help_override "#{ascestor_name} all"
26
25
  long_desc <<-LONG_DESC
27
26
  NAME
28
27
  \x5
@@ -32,15 +31,12 @@ module Branch
32
31
  \x5
33
32
  branch-name config delete all
34
33
  LONG_DESC
35
- method_option :all, type: :boolean, aliases: '-a'
36
-
37
34
  def all
38
35
  delete_global_config_file!
39
36
  delete_local_config_file!
40
37
  end
41
38
 
42
39
  desc 'global', 'Deletes the global config file for this gem'
43
- subcommand_help_override "#{ascestor_name} global"
44
40
  long_desc <<-LONG_DESC
45
41
  NAME
46
42
  \x5
@@ -50,14 +46,11 @@ module Branch
50
46
  \x5
51
47
  branch-name config delete global
52
48
  LONG_DESC
53
- method_option :global, type: :boolean, aliases: '-g'
54
-
55
49
  def global
56
50
  delete_global_config_file!
57
51
  end
58
52
 
59
53
  desc 'local', 'Deletes the local config file for this gem'
60
- subcommand_help_override "#{ascestor_name} local"
61
54
  long_desc <<-LONG_DESC
62
55
  NAME
63
56
  \x5
@@ -67,8 +60,6 @@ module Branch
67
60
  \x5
68
61
  branch-name config delete local
69
62
  LONG_DESC
70
- method_option :local, type: :boolean, aliases: '-l'
71
-
72
63
  def local
73
64
  delete_local_config_file!
74
65
  end
@@ -16,13 +16,12 @@ module Branch
16
16
  include TaskDefaultable
17
17
 
18
18
  class << self
19
- def ascestor_name
19
+ def base_usage
20
20
  'config init'
21
21
  end
22
22
  end
23
23
 
24
24
  desc 'global', 'Creates and initializes a .branch-name file in the global folder'
25
- subcommand_help_override "#{ascestor_name} global"
26
25
  long_desc <<-LONG_DESC
27
26
  NAME
28
27
  \x5
@@ -38,7 +37,6 @@ module Branch
38
37
  end
39
38
 
40
39
  desc 'local', 'Creates and initializes a .branch-name file in the local folder'
41
- subcommand_help_override "#{ascestor_name} local"
42
40
  long_desc <<-LONG_DESC
43
41
  NAME
44
42
  \x5
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'help_nestable'
4
-
5
3
  module Branch
6
4
  module Name
7
5
  module Subcommands
@@ -13,30 +11,33 @@ module Branch
13
11
  class << self
14
12
  def included(base)
15
13
  base.extend ClassMethods
16
- base.include HelpNestable
17
14
  end
18
15
  end
19
16
 
20
17
  module ClassMethods
21
- def ascestor_name
18
+ def base_usage
22
19
  raise NotImplementedError
23
20
  end
24
21
 
25
22
  # Thor override
26
- def banner(command, _namespace = nil, subcommand = false)
27
- command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |_formatted_usage|
28
- command_name = command.name.to_sym
29
- "#{basename} #{@subcommand_help_override[command.usage]}"
30
- end.join("\n")
23
+ # rubocop:disable Style/OptionHash
24
+ def desc(usage, description, options = {})
25
+ super "#{base_usage} #{usage} ", description, options
31
26
  end
27
+ # rubocop:enable Style/OptionHash
32
28
 
33
- def subcommand_help_override(help_string)
34
- raise "Thor.desc must be called for \"#{help_string}\" " \
35
- 'prior to calling .subcommand_help_override' if @usage.blank?
36
-
37
- @subcommand_help_override = {} unless defined? @subcommand_help_override
38
- @subcommand_help_override[@usage] = help_string
29
+ # Thor override
30
+ # rubocop:disable Style/GlobalVars
31
+ # rubocop:disable Lint/UnusedMethodArgument
32
+ # rubocop:disable Style/OptionalBooleanParameter
33
+ def banner(command, namespace = nil, subcommand = false)
34
+ command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |_formatted_usage|
35
+ "#{basename} #{command.usage}"
36
+ end.join("\n")
39
37
  end
38
+ # rubocop:enable Style/GlobalVars
39
+ # rubocop:enable Lint/UnusedMethodArgument
40
+ # rubocop:enable Style/OptionalBooleanParameter
40
41
  end
41
42
  end
42
43
  end
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '3.0.0'
6
+ VERSION = '3.2.2'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch-name
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -119,7 +119,6 @@ files:
119
119
  - lib/branch/name/projectable.rb
120
120
  - lib/branch/name/subcommands/config.rb
121
121
  - lib/branch/name/subcommands/delete.rb
122
- - lib/branch/name/subcommands/help_nestable.rb
123
122
  - lib/branch/name/subcommands/init.rb
124
123
  - lib/branch/name/subcommands/nestable.rb
125
124
  - lib/branch/name/task_defaultable.rb
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Branch
4
- module Name
5
- module Subcommands
6
- # This module helps fix a bug in Thor that prohibits help for nested
7
- # subcommands from displaying help properly. Nested subcommands fail
8
- # to display their subcommand ancestor command name. This fixes that
9
- # bug. This module is used in conjunction with the Nestable module.
10
- module HelpNestable
11
- class << self
12
- def included(base)
13
- # Thor override
14
- base.desc 'help [COMMAND]', 'Describe available commands or one specific command'
15
- base.subcommand_help_override "config init help [SUBCOMMAND]"
16
- def help(command = nil, subcommand = false)
17
- super
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end