branch-name 2.1.0 → 2.2.0

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: 56671e5fc00e4ad0045dad3658a70038a878d4352fb711c8aad559d5132516ff
4
- data.tar.gz: 7317863bb70d45b73df3c64ff0e6a73251e6245a920b1e99f21fa7ffa9b31a95
3
+ metadata.gz: c79db6ebf8cf49b09e86cc7ffff4bbe74fe88981da302cf83231cbce59a8ec0d
4
+ data.tar.gz: 15f849bc8342043994590d68b2caa5ea439a7c9a9c89a16a04a03211d3f47250
5
5
  SHA512:
6
- metadata.gz: 9078aa3f683ff648fcfe3a4d37ac4e0f39346d13f207a82c32e2c090c1549914626d225114985ff23190203daf101226af4aa4494e8ba340ef73f600f5b98ed3
7
- data.tar.gz: cd69167ddb0f89e7e70e68d8c936ee9aa2c411445f31e46cd624cbc5ee7664247ecd0619d66d5e04fb50d3ef8a2f53e773411eecca96ab3a635b42e579be94e7
6
+ metadata.gz: edd5e60ccba0dd53b403290dc1956df060e2d31ca61c2959feb97d9ee80f8cda6802e8b90c441f8571fbf254e93929c9ba382af284cfda5ef3de997319a7e52d
7
+ data.tar.gz: 866f0482f61a59968b7b8fe3c4923551e3e0920416383aa5aa146ce1c4a827fb5f917bceef4297d020058c6e4a76f047c3027166937ff05ba9d1adc3216292b9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## ['2.2.0'] - 2022-09-24
2
+ * Enhancements:
3
+ * Add support for `branch-name create` `-x` argument (see `branch-name help create`) which allows you to position the ticket and ticket description within the forulated branch name.
4
+ * The `branch-name create :project_location` option string now accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directive.
5
+ * Add better test coverage, although not what it should be (I'm working on it); this started a "quick and dirty" tool.
6
+ * `branch-name create` will now create the PROJECT_LOCATION if it does not exist.
7
+ * Update README.md file.
8
+
1
9
  ## ['2.1.0'] - 2022-09-22
2
10
  * Enhancements: Add support for Windows clipboard. Branch names created are copied to the clibboard for macOS and Windows now.
3
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (2.1.0)
4
+ branch-name (2.2.0)
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
@@ -42,9 +42,9 @@ $ branch-name config init global
42
42
  #=> Configuration file (/Users/<username>/.branch-name) created
43
43
  ```
44
44
 
45
- This creates a `.branch-name` .yaml configuration file the home folder of the current user (`$ whoami` on *macOS*) with the following option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `brnch-name` command is *not* found in the `.branch-name` confg file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command are not currently supported.
45
+ This creates a `.branch-name` yaml configuration file the home folder of the current user (`$ whoami` on *macOS*) with the below option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `branch-name` command is *not* found in the `.branch-name` config file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command are not currently supported.
46
46
 
47
- For example, the following default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
47
+ Below is a list of _default_ options created when initializing _global_ options; consequently, these default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
48
48
 
49
49
  ```yaml
50
50
  # /Users/<username>/.branch-name
@@ -52,23 +52,27 @@ For example, the following default options will be used whenever the `branch-nam
52
52
  create:
53
53
  downcase: false
54
54
  separator: _
55
+ format_string: "%t %d"
55
56
  project: false
56
- project_location: "/Users/<username>"
57
+ project_location: "/Users/<username>/branch-name/projects/%Y/%m (%B)"
57
58
  project_files:
58
- - scratch.rb
59
59
  - readme.txt
60
+ - scratch.rb
61
+ - snippets.rb
60
62
  ```
61
63
 
62
- NOTE: It is recommended that you change the default `create: project_location` to a more suitable location depending on your *os*. For example, on *macOS* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
64
+ NOTE: You can manually change any of the options you wish. It is recommended that you change the default `create: project_location` to meet your needs, depending on your *os*. For example, on *macOS* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
65
+
66
+ The `create: project_location` option string also accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directives.
63
67
 
64
- Any or all of these options can be overwritten on the command-line:
68
+ The `create: format_string` option string can be used to position the *ticket* (`%t`) and *ticket description* (`%d`) within the branch name formulated. You can also include any other information you wish in the format string, for example: "`<username> %t %d`". However, non-word characters will be stripped (see `Branch::Name::Normalizable::NON_WORD_CHARS_REGEX` which equates to `/[\W_]/`)
65
69
 
66
- For more information:
70
+ Any or all of these options can also be overwritten on the command-line. For more information:
67
71
  `$ branch-name config help init`
68
72
 
69
73
  ### Creating Feature Branch Names and Projects Examples
70
74
 
71
- NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply formulates a suitable feature branch name given a *jira* ticket and *jira* ticket description.
75
+ NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply _formulates_ a suitable feature branch name given a *jira* ticket and *jira* ticket description.
72
76
 
73
77
  NOTE: The below examples will assume the following `global` config file defaults (`$ branch-name config init global`) that have been *manually* manipulated to have the following options:
74
78
 
@@ -79,7 +83,7 @@ create:
79
83
  downcase: false
80
84
  separator: _
81
85
  project: false
82
- project_location: "/Users/<username>/feature-branches/2022"
86
+ project_location: "/Users/<username>/feature-branches/%Y"
83
87
  project_files:
84
88
  - readme.txt
85
89
  - scratch.rb
@@ -43,7 +43,7 @@ module Branch
43
43
 
44
44
  SYNOPSIS
45
45
  \x5
46
- branch-name create [-l|-f|-d|-s|-p] DESCRIPTION [TICKET]
46
+ branch-name create [-l|-f|-d|-s|-p|-x] DESCRIPTION [TICKET]
47
47
 
48
48
  \x5
49
49
  The following options are available:
@@ -69,9 +69,17 @@ module Branch
69
69
  A "project" is a folder that is created in the PROJECT_LOCATION specified,
70
70
  whose name is equivalent to the branch name that is formulated.
71
71
  The default is: "#{Locatable.project_folder(options: options)}".
72
+
73
+ \x5 -x FORMAT_STRING: This is a string that determines the format of the branch name
74
+ that is formulated. The following are a list of required placeholders you must put
75
+ in your format string to format the brach name: [%t, %d].
76
+ \x5Where %t will be replaced by the ticket.
77
+ \x5Where %d will be replaced by the ticket description.
78
+ \x5The default is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
72
79
  LONG_DESC
73
80
  method_option :downcase, type: :boolean, aliases: '-d'
74
81
  method_option :separator, type: :string, aliases: '-s'
82
+ method_option :format_string, type: :string, aliases: '-x'
75
83
  method_option :project, type: :boolean, aliases: '-p'
76
84
  method_option :project_location, type: :string, aliases: '-l'
77
85
  method_option :project_files, type: :array, aliases: '-f'
@@ -84,7 +92,10 @@ module Branch
84
92
 
85
93
  init_options_for! command: :create
86
94
 
87
- branch_name = normalize_branch_name(ticket_description, ticket)
95
+ branch_name = normalize_branch_name(ticket_description, ticket) do |error|
96
+ say_error error.message
97
+ exit 1
98
+ end
88
99
 
89
100
  say "Branch name: #{branch_name}", :cyan
90
101
 
@@ -21,7 +21,6 @@ module Branch
21
21
 
22
22
  def copy_to_clipboard_macos(text)
23
23
  copy_to_clipboard_with(app: 'pbcopy', text: text)
24
-
25
24
  end
26
25
 
27
26
  def copy_to_clipboard_windows(text)
@@ -16,8 +16,9 @@ module Branch
16
16
  'create' => {
17
17
  'downcase' => false,
18
18
  'separator' => '_',
19
+ 'format_string' => '%t %d',
19
20
  'project' => false,
20
- 'project_location' => Locatable.project_folder,
21
+ 'project_location' => "#{Locatable.project_folder}/branch-name/projects/%Y/%m (%B)",
21
22
  'project_files' => %w[readme.txt scratch.rb snippets.rb]
22
23
  }
23
24
  }.freeze
@@ -1,25 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'option_error'
4
+
3
5
  module Branch
4
6
  module Name
5
7
  module Normalizable
6
8
  NON_WORD_CHARS_REGEX = /[\W_]/
7
9
 
8
10
  def normalize_branch_name(ticket_description, ticket)
9
- normalized_ticket_description = normalize_ticket_description ticket_description
10
- return normalized_ticket_description if ticket.blank?
11
+ formatted_branch_name = format_string_or_default
12
+ formatted_branch_name = formatted_branch_name.gsub('%t', ticket || '')
13
+ formatted_branch_name = formatted_branch_name.gsub('%d', ticket_description)
14
+ formatted_branch_name = normalize_token formatted_branch_name
15
+ rescue Branch::Name::OptionError => e
16
+ raise unless block_given?
11
17
 
12
- normalized_ticket = normalize_ticket ticket
13
- "#{normalized_ticket}#{options[:separator]}#{normalized_ticket_description}"
18
+ yield e
14
19
  end
15
20
 
16
21
  private
17
22
 
23
+ def format_string_or_default
24
+ format_string = options[:format_string].presence ||
25
+ Configurable::DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']
26
+ unless %w[%t %d].all? { |o| format_string.include?(o) }
27
+ raise Branch::Name::OptionError.new(
28
+ 'was called having argument [-x/--format-string] ' \
29
+ 'which did not contain %t and %d format placeholders',
30
+ current_command_chain.first
31
+ )
32
+ end
33
+
34
+ format_string
35
+ end
36
+
18
37
  def normalize_ticket_description(ticket_description)
19
38
  normalize_token ticket_description
20
39
  end
21
40
 
22
41
  def normalize_ticket(ticket)
42
+ return if ticket.blank?
43
+
23
44
  ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
24
45
  normalize_token(token)
25
46
  end.join(options[:separator])
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ class OptionError < StandardError
6
+ attr_reader :command
7
+
8
+ def initialize(msg, command)
9
+ super(msg)
10
+
11
+ @command = command
12
+ end
13
+
14
+ def message
15
+ "ERROR: \"branch-name #{command}\" #{super}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,8 @@ module Branch
11
11
  def create_project!(branch_name)
12
12
  raise 'options[:project] is false' unless options[:project]
13
13
 
14
- project_folder = "#{options[:project_location]}/#{branch_name}"
14
+ project_location = Time.new.strftime(options[:project_location])
15
+ project_folder = "#{project_location}/#{branch_name}"
15
16
 
16
17
  if Dir.exist? project_folder
17
18
  puts "Project folder \"#{project_folder}\" already exists"
@@ -19,7 +20,7 @@ module Branch
19
20
  return
20
21
  end
21
22
 
22
- Dir.mkdir project_folder
23
+ FileUtils.mkdir_p(project_folder)
23
24
  create_project_files!(project_folder)
24
25
 
25
26
  puts "Project folder \"#{project_folder}\" with project files #{options[:project_files]} was created".green
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '2.1.0'
6
+ VERSION = '2.2.0'
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: 2.1.0
4
+ version: 2.2.0
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-22 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -115,6 +115,7 @@ files:
115
115
  - lib/branch/name/loadable.rb
116
116
  - lib/branch/name/locatable.rb
117
117
  - lib/branch/name/normalizable.rb
118
+ - lib/branch/name/option_error.rb
118
119
  - lib/branch/name/projectable.rb
119
120
  - lib/branch/name/subcommands/config.rb
120
121
  - lib/branch/name/subcommands/init.rb