branch-name 3.0.0 → 3.2.1

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: ecf9d15cb3f6a7be37ca9d39377e9d8c103b71557ae26a01dbf19670ce3c9548
4
- data.tar.gz: 2ee162f10d1bd5bf48cde5e2d7611241600030098b9e50331472eef08077bbad
3
+ metadata.gz: 8a3968d20d8af29e02e511894c96e66b09965f60fd945efdb42c0454d190ce75
4
+ data.tar.gz: 3d936e247ea81a147fd4e117ee15a10ffce733557c117060c1ead457c1c0bf13
5
5
  SHA512:
6
- metadata.gz: d7dd261862332096d9dd74d38ade8fd517b72ea07fe867a8d2b2b6cbf367b13e296ce2f8fc35cd9bd2a697e53a51d39edc842ca9ad644a6ece15dcd4e0c0b3ac
7
- data.tar.gz: cba46ce2945c423427d1e39930d9695841a0153fa041d61899f90b396a156162a4dcce047f1c04d1b131ce7573aa497b3f351538d8d12f6bc7820fcf2fe39b6e
6
+ metadata.gz: 64bf17dc7a54feffe42ed5195d869291a59689c4cc7a06a0c2329ae3c1dbc86cc3ba08225aa58a30b964cd7c82fb6e55aedb8e121a346b2ddc5602938feb46bd
7
+ data.tar.gz: 29a1c7a1b64f38ed6404c6c9f87d5c95bc5470d31408362b42b96ceaf9b0ca8958a7d59f8bbab0b06b322734b4326ae55652cf5aa4edbcaf3d35fd5aabef8b57
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
- ## ['3.0.0'] - 2022-09-26
1
+ ## ['3.2.1'] - 2022-09-26
2
+ * Changes:
3
+ * Fix rubocop violations.
4
+ * Miscellaneous mixin refactors.
5
+ * Bug Fixes: Fix bug that displayed subcommand help incorrectly.
6
+
7
+ ## ['3.1.0'] - 2022-09-26
2
8
  * Enhancements:
9
+ * Branch names may now be created using a forward-slash (/). See the README.md file for more information.
10
+ * 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.
11
+
12
+ ## ['3.0.0'] - 2022-09-26
3
13
  * Changes:
4
14
  * Default default commands to :help.
5
15
  * 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.1)
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])
@@ -3,6 +3,7 @@
3
3
  require 'thor'
4
4
  require_relative '../configurable'
5
5
  require_relative '../exitable'
6
+ require_relative 'help_nestable'
6
7
  require_relative 'nestable'
7
8
  require_relative '../task_defaultable'
8
9
 
@@ -16,13 +17,16 @@ module Branch
16
17
  include TaskDefaultable
17
18
 
18
19
  class << self
19
- def ascestor_name
20
+ def ancestor_name
20
21
  'config delete'
21
22
  end
22
23
  end
23
24
 
25
+ # NOTE: This must be included AFTER defining .ancestor_name
26
+ include HelpNestable
27
+
24
28
  desc 'all', 'Deletes all config files (local and global) for this gem'
25
- subcommand_help_override "#{ascestor_name} all"
29
+ help_override "#{ancestor_name} all"
26
30
  long_desc <<-LONG_DESC
27
31
  NAME
28
32
  \x5
@@ -32,15 +36,13 @@ module Branch
32
36
  \x5
33
37
  branch-name config delete all
34
38
  LONG_DESC
35
- method_option :all, type: :boolean, aliases: '-a'
36
-
37
39
  def all
38
40
  delete_global_config_file!
39
41
  delete_local_config_file!
40
42
  end
41
43
 
42
44
  desc 'global', 'Deletes the global config file for this gem'
43
- subcommand_help_override "#{ascestor_name} global"
45
+ help_override "#{ancestor_name} global"
44
46
  long_desc <<-LONG_DESC
45
47
  NAME
46
48
  \x5
@@ -50,14 +52,12 @@ module Branch
50
52
  \x5
51
53
  branch-name config delete global
52
54
  LONG_DESC
53
- method_option :global, type: :boolean, aliases: '-g'
54
-
55
55
  def global
56
56
  delete_global_config_file!
57
57
  end
58
58
 
59
59
  desc 'local', 'Deletes the local config file for this gem'
60
- subcommand_help_override "#{ascestor_name} local"
60
+ help_override "#{ancestor_name} local"
61
61
  long_desc <<-LONG_DESC
62
62
  NAME
63
63
  \x5
@@ -67,8 +67,6 @@ module Branch
67
67
  \x5
68
68
  branch-name config delete local
69
69
  LONG_DESC
70
- method_option :local, type: :boolean, aliases: '-l'
71
-
72
70
  def local
73
71
  delete_local_config_file!
74
72
  end
@@ -12,10 +12,13 @@ module Branch
12
12
  def included(base)
13
13
  # Thor override
14
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
15
+ base.help_override "#{base.ancestor_name} help [SUBCOMMAND]"
16
+ # rubocop:disable Style/OptionalBooleanParameter
17
+ # def help(command = nil, subcommand = false)
18
+ # puts "subcommand: #{subcommand}"
19
+ # super
20
+ # end
21
+ # rubocop:enable Style/OptionalBooleanParameter
19
22
  end
20
23
  end
21
24
  end
@@ -3,6 +3,7 @@
3
3
  require 'thor'
4
4
  require_relative '../configurable'
5
5
  require_relative '../exitable'
6
+ require_relative 'help_nestable'
6
7
  require_relative 'nestable'
7
8
  require_relative '../task_defaultable'
8
9
 
@@ -16,13 +17,16 @@ module Branch
16
17
  include TaskDefaultable
17
18
 
18
19
  class << self
19
- def ascestor_name
20
+ def ancestor_name
20
21
  'config init'
21
22
  end
22
23
  end
23
24
 
25
+ # NOTE: This must be included AFTER defining .ancestor_name
26
+ include HelpNestable
27
+
24
28
  desc 'global', 'Creates and initializes a .branch-name file in the global folder'
25
- subcommand_help_override "#{ascestor_name} global"
29
+ help_override "#{ancestor_name} global"
26
30
  long_desc <<-LONG_DESC
27
31
  NAME
28
32
  \x5
@@ -38,7 +42,7 @@ module Branch
38
42
  end
39
43
 
40
44
  desc 'local', 'Creates and initializes a .branch-name file in the local folder'
41
- subcommand_help_override "#{ascestor_name} local"
45
+ help_override "#{ancestor_name} local"
42
46
  long_desc <<-LONG_DESC
43
47
  NAME
44
48
  \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,29 +11,36 @@ 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 ancestor_name
22
19
  raise NotImplementedError
23
20
  end
24
21
 
25
22
  # Thor override
26
- def banner(command, _namespace = nil, subcommand = false)
23
+ # rubocop:disable Style/GlobalVars
24
+ # rubocop:disable Lint/UnusedMethodArgument
25
+ # rubocop:disable Style/OptionalBooleanParameter
26
+ def banner(command, namespace = nil, subcommand = false)
27
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]}"
28
+ "#{basename} #{@help_override[command.usage]}"
30
29
  end.join("\n")
31
30
  end
31
+ # rubocop:enable Style/GlobalVars
32
+ # rubocop:enable Lint/UnusedMethodArgument
33
+ # rubocop:enable Style/OptionalBooleanParameter
32
34
 
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?
35
+ def help_override(help_string)
36
+ if @usage.blank?
37
+ raise 'Thor.desc must be called for the command that should ' \
38
+ "be associated with \"#{help_string}\" prior to calling " \
39
+ '.help_override'
40
+ end
36
41
 
37
- @subcommand_help_override = {} unless defined? @subcommand_help_override
38
- @subcommand_help_override[@usage] = help_string
42
+ @help_override = {} unless defined? @help_override
43
+ @help_override[@usage] = help_string
39
44
  end
40
45
  end
41
46
  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.1'
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.1
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